DGtal 1.3.0
Loading...
Searching...
No Matches
testMeshReader.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/shapes/Mesh.h"
34#include "DGtal/io/readers/MeshReader.h"
35#include "DGtal/helpers/StdDefs.h"
36
37#include "ConfigTest.h"
38
40
41using namespace std;
42using namespace DGtal;
43
44
45
46struct Point3D{
47 using Component = double;
48
49 static const unsigned int dimension = 3;
50 const Component & operator[]( unsigned int i ) const{
51 assert(i<3);
52 switch (i){
53 case 0: {return x;}
54 case 1: {return y;}
55 case 2: {return z;}
56 }
57 return x;
58 };
59
60 Component & operator[]( unsigned int i ) {
61 assert(i<3);
62 switch (i){
63 case 0: {return x;}
64 case 1: {return y;}
65 case 2: {return z;}
66 }
67 return x;
68 };
69
70 Component x, y,z;
71};
72
73
74typedef Point3D Point;
75
76
77
78
79
80
81
82
84// Functions for testing class MeshReader.
86
91{
92 unsigned int nbok = 0;
93 unsigned int nb = 0;
94 trace.beginBlock ( "Testing block ..." );
95 nb++;
96 std::string filenameOFF = testPath + "samples/box.off";
97 Mesh<Point> a3DMesh;
98 bool importOK = a3DMesh << filenameOFF;
99 nbok += importOK ? 1 : 0;
100
101
102 nb++;
103 Mesh<Point>::MeshFace aFace = a3DMesh.getFace(0);
104 bool isWellImported = (a3DMesh.nbVertex()==8) && (a3DMesh.nbFaces()==6) && (aFace.size()==4) && (aFace.at(0)==0);
105 nbok+=isWellImported? 1: 0;
106
107
108 trace.info() << "(" << nbok << "/" << nb << ") "
109 << "true == true" << std::endl;
110
111
112 nb++;
113 std::string filenameOFS = testPath + "samples/testMesh.ofs";
114 Mesh<Point> a3DMesh2;
115 bool importOK2= a3DMesh2 << filenameOFS;
116 nbok += importOK2 ? 1 : 0;
117
118 nb++;
119 std::string filenameOBJ = testPath + "samples/testObj.obj";
120 Mesh<Point> a3DMesh3;
121 bool importOK3= a3DMesh3 << filenameOBJ;
122 nbok += importOK3 ? 1 : 0;
123
124 nb++;
125 bool importOK4 = a3DMesh3.getFaceColor(0) == DGtal::Color::Red &&
126 a3DMesh3.getFaceColor(5) == DGtal::Color::Purple;
127 nbok += importOK4 ? 1 : 0;
128
129 nb++;
130 Mesh<Point>::MeshFace aFace2 = a3DMesh2.getFace(0);
131 bool isWellImported2 = (a3DMesh2.nbVertex()==32) && (a3DMesh2.nbFaces()==60) && (aFace2.size()==3) && (aFace2.at(0)==0);
132 nbok+=isWellImported2? 1: 0;
133
134 nb++;
135 std::string filenameOBJrel = testPath + "samples/testObjRel.obj";
136 Mesh<Point> a3DMesh4;
137 bool importOK5 = a3DMesh4 << filenameOBJrel;
138 nbok += importOK5 ? 1 : 0;
139
140 nb++;
141 bool importOK6 = a3DMesh4.getFaceColor(0) == DGtal::Color::Red &&
142 a3DMesh4.getFaceColor(5) == DGtal::Color::Purple;
143 nbok += importOK6 ? 1 : 0;
144
145
146 trace.info() << "(" << nbok << "/" << nb << ") "
147 << "true == true" << std::endl;
148 trace.endBlock();
149
150
151 return nbok == nb;
152}
153
155// Standard services - public :
156
157int main( int argc, char** argv )
158{
159 trace.beginBlock ( "Testing class MeshReader" );
160 trace.info() << "Args:";
161 for ( int i = 0; i < argc; ++i )
162 trace.info() << " " << argv[ i ];
163 trace.info() << endl;
164
165 bool res = testMeshReader(); // && ... other tests
166 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
167 trace.endBlock();
168 return res ? 0 : 1;
169}
170// //
static const Color Purple
Definition: Color.h:424
static const Color Red
Definition: Color.h:416
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:92
const Color & getFaceColor(Index i) const
Size nbFaces() const
Size nbVertex() const
const MeshFace & getFace(Index i) const
std::vector< Index > MeshFace
Definition: Mesh.h:126
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
int main()
Definition: testBits.cpp:56
Point3D Point
bool testMeshReader()