DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testMeshReader.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
34 #include "DGtal/shapes/fromPoints/MeshFromPoints.h"
35 #include "DGtal/io/readers/MeshReader.h"
37 #include "DGtal/helpers/StdDefs.h"
38 
39 #include "ConfigTest.h"
40 
42 
43 using namespace std;
44 using namespace DGtal;
45 
46 
47 
48 struct Point3D{
49  const double & operator[]( unsigned int i ) const{
50  assert(i<3);
51  switch (i){
52  case 0: {return x;}
53  case 1: {return y;}
54  case 2: {return z;}
55  }
56  return x;
57  };
58 
59  double & operator[]( unsigned int i ) {
60  assert(i<3);
61  switch (i){
62  case 0: {return x;}
63  case 1: {return y;}
64  case 2: {return z;}
65  }
66  return x;
67  };
68 
69  double x, y,z;
70 };
71 
72 
73 typedef Point3D Point;
74 
75 
76 
77 
78 
79 
80 
81 
83 // Functions for testing class MeshReader.
85 
89 bool testMeshReader()
90 {
91  unsigned int nbok = 0;
92  unsigned int nb = 0;
93  trace.beginBlock ( "Testing block ..." );
94  nb++;
96  std::string filenameOFF = testPath + "samples/box.off";
97  MeshFromPoints<Point> a3DMesh;
98  bool importOK = a3DMesh << filenameOFF;
100  nbok += importOK ? 1 : 0;
101 
102 
103  nb++;
104  MeshFromPoints<Point>::MeshFace aFace = a3DMesh.getFace(0);
105  bool isWellImported = (a3DMesh.nbVertex()==8) && (a3DMesh.nbFaces()==6) && (aFace.size()==4) && (aFace.at(0)==0);
106  nbok+=isWellImported? 1: 0;
107 
108 
109  trace.info() << "(" << nbok << "/" << nb << ") "
110  << "true == true" << std::endl;
111 
112 
113  nb++;
114  std::string filenameOFS = testPath + "samples/testMesh.ofs";
115  MeshFromPoints<Point> a3DMesh2;
116  bool importOK2= a3DMesh2 << filenameOFS;
117  nbok += importOK2 ? 1 : 0;
118 
119  nb++;
120  MeshFromPoints<Point>::MeshFace aFace2 = a3DMesh2.getFace(0);
121  bool isWellImported2 = (a3DMesh2.nbVertex()==32) && (a3DMesh2.nbFaces()==60) && (aFace2.size()==3) && (aFace2.at(0)==0);
122  nbok+=isWellImported2? 1: 0;
123 
124 
125  trace.info() << "(" << nbok << "/" << nb << ") "
126  << "true == true" << std::endl;
127  trace.endBlock();
128 
129 
130 
131 
132 
133 
134 
135 
136  return nbok == nb;
137 }
138 
140 // Standard services - public :
141 
142 int main( int argc, char** argv )
143 {
144  trace.beginBlock ( "Testing class MeshReader" );
145  trace.info() << "Args:";
146  for ( int i = 0; i < argc; ++i )
147  trace.info() << " " << argv[ i ];
148  trace.info() << endl;
149 
150  bool res = testMeshReader(); // && ... other tests
151  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
152  trace.endBlock();
153  return res ? 0 : 1;
154 }
155 // //