DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testImplicitShape.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/shapes/Shapes.h"
35 #include "DGtal/shapes/ShapeFactory.h"
36 #include "DGtal/io/boards/Board2D.h"
37 #include "DGtal/io/colormaps/GrayscaleColorMap.h"
38 #include "DGtal/io/writers/VolWriter.h"
39 #include "DGtal/images/ImageContainerBySTLVector.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 // Functions for testing class ImplicitShape.
48 
52 bool testImplicitShape()
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
57  trace.beginBlock ( "Testing implicit shaper ..." );
58  Z2i::Point a(0,0);
59  Z2i::Point b(64,64);
60  Z2i::Point c(32,32);
61 
62  Board2D board;
63 
64  Z2i::Domain domain(a,b);
65  Z2i::DigitalSet set(domain);
66 
68  ImplicitBall<Z2i::Space>( c, 10));
69  board << set;
70  board.saveSVG("implicitball.svg");
71 
72  set.clear();
73  board.clear();
76  board << set;
77  board.saveSVG("implicitcube.svg");
78 
79 
80  set.clear();
81  board.clear();
84  board << set;
85  board.saveSVG("implicitlosange.svg");
86 
87  set.clear();
88  board.clear();
91  board << set;
92  board.saveSVG("implicitrounded-1.svg");
93 
94 
95  set.clear();
96  board.clear();
99  board << set;
100  board.saveSVG("implicitrounded-2.5.svg");
101 
102 
103  nbok += true ? 1 : 0;
104  nb++;
105  trace.info() << "(" << nbok << "/" << nb << ") "
106  << "true == true" << std::endl;
107  trace.endBlock();
108 
109  return nbok == nb;
110 }
115 bool testImplicitShape3D()
116 {
117  unsigned int nbok = 0;
118  unsigned int nb = 0;
119 
120  trace.beginBlock ( "Testing implicit shaper in 3D..." );
121  Z3i::Point a(0,0);
122  Z3i::Point b(64,64,64);
123  Z3i::Point c(32,32,32);
124 
125  Z3i::Domain domain(a,b);
126 
128 
129  Image image(domain);
130  Z3i::DigitalSet set(domain);
131 
134 
135  for(Z3i::DigitalSet::ConstIterator it=set.begin(), itend=set.end();
136  it != itend;
137  ++it)
138  {
139  image.setValue((*it), 128);
140  }
141 
142  VolWriter<Image>::exportVol("implicitrounded.vol",image);
143 
144  nbok += true ? 1 : 0;
145  nb++;
146  trace.info() << "(" << nbok << "/" << nb << ") "
147  << "true == true" << std::endl;
148  trace.endBlock();
149 
150  return nbok == nb;
151 }
152 
154 // Standard services - public :
155 
156 int main( int argc, char** argv )
157 {
158  trace.beginBlock ( "Testing class ImplicitShape" );
159  trace.info() << "Args:";
160  for ( int i = 0; i < argc; ++i )
161  trace.info() << " " << argv[ i ];
162  trace.info() << endl;
163 
164  bool res = testImplicitShape() && testImplicitShape3D(); // && ... other tests
165  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
166  trace.endBlock();
167  return res ? 0 : 1;
168 }
169 // //