DGtal 1.4.0
Loading...
Searching...
No Matches
testMeshWriter.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/shapes/Mesh.h"
36#include "DGtal/io/writers/MeshWriter.h"
39
40using namespace std;
41using namespace DGtal;
42using namespace Z3i;
43
45// Functions for testing class MeshWriter.
47
48
54{
55 unsigned int nbok = 0;
56 unsigned int nb = 0;
58 // Constructing the mesh to export in OFF format
59 Mesh<Point> aMesh(true);
60 vector<Point> vectVertex;
61 Point p1(0, 0, 0);
62 Point p2(1, 0, 0);
63 Point p3(1, 1, 0);
64 Point p4(0, 1, 0);
65 Point p11(0, 0, 1);
66 Point p21(1, 0, 1);
67 Point p31(1, 1, 1);
68 Point p41(0, 1, 1);
69 aMesh.addVertex(p1);
70 aMesh.addVertex(p2);
71 aMesh.addVertex(p3);
72 aMesh.addVertex(p4);
73 aMesh.addVertex(p11);
74 aMesh.addVertex(p21);
75 aMesh.addVertex(p31);
76 aMesh.addVertex(p41);
77
78 vector<DGtal::Color> vectColor;
79 DGtal::Color col (250,0,0, 200);
80 DGtal::Color col2 (250,250,0, 200);
81
82 aMesh.addQuadFace(0,1,2,3, col);
83 aMesh.addQuadFace(4,5,6,7, col2);
84 aMesh.addQuadFace(0,1,5,4, col);
85
88 bool isOK = aMesh >> "test.off";
90 nb++;
91 bool isOK2 = aMesh >> "testColor.obj";
92 nb++;
93 std::fstream exportObj;
94 exportObj.open("test.obj", std::fstream::out);
95 bool isOK3 = MeshWriter<Point>::export2OBJ(exportObj, aMesh);
96
97 nb++;
98
99 trace.beginBlock ( "Testing block ..." );
100 nbok += isOK ? 1 : 0;
101 nbok += isOK2 ? 1 : 0;
102 nbok += isOK3 ? 1 : 0;
103
104 trace.info() << "(" << nbok << "/" << nb << ") "
105 << "true == true" << std::endl;
106 trace.endBlock();
107 return nbok == nb;
108}
109
111// Standard services - public :
112
113int main( int argc, char** argv )
114{
115 trace.beginBlock ( "Testing class MeshWriter" );
116 trace.info() << "Args:";
117 for ( int i = 0; i < argc; ++i )
118 trace.info() << " " << argv[ i ];
119 trace.info() << endl;
120
121 bool res = testMeshWriter(); // && ... other tests
122 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
123 trace.endBlock();
124 return res ? 0 : 1;
125}
126// //
128
129
Structure representing an RGB triple with alpha component.
Definition Color.h:68
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition Mesh.h:92
void addQuadFace(Index indexVertex1, Index indexVertex2, Index indexVertex3, Index indexVertex4, const DGtal::Color &aColor=DGtal::Color::White)
void addVertex(const TPoint &vertex)
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:153
STL namespace.
static bool export2OBJ(std::ostream &out, const Mesh< TPoint > &aMesh)
int main()
Definition testBits.cpp:56
bool testMeshWriter()