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