25 #ifndef WMARCHINGLEGOALGORITHM_H
26 #define WMARCHINGLEGOALGORITHM_H
31 #include "../math/WMatrix.h"
32 #include "../WProgressCombiner.h"
34 #include "core/graphicsEngine/WTriangleMesh.h"
47 typedef std::map< unsigned int, WMLPointXYZId > ID2WMLPointXYZId;
57 typedef std::vector<WMLTriangle> WMLTriangleVECTOR;
91 template<
typename T >
92 boost::shared_ptr< WTriangleMesh >
generateSurface(
size_t nbCoordsX,
size_t nbCoordsY,
size_t nbCoordsZ,
94 const std::vector< T >* vals,
96 boost::shared_ptr<WProgressCombiner> mainProgress
97 = boost::shared_ptr < WProgressCombiner >() );
114 boost::shared_ptr< WTriangleMesh >
genSurfaceOneValue(
size_t nbCoordsX,
size_t nbCoordsY,
size_t nbCoordsZ,
116 const std::vector< size_t >* vals,
118 boost::shared_ptr<WProgressCombiner> progress
119 = boost::shared_ptr < WProgressCombiner >() );
130 void addSurface(
size_t x,
size_t y,
size_t z,
size_t surface );
139 size_t getVertexID(
size_t nX,
size_t nY,
size_t nZ );
153 template<
typename T> boost::shared_ptr<WTriangleMesh>
156 const std::vector< T >* vals,
158 boost::shared_ptr<WProgressCombiner> mainProgress )
160 WAssert( vals,
"No value set provided." );
173 size_t nX = nbCoordsX;
174 size_t nY = nbCoordsY;
176 size_t nPointsInSlice = nX * nY;
178 boost::shared_ptr< WProgress > progress;
181 progress = boost::shared_ptr< WProgress >(
new WProgress(
"Marching Cubes",
m_nCellsZ ) );
182 mainProgress->addSubProgress( progress );
196 if( ( *vals )[ z * nPointsInSlice + y * nX + x ] <
m_tIsoLevel )
201 if( x > 0 && ( ( *vals )[ z * nPointsInSlice + y * nX + x - 1 ] <
m_tIsoLevel ) )
205 if( x < m_nCellsX - 1 && ( ( *vals )[ z * nPointsInSlice + y * nX + x + 1 ] <
m_tIsoLevel ) )
210 if( y > 0 && ( ( *vals )[ z * nPointsInSlice + ( y - 1 ) * nX + x ] <
m_tIsoLevel ) )
215 if( y < m_nCellsY - 1 && ( ( *vals )[ z * nPointsInSlice + ( y + 1 ) * nX + x ] <
m_tIsoLevel ) )
220 if( z > 0 && ( ( *vals )[ ( z - 1 ) * nPointsInSlice + y * nX + x ] <
m_tIsoLevel ) )
225 if( z < m_nCellsZ - 1 && ( ( *vals )[ ( z + 1 ) * nPointsInSlice + y * nX + x ] <
m_tIsoLevel ) )
234 if( x == m_nCellsX - 1 )
244 if( y == m_nCellsY - 1 )
254 if( z == m_nCellsZ - 1 )
261 unsigned int nextID = 0;
269 mapIterator->second.y / nbCoordsY,
270 mapIterator->second.z / nbCoordsZ );
273 WPosition pos =
WPosition( mapIterator->second.x, mapIterator->second.y, mapIterator->second.z );
275 std::vector< double > resultPos4D( 4 );
281 ( *mapIterator ).second.newID = nextID;
282 triMesh->addVertex( resultPos4D[0] / resultPos4D[3],
283 resultPos4D[1] / resultPos4D[3],
284 resultPos4D[2] / resultPos4D[3] );
285 triMesh->addTextureCoordinate( texCoord );
294 for(
unsigned int i = 0; i < 3; i++ )
296 unsigned int newID =
m_idToVertices[( *vecIterator ).pointID[i]].newID;
297 ( *vecIterator ).pointID[i] = newID;
299 triMesh->addTriangle( ( *vecIterator ).pointID[0], ( *vecIterator ).pointID[1], ( *vecIterator ).pointID[2] );
308 #endif // WMARCHINGLEGOALGORITHM_H