25 #ifndef WMARCHINGLEGOALGORITHM_H
26 #define WMARCHINGLEGOALGORITHM_H
32 #include "../WProgressCombiner.h"
33 #include "../math/WMatrix.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 std::shared_ptr< WTriangleMesh >
generateSurface(
size_t nbCoordsX,
size_t nbCoordsY,
size_t nbCoordsZ,
94 const std::vector< T >* vals,
96 std::shared_ptr<WProgressCombiner> mainProgress
97 = std::shared_ptr < WProgressCombiner >() );
114 std::shared_ptr< WTriangleMesh >
genSurfaceOneValue(
size_t nbCoordsX,
size_t nbCoordsY,
size_t nbCoordsZ,
116 const std::vector< size_t >* vals,
118 std::shared_ptr<WProgressCombiner> progress
119 = std::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> std::shared_ptr<WTriangleMesh>
156 const std::vector< T >* vals,
158 std::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 std::shared_ptr< WProgress > progress;
181 progress = std::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 ) )
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 ) )
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] );
Creates a non interpolated triangulation of an isosurface.
ID2WMLPointXYZId m_idToVertices
List of WPointXYZIds which form the isosurface.
WMarchingLegoAlgorithm()
standard constructor
WMatrix< double > m_matrix
The 4x4 transformation matrix for the triangle vertices.
unsigned int m_nCellsX
No. of cells in x direction.
std::shared_ptr< WTriangleMesh > genSurfaceOneValue(size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ, const WMatrix< double > &mat, const std::vector< size_t > *vals, size_t isoValue, std::shared_ptr< WProgressCombiner > progress=std::shared_ptr< WProgressCombiner >())
Generate the triangles for the surface on the given dataSet (inGrid, vals).
size_t getVertexID(size_t nX, size_t nY, size_t nZ)
returns a vertex id for a given grid point
std::shared_ptr< WTriangleMesh > generateSurface(size_t nbCoordsX, size_t nbCoordsY, size_t nbCoordsZ, const WMatrix< double > &mat, const std::vector< T > *vals, double isoValue, std::shared_ptr< WProgressCombiner > mainProgress=std::shared_ptr< WProgressCombiner >())
Generate the triangles for the surface on the given dataSet (inGrid, vals).
unsigned int m_nCellsZ
No. of cells in z direction.
double m_tIsoLevel
The isovalue.
WMLTriangleVECTOR m_trivecTriangles
List of WMCTriangleS which form the triangulation of the isosurface.
void addSurface(size_t x, size_t y, size_t z, size_t surface)
adds 2 triangles for a given face of the voxel
~WMarchingLegoAlgorithm()
destructor
unsigned int m_nCellsY
No. of cells in y direction.
This only is a 3d double vector.
Class managing progress inside of modules.
Triangle mesh data structure allowing for convenient access of the elements.
A point consisting of its coordinates and ID.
double x
x coordinates of the point.
double y
y coordinates of the point.
double z
z coordinates of the point.
unsigned int newID
ID of the point.
Encapsulated ids representing a triangle.
unsigned int pointID[3]
The IDs of the vertices of the triangle.