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"
39 using namespace DGtal;
89 trace.
info() << p0f0 << p1f0 << p2f0<< endl;
92 trace.
info() << p0f1 << p1f1 << p2f1<< endl;
95 bool okMeshConstruct = (p0==p0f0) && (p1==p1f0) && (p2==p2f0) &&
96 (p3==p0f1) && (p4==p1f1) && (p5==p2f1) ;
99 bool okMeshIterators =
true;
108 okMeshIterators = okMeshIterators && (nb == aMesh.
nbVertex());
110 trace.
info() <<
"vertex iteration test ok"<<std::endl;
116 (*it)[0]+=10; (*it)[1]+=5;
125 okMeshIterators = okMeshIterators && (nb == aMesh.
nbFaces());
127 trace.
info() <<
"face iteration test ok"<<std::endl;
138 trace.
info() <<
"getVertex and getFaceCenter tests ok"<<std::endl;
150 bool boundingBoxOK = (bb.first ==
Point(20,10)) && (bb.second ==
Point(26,18));
151 trace.
info() <<
"bouding box=" << bb.first <<
" " << bb.second <<
"(should be (20,10) (26,18)" <<std::endl;
161 trace.
info() <<
"nb vertices before subdivision: " << aMeshR.
nbVertex() << std::endl;
162 trace.
info() <<
"nb faces before subdivision: " << aMeshR.
nbFaces() << std::endl;
164 trace.
info() <<
"nb vertices after subdivision: " << aMeshR.
nbVertex() <<
" (should be 4)"<<std::endl;
165 trace.
info() <<
"nb faces after subdivision: " << aMeshR.
nbFaces() <<
" (should be 3)" <<std::endl;
169 trace.
info() << (okSubDivide ?
"[subdivise OK]":
"[subdivise fail]" ) << std::endl;
183 trace.
info() <<
"nb faces after quad to triangle transform: " << aMeshQ.
nbFaces() ;
184 bool okQuadToTrans = aMeshQ.
nbFaces() == 2;
185 trace.
info() <<
"(should be 2) "<< (okQuadToTrans?
"[ok]":
"[error]") << std::endl;
195 trace.
info() << (okMeshCopy ?
"[copy ok]":
"[copy fail]" ) << std::endl;
200 std::vector<unsigned int> f = {1};
203 trace.
info() << (okRemoveFace ?
"[face remove ok]":
"[face remove fail]" ) << std::endl;
205 ok = ok & okMeshConstruct && okMeshIterators && okMeshColor && okMeshCopy && boundingBoxOK &&
206 okSubDivide && okQuadToTrans && okRemoveFace;
225 std::vector<Z3i::RealPoint> aSkeleton;
245 trace.
info() <<
"Nb faces: "<< aMesh.
nbFaces() <<
" (sould be 320)" << std::endl;
246 trace.
info() <<
"Nb vertices: "<< aMesh.
nbVertex() <<
" (sould be 352)" << std::endl;
249 trace.
beginBlock (
"Testing Tube generation (bis with variable raidii ..." );
251 std::vector<double> vectRadii;
252 vectRadii.push_back(0.5);
253 vectRadii.push_back(1.5);
254 vectRadii.push_back(2.5);
258 trace.
info() <<
"Nb faces: "<< aMeshBis.
nbFaces() <<
" (sould be 320)" << std::endl;
259 trace.
info() <<
"Nb vertices: "<< aMeshBis.
nbVertex() <<
" (sould be 352)" << std::endl;
261 std::ofstream ofbis (
"tubeVariableRadiiGeneratedFromTestMesh.off");
264 bool okMeshTube1bis = aMeshBis.
nbFaces() == 320 && aMeshBis.
nbVertex() == 352;
269 std::vector<double> heightSequence;
270 heightSequence.push_back(0.1);
271 heightSequence.push_back(0.2);
272 heightSequence.push_back(0.15);
274 heightSequence.push_back(1.1);
275 heightSequence.push_back(2.2);
276 heightSequence.push_back(1.15);
278 heightSequence.push_back(0.1);
279 heightSequence.push_back(0.2);
280 heightSequence.push_back(0.15);
287 trace.
info() <<
"Nb faces: "<< aMesh.
nbFaces() <<
" (sould be 324)" << std::endl;
288 trace.
info() <<
"Nb vertices: "<< aMesh.
nbVertex() <<
" (sould be 361)" << std::endl;
289 bool okMeshTube1AndHF = aMesh.
nbFaces() == 324 && aMesh.
nbVertex() == 361;
292 std::ofstream of (
"tubeAndHeighFieldGeneratedFromTestMesh.off");
297 ok = ok & okMeshTube1 & okMeshTube1bis & okMeshTube1AndHF;
309 unsigned int nbok = 0;
312 trace.
beginBlock(
"Testing visual tubular mesh generation (shell mesh):");
314 std::vector<Z3i::RealPoint> centerline;
315 unsigned int nbPoints = 0;
317 double radiusSpirale = 13.0;
318 double radiusTube = 15.0;
319 double alphaMax = 32.0;
321 for (
double alpha = 0; alpha< alphaMax; alpha += 0.1, z += 0.5-reduc)
323 centerline.push_back(
Z3i::RealPoint(radiusSpirale*cos(alpha), radiusSpirale*sin(alpha), z ));
325 radiusSpirale -=reduc;
326 radiusSpirale =
std::max(radiusSpirale, 0.0);
329 std::vector<double> vectRadius;
330 for(
unsigned int i=0; i<nbPoints; i++)
332 vectRadius.push_back(radiusTube);
334 radiusTube =
std::max(radiusTube, 0.0);
341 <<
" faces (should be " << (centerline.size()-1)*63 <<
" )" << std::endl;
343 nbok += theMeshShell.
nbFaces() == (centerline.size()-1)*63;
344 theMeshShell >>
"spiraleGeneratedFromTestMesh.off";
350 trace.
beginBlock(
"Testing visual tubular mesh generation (tube mesh):");
351 std::vector<Z3i::RealPoint> centerLine2;
385 trace.
info() <<
"Mesh generated with " << theMeshTube.
nbFaces() <<
" faces (should be "
386 << (centerLine2.size()-1)*32 <<
" )" << std::endl;
388 nbok += theMeshTube.
nbFaces() == (centerLine2.size()-1)*32;
390 theMeshTube >>
"tubeGeneratedFromTestMesh.off";
400 int main(
int argc,
char** argv )
404 for (
int i = 0; i < argc; ++i )
409 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....
unsigned int quadToTriangularFaces()
const Color & getFaceColor(unsigned int i) const
std::vector< unsigned int > MeshFace
void addQuadFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, unsigned int indexVertex4, const DGtal::Color &aColor=DGtal::Color::White)
void changeScale(const typename TPoint::Component aScale)
std::pair< TPoint, TPoint > getBoundingBox() const
const MeshFace & getFace(unsigned int i) const
RealPoint getFaceBarycenter(unsigned int i) const
FaceStorage::const_iterator faceEnd() const
const TPoint & getVertex(unsigned int i) const
void setFaceColor(unsigned int i, const DGtal::Color &aColor)
ConstIterator vertexEnd() const
void addTriangularFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, const DGtal::Color &aColor=DGtal::Color::White)
double subDivideTriangularFaces(const double minArea)
void removeFaces(const std::vector< unsigned int > &facesIndex)
FaceStorage::const_iterator faceBegin() const
ConstIterator vertexBegin() const
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.
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()
int main(int argc, char **argv)
bool testVisualTubularMesh()