DGtal  0.9.3
testMeshReader.cpp
Go to the documentation of this file.
1 
30 #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 
41 using namespace std;
42 using namespace DGtal;
43 
44 
45 
46 struct Point3D{
47  static const unsigned int dimension = 3;
48  const double & operator[]( unsigned int i ) const{
49  assert(i<3);
50  switch (i){
51  case 0: {return x;}
52  case 1: {return y;}
53  case 2: {return z;}
54  }
55  return x;
56  };
57 
58  double & operator[]( unsigned int i ) {
59  assert(i<3);
60  switch (i){
61  case 0: {return x;}
62  case 1: {return y;}
63  case 2: {return z;}
64  }
65  return x;
66  };
67 
68  double x, y,z;
69 };
70 
71 
72 typedef Point3D Point;
73 
74 
75 
76 
77 
78 
79 
80 
82 // Functions for testing class MeshReader.
84 
89 {
90  unsigned int nbok = 0;
91  unsigned int nb = 0;
92  trace.beginBlock ( "Testing block ..." );
93  nb++;
94  std::string filenameOFF = testPath + "samples/box.off";
95  Mesh<Point> a3DMesh;
96  bool importOK = a3DMesh << filenameOFF;
97  nbok += importOK ? 1 : 0;
98 
99 
100  nb++;
101  Mesh<Point>::MeshFace aFace = a3DMesh.getFace(0);
102  bool isWellImported = (a3DMesh.nbVertex()==8) && (a3DMesh.nbFaces()==6) && (aFace.size()==4) && (aFace.at(0)==0);
103  nbok+=isWellImported? 1: 0;
104 
105 
106  trace.info() << "(" << nbok << "/" << nb << ") "
107  << "true == true" << std::endl;
108 
109 
110  nb++;
111  std::string filenameOFS = testPath + "samples/testMesh.ofs";
112  Mesh<Point> a3DMesh2;
113  bool importOK2= a3DMesh2 << filenameOFS;
114  nbok += importOK2 ? 1 : 0;
115 
116  nb++;
117  Mesh<Point>::MeshFace aFace2 = a3DMesh2.getFace(0);
118  bool isWellImported2 = (a3DMesh2.nbVertex()==32) && (a3DMesh2.nbFaces()==60) && (aFace2.size()==3) && (aFace2.at(0)==0);
119  nbok+=isWellImported2? 1: 0;
120 
121 
122  trace.info() << "(" << nbok << "/" << nb << ") "
123  << "true == true" << std::endl;
124  trace.endBlock();
125 
126 
127 
128 
129 
130 
131 
132 
133  return nbok == nb;
134 }
135 
137 // Standard services - public :
138 
139 int main( int argc, char** argv )
140 {
141  trace.beginBlock ( "Testing class MeshReader" );
142  trace.info() << "Args:";
143  for ( int i = 0; i < argc; ++i )
144  trace.info() << " " << argv[ i ];
145  trace.info() << endl;
146 
147  bool res = testMeshReader(); // && ... other tests
148  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
149  trace.endBlock();
150  return res ? 0 : 1;
151 }
152 // //
void beginBlock(const std::string &keyword="")
std::vector< unsigned int > MeshFace
Definition: Mesh.h:116
Trace trace
Definition: Common.h:137
unsigned int nbVertex() const
unsigned int nbFaces() const
Aim: This class is defined to represent a surface mesh through a set of vertices and faces...
Definition: Mesh.h:91
STL namespace.
double endBlock()
int main(int argc, char **argv)
Point3D Point
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
const MeshFace & getFace(unsigned int i) const
std::ostream & info()
bool testMeshReader()