DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testMeshReader.cpp
Go to the documentation of this file.
1
16
29
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
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
90
bool
testMeshReader
()
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
157
int
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
// //
DGtal::Color::Purple
static const Color Purple
Definition
Color.h:433
DGtal::Color::Red
static const Color Red
Definition
Color.h:425
DGtal::Mesh
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition
Mesh.h:92
DGtal::Mesh::getFaceColor
const Color & getFaceColor(Index i) const
DGtal::Mesh::nbFaces
Size nbFaces() const
DGtal::Mesh::nbVertex
Size nbVertex() const
DGtal::Mesh::getFace
const MeshFace & getFace(Index i) const
DGtal::Mesh::MeshFace
std::vector< Index > MeshFace
Definition
Mesh.h:126
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
Point3D
Definition
testMeshReader.cpp:46
Point3D::y
Component y
Definition
testMeshReader.cpp:70
Point3D::dimension
static const unsigned int dimension
Definition
testMeshReader.cpp:49
Point3D::Component
double Component
Definition
testMeshReader.cpp:47
Point3D::z
Component z
Definition
testMeshReader.cpp:70
Point3D::x
Component x
Definition
testMeshReader.cpp:70
Point3D::operator[]
const Component & operator[](unsigned int i) const
Definition
testMeshReader.cpp:50
Point3D::operator[]
Component & operator[](unsigned int i)
Definition
testMeshReader.cpp:60
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testMeshReader
bool testMeshReader()
Definition
testMeshReader.cpp:90
tests
io
readers
testMeshReader.cpp
Generated on
for DGtal by
1.18.0