DGtal  0.9.2
testBoard3D.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/io/boards/Board3D.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 using namespace Z3i;
41 
43 // Functions for testing class Board3D.
45 
49 bool testBoard3D()
50 {
51  unsigned int nbok = 0;
52  unsigned int nb = 0;
53  trace.beginBlock ( "Testing Board3D ..." );
54 
55 
56 
57  Point p1( -3, -2, 0 );
58  Point p2( 7, 3 , 6);
59  Point p3( -1, -1, -1);
60  Point p4(-1, -1, 0 );
61  Point p5( 5, 2 , 4);
62  Point p6(-3, -6, 0 );
63  Point p7( 5, 2 , 3);
64 
65  Domain domain(p6, p7);
66  DigitalSet shape_set( domain );
67  shape_set.insertNew(p6);
68  shape_set.insertNew(p7);
69 
70  Board3D<> board;
71  board << SetMode3D(domain.className(), "Paving");
72  board << p1 << p2 << p3;
73  board << shape_set;
74  board.saveOBJ("dgtalBoard3D-1-points.obj");
75 
76  trace.info()<<" Second"<<std::endl;
77  Board3D<> board2;
78  board2 << SetMode3D(domain.className(), "Paving");
79  board2 << CustomColors3D(Color(250, 0,0),Color(250, 0,0));
80  board2 << p1 ;
81  board2 << CustomColors3D(Color(0, 255,0),Color(0, 255,0));
82  board2 << p2 << p3;
83  board2 << CustomColors3D(Color(0, 0,255),Color(0, 0,255));
84  board2 << p6;
85 
86  board2.saveOBJ("dgtalBoard3D-1bis-points.obj");
87 
88  nbok += true ? 1 : 0;
89  nb++;
90  trace.info() << "(" << nbok << "/" << nb << ") "
91  << "true == true" << std::endl;
92  trace.endBlock();
93 
94  return nbok == nb;
95 }
96 
97 bool testQuadNorm()
98 {
99  unsigned int nbok = 0;
100  unsigned int nb = 0;
101  trace.beginBlock ( "Testing Board3D Quads ..." );
102 
103 
104 
105  Point p1( 0, 0, 0 );
106  Point p2( 0, 1 , 0);
107  Point p3( 1, 1, 0);
108  Point p4(1, 0, 0 );
109  Point p5( 2, 0 , 0);
110  Point p6( 2, 1, 0);
111  RealVector n(1,1,1);
112  RealVector n2(0,1,1);
113 
114  KSpace k;
115 
116  k.init(Point(2,2,2), Point(4,4,4), true);
117 
118  Board3D<Space,KSpace> board(k);
119  board << CustomColors3D(Color(0, 255,0),Color(0, 255, 0));
120  board.addQuadWithNormal(p1,p2,p3,p4, n.getNormalized(), true);
121  board << CustomColors3D(Color(0, 0, 255),Color(0, 0, 255));
122  board.addQuadWithNormal(p4,p5,p6,p3, n2.getNormalized(), true);
123 
124  Cell surfel = k.uCell( Point( 4,5,5) );
125  Display3DFactory<Space,KSpace>::drawUnorientedSurfelWithNormal( board, surfel, n2.getNormalized());
126 
127  board.saveOBJ("dgtalBoard3D.quad.obj");
128 
129 
130  nbok += true ? 1 : 0;
131  nb++;
132  trace.info() << "(" << nbok << "/" << nb << ") "
133  << "true == true" << std::endl;
134  trace.endBlock();
135 
136  return nbok == nb;
137 }
138 
139 
140 bool testNormaliation()
141 {
142  trace.beginBlock ( "Testing normalization ..." );
143 
144  Point p1( 0, 0, 0 );
145  Point p2( 0, 10 , 0);
146  Point p3( 10, 10, 0);
147  Point p4(10, 0, 100 );
148  Point p5( 20, 0 , 0);
149  Point p6( 20, 10, 0);
150 
151  KSpace k;
152 
153  k.init(Point(2,2,2), Point(4,4,4), true);
154 
155  Board3D<Space,KSpace> board(k);
156 
157  board << p1<<p2<<p3<<p4;
158 
159  board.saveOBJ("dgtalBoard3D-norm.obj", true);
160  board.saveOBJ("dgtalBoard3D-wonorm.obj");
161 
162  trace.endBlock();
163 
164  return true;
165 }
166 
167 
168 bool testShapes()
169 {
170  trace.beginBlock ( "Testing shapes ..." );
171 
172  RealPoint p1( 0, 0, 0 );
173  RealPoint p2(10, 10, 0);
174 
175  Board3D<Space,KSpace> board;
176 
177  board.setLineColor(Color::Red);
178  board.addLine(p1,p2, 0.5);
179 
180  board.saveOBJ("dgtalBoard3D-line.obj");
181 
182  trace.endBlock();
183 
184  return true;
185 }
186 
187 
188 
190 // Standard services - public :
191 
192 int main( int argc, char** argv )
193 {
194  trace.beginBlock ( "Testing class Board3D" );
195  trace.info() << "Args:";
196  for ( int i = 0; i < argc; ++i )
197  trace.info() << " " << argv[ i ];
198  trace.info() << endl;
199 
200 bool res = testBoard3D() && testQuadNorm()
201  && testNormaliation()
202  && testShapes(); // && ... other tests
203  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
204  trace.endBlock();
205  return res ? 0 : 1;
206 }
207 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
void saveOBJ(const std::string &filename, const bool isNormalized=false)
STL namespace.
double endBlock()
virtual void setLineColor(DGtal::Color aColor)
Factory for GPL Display3D:
Cell uCell(const PreCell &c) const
std::string className() const
std::ostream & emphase()
bool init(const Point &lower, const Point &upper, bool isClosed)
The class Board3D is a type of Display3D which export the figures in the format OBJ/MTL when calling ...
Definition: Board3D.h:81
void addLine(const RealPoint &p1, const RealPoint &p2, const double width=0.03)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void addQuadWithNormal(const RealPoint &p1, const RealPoint &p2, const RealPoint &p3, const RealPoint &p4, const RealPoint &n, const bool enableReorientation, const bool enableDoubleFace=false)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.