32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/io/writers/MeshWriter.h"
35#include "DGtal/shapes/Mesh.h"
89 trace.
info() << p0f0 << p1f0 << p2f0<< endl;
92 trace.
info() << p0f1 << p1f1 << p2f1<< endl;
99 bool okMeshConstruct = (p0==p0f0) && (p1==p1f0) && (p2==p2f0) &&
100 (p3==p0f1) && (p4==p1f1) && (p5==p2f1) ;
103 bool okMeshIterators =
true;
107 for( Mesh<Point>::VertexStorage::const_iterator it = aMesh.
vertexBegin();
112 okMeshIterators = okMeshIterators && (nb == aMesh.
nbVertex());
114 trace.
info() <<
"vertex iteration test ok"<<std::endl;
117 for( Mesh<Point>::VertexStorage::iterator it = aMesh.
vertexBegin();
120 (*it)[0]+=10; (*it)[1]+=5;
124 for( Mesh<Point>::FaceStorage::const_iterator it = aMesh.
faceBegin();
129 okMeshIterators = okMeshIterators && (nb == aMesh.
nbFaces());
131 trace.
info() <<
"face iteration test ok"<<std::endl;
135 for( Mesh<Point>::FaceStorage::iterator it = aMesh.
faceBegin();
142 trace.
info() <<
"getVertex and getFaceCenter tests ok"<<std::endl;
154 bool boundingBoxOK = (bb.first ==
Point(20,10)) && (bb.second ==
Point(26,18));
155 trace.
info() <<
"bouding box=" << bb.first <<
" " << bb.second <<
"(should be (20,10) (26,18)" <<std::endl;
165 trace.
info() <<
"nb vertices before subdivision: " << aMeshR.
nbVertex() << std::endl;
166 trace.
info() <<
"nb faces before subdivision: " << aMeshR.
nbFaces() << std::endl;
168 trace.
info() <<
"nb vertices after subdivision: " << aMeshR.
nbVertex() <<
" (should be 4)"<<std::endl;
169 trace.
info() <<
"nb faces after subdivision: " << aMeshR.
nbFaces() <<
" (should be 3)" <<std::endl;
173 trace.
info() << (okSubDivide ?
"[subdivise OK]":
"[subdivise fail]" ) << std::endl;
187 trace.
info() <<
"nb faces after quad to triangle transform: " << aMeshQ.
nbFaces() ;
188 bool okQuadToTrans = aMeshQ.
nbFaces() == 2;
189 trace.
info() <<
"(should be 2) "<< (okQuadToTrans?
"[ok]":
"[error]") << std::endl;
199 trace.
info() << (okMeshCopy ?
"[copy ok]":
"[copy fail]" ) << std::endl;
204 std::vector<typename Mesh<Point>::Index> f = {1};
207 trace.
info() << (okRemoveFace ?
"[face remove ok]":
"[face remove fail]" ) << std::endl;
225 bool okClean = aMeshClean.
nbVertex() == 4;
226 trace.
info() <<
"get firt vertex index of second face : " << aMeshClean.
nbVertex() ;
227 bool okClean2 = aMeshClean.
getFace(1)[0] == 3;
228 trace.
info() <<
"(should be 3) "<< (okClean2?
"[ok]":
"[error]") << std::endl;
232 ok = ok & okMeshConstruct && okMeshIterators && okMeshColor && okMeshCopy && boundingBoxOK &&
233 okSubDivide && okQuadToTrans && okRemoveFace && okClean && okClean2;
253 std::vector<Z3i::RealPoint> aSkeleton;
273 trace.
info() <<
"Nb faces: "<< aMesh.
nbFaces() <<
" (sould be 320)" << std::endl;
274 trace.
info() <<
"Nb vertices: "<< aMesh.
nbVertex() <<
" (sould be 352)" << std::endl;
277 trace.
beginBlock (
"Testing Tube generation (bis with variable raidii ..." );
279 std::vector<double> vectRadii;
280 vectRadii.push_back(0.5);
281 vectRadii.push_back(1.5);
282 vectRadii.push_back(2.5);
286 trace.
info() <<
"Nb faces: "<< aMeshBis.
nbFaces() <<
" (sould be 320)" << std::endl;
287 trace.
info() <<
"Nb vertices: "<< aMeshBis.
nbVertex() <<
" (sould be 352)" << std::endl;
289 std::ofstream ofbis (
"tubeVariableRadiiGeneratedFromTestMesh.off");
292 bool okMeshTube1bis = aMeshBis.
nbFaces() == 320 && aMeshBis.
nbVertex() == 352;
297 std::vector<double> heightSequence;
298 heightSequence.push_back(0.1);
299 heightSequence.push_back(0.2);
300 heightSequence.push_back(0.15);
302 heightSequence.push_back(1.1);
303 heightSequence.push_back(2.2);
304 heightSequence.push_back(1.15);
306 heightSequence.push_back(0.1);
307 heightSequence.push_back(0.2);
308 heightSequence.push_back(0.15);
315 trace.
info() <<
"Nb faces: "<< aMesh.
nbFaces() <<
" (sould be 324)" << std::endl;
316 trace.
info() <<
"Nb vertices: "<< aMesh.
nbVertex() <<
" (sould be 361)" << std::endl;
317 bool okMeshTube1AndHF = aMesh.
nbFaces() == 324 && aMesh.
nbVertex() == 361;
320 std::ofstream of (
"tubeAndHeighFieldGeneratedFromTestMesh.off");
325 ok = ok & okMeshTube1 & okMeshTube1bis & okMeshTube1AndHF;
337 unsigned int nbok = 0;
340 trace.
beginBlock(
"Testing visual tubular mesh generation (shell mesh):");
342 std::vector<Z3i::RealPoint> centerline;
343 unsigned int nbPoints = 0;
345 double radiusSpirale = 13.0;
346 double radiusTube = 15.0;
347 double alphaMax = 32.0;
349 for (
double alpha = 0; alpha< alphaMax; alpha += 0.1, z += 0.5-reduc)
351 centerline.push_back(
Z3i::RealPoint(radiusSpirale*cos(alpha), radiusSpirale*sin(alpha), z ));
353 radiusSpirale -=reduc;
354 radiusSpirale = std::max(radiusSpirale, 0.0);
357 std::vector<double> vectRadius;
358 for(
unsigned int i=0; i<nbPoints; i++)
360 vectRadius.push_back(radiusTube);
362 radiusTube = std::max(radiusTube, 0.0);
369 <<
" faces (should be " << (centerline.size()-1)*63 <<
" )" << std::endl;
371 nbok += theMeshShell.
nbFaces() == (centerline.size()-1)*63;
372 theMeshShell >>
"spiraleGeneratedFromTestMesh.off";
378 trace.
beginBlock(
"Testing visual tubular mesh generation (tube mesh):");
379 std::vector<Z3i::RealPoint> centerLine2;
413 trace.
info() <<
"Mesh generated with " << theMeshTube.
nbFaces() <<
" faces (should be "
414 << (centerLine2.size()-1)*32 <<
" )" << std::endl;
416 nbok += theMeshTube.
nbFaces() == (centerLine2.size()-1)*32;
418 theMeshTube >>
"tubeGeneratedFromTestMesh.off";
428int main(
int argc,
char** argv )
432 for (
int i = 0; i < argc; ++i )
437 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
static const Color Yellow
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
const Color & getFaceColor(Index i) const
DGtal::PointVector< TPoint::dimension, double > RealPoint
std::pair< TPoint, TPoint > getBoundingBox() const
void addQuadFace(Index indexVertex1, Index indexVertex2, Index indexVertex3, Index indexVertex4, const DGtal::Color &aColor=DGtal::Color::White)
void rescale(const typename TPoint::Component aScale)
RealPoint getFaceBarycenter(Index i) const
unsigned int quadToTriangularFaces()
const MeshFace & getFace(Index i) const
void setFaceColor(Index i, const DGtal::Color &aColor)
FaceStorage::const_iterator faceEnd() const
void invertVertexFaceOrder()
static void createMeshFromHeightSequence(Mesh< TPoint > &aMesh, const std::vector< TValue > &anValueSequence, const unsigned int lengthSequence, double stepX, double stepY, double stepZ, const DGtal::Color &aMeshColor=DGtal::Color::White)
const TPoint & getVertex(Index i) const
ConstIterator vertexEnd() const
std::vector< Index > MeshFace
void removeFaces(const std::vector< Index > &facesIndex)
double subDivideTriangularFaces(const double minArea)
void addTriangularFace(Index indexVertex1, Index indexVertex2, Index indexVertex3, const DGtal::Color &aColor=DGtal::Color::White)
FaceStorage::const_iterator faceBegin() const
ConstIterator vertexBegin() const
void removeIsolatedVertices()
static void createTubularMesh(Mesh< TPoint > &aMesh, const std::vector< TPoint > &aSkeleton, const double aRadius, const double angleStep=0.2, const DGtal::Color &aMeshColor=DGtal::Color::White)
void addVertex(const TPoint &vertex)
void beginBlock(const std::string &keyword="")
Z2i this namespace gathers the standard of types for 2D imagery.
Space::RealPoint RealPoint
DGtal is the top-level namespace which contains all DGtal functions and types.
static bool export2OFF(std::ostream &out, const Mesh< TPoint > &aMesh, bool exportColor=true)
bool testMeshGeneration()
bool testVisualTubularMesh()