OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #include <vector> 00026 00027 #include "WMarchingCubesAlgorithm.h" 00028 00029 WMarchingCubesAlgorithm::WMarchingCubesAlgorithm() 00030 : m_matrix( 4, 4 ) 00031 { 00032 } 00033 00034 WPointXYZId WMarchingCubesAlgorithm::interpolate( double fX1, double fY1, double fZ1, double fX2, double fY2, double fZ2, 00035 double tVal1, double tVal2 ) 00036 { 00037 WPointXYZId interpolation; 00038 double mu; 00039 00040 mu = static_cast<double>( ( m_tIsoLevel - tVal1 ) ) / ( tVal2 - tVal1 ); 00041 interpolation.x = fX1 + mu * ( fX2 - fX1 ); 00042 interpolation.y = fY1 + mu * ( fY2 - fY1 ); 00043 interpolation.z = fZ1 + mu * ( fZ2 - fZ1 ); 00044 interpolation.newID = 0; 00045 00046 return interpolation; 00047 } 00048 00049 int WMarchingCubesAlgorithm::getEdgeID( unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nEdgeNo ) 00050 { 00051 switch( nEdgeNo ) 00052 { 00053 case 0: 00054 return 3 * getVertexID( nX, nY, nZ ) + 1; 00055 case 1: 00056 return 3 * getVertexID( nX, nY + 1, nZ ); 00057 case 2: 00058 return 3 * getVertexID( nX + 1, nY, nZ ) + 1; 00059 case 3: 00060 return 3 * getVertexID( nX, nY, nZ ); 00061 case 4: 00062 return 3 * getVertexID( nX, nY, nZ + 1 ) + 1; 00063 case 5: 00064 return 3 * getVertexID( nX, nY + 1, nZ + 1 ); 00065 case 6: 00066 return 3 * getVertexID( nX + 1, nY, nZ + 1 ) + 1; 00067 case 7: 00068 return 3 * getVertexID( nX, nY, nZ + 1 ); 00069 case 8: 00070 return 3 * getVertexID( nX, nY, nZ ) + 2; 00071 case 9: 00072 return 3 * getVertexID( nX, nY + 1, nZ ) + 2; 00073 case 10: 00074 return 3 * getVertexID( nX + 1, nY + 1, nZ ) + 2; 00075 case 11: 00076 return 3 * getVertexID( nX + 1, nY, nZ ) + 2; 00077 default: 00078 // Invalid edge no. 00079 return -1; 00080 } 00081 } 00082 00083 unsigned int WMarchingCubesAlgorithm::getVertexID( unsigned int nX, unsigned int nY, unsigned int nZ ) 00084 { 00085 return nZ * ( m_nCellsY + 1 ) * ( m_nCellsX + 1) + nY * ( m_nCellsX + 1 ) + nX; 00086 } 00087