DGtal  1.0.0
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  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 
74 typedef 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  Mesh<Point>::MeshFace aFace2 = a3DMesh2.getFace(0);
120  bool isWellImported2 = (a3DMesh2.nbVertex()==32) && (a3DMesh2.nbFaces()==60) && (aFace2.size()==3) && (aFace2.at(0)==0);
121  nbok+=isWellImported2? 1: 0;
122 
123 
124  trace.info() << "(" << nbok << "/" << nb << ") "
125  << "true == true" << std::endl;
126  trace.endBlock();
127 
128 
129  return nbok == nb;
130 }
131 
133 // Standard services - public :
134 
135 int main( int argc, char** argv )
136 {
137  trace.beginBlock ( "Testing class MeshReader" );
138  trace.info() << "Args:";
139  for ( int i = 0; i < argc; ++i )
140  trace.info() << " " << argv[ i ];
141  trace.info() << endl;
142 
143  bool res = testMeshReader(); // && ... other tests
144  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
145  trace.endBlock();
146  return res ? 0 : 1;
147 }
148 // //
void beginBlock(const std::string &keyword="")
std::vector< unsigned int > MeshFace
Definition: Mesh.h:116
Size nbVertex() const
Trace trace
Definition: Common.h:144
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:91
double endBlock()
int main(int argc, char **argv)
Point3D Point
Size nbFaces() const
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()