DGtal  1.0.0
testParametricCurveDigitization.cpp
Go to the documentation of this file.
1 
33 #include <iostream>
35 
36 #include "DGtalCatch.h"
37 #include "DGtal/base/Common.h"
38 #include "DGtal/helpers/StdDefs.h"
39 
40 #include "DGtal/geometry/curves/parametric/EllipticHelix.h"
41 #include "DGtal/geometry/curves/parametric/DecoratorParametricCurveTransformation.h"
42 #include "DGtal/geometry/curves/parametric/Knot_3_1.h"
43 #include "DGtal/geometry/curves/parametric/Knot_3_2.h"
44 #include "DGtal/geometry/curves/parametric/Knot_4_1.h"
45 #include "DGtal/geometry/curves/parametric/Knot_4_3.h"
46 #include "DGtal/geometry/curves/parametric/Knot_5_1.h"
47 #include "DGtal/geometry/curves/parametric/Knot_5_2.h"
48 #include "DGtal/geometry/curves/parametric/Knot_6_2.h"
49 #include "DGtal/geometry/curves/parametric/Knot_7_4.h"
50 #include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
51 #include "DGtal/images/RigidTransformation3D.h"
52 
54 
55 using namespace std;
56 using namespace DGtal;
57 using namespace Z3i;
58 using namespace functors;
59 
60 TEST_CASE( "Elliptic Helix test" )
61 {
62  typedef EllipticHelix < Space > MyHelix;
63  typedef NaiveParametricCurveDigitizer3D < MyHelix > DigitizerHelix;
66 
67  MyDigitalCurve digitalCurve;
68  MyMetaData metaData;
69  MyHelix helix( 15, 10, 1 );
70  DigitizerHelix digitize;
71  digitize.init ( M_PI / 2., MyHelix::getPeriod() + M_PI / 2., 0.001 );
72  digitize.attach ( &helix );
73  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
74 
75  SECTION("Data")
76  {
77  REQUIRE( digitalCurve.size ( ) > 0 );
78  }
79 
80  digitalCurve.clear ( );
81 
82  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
83 
84  SECTION("Size Comparisons")
85  {
86  REQUIRE( digitalCurve.size ( ) > 0 );
87  REQUIRE( metaData.size ( ) > 0 );
88  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
89  }
90 
91  SECTION("Inverses")
92  {
93  helix.f ( digitalCurve[0] );
94  helix.g ( digitalCurve[0] );
95  helix.h ( digitalCurve[0] );
96  }
97 
98 }
99 
100 
101 TEST_CASE( "Parametric Curve Decorator test" )
102 {
103  typedef EllipticHelix < Space > MyHelix;
104  typedef ForwardRigidTransformation3D < Space, RealPoint, RealPoint, Identity > ForwardTrans;
109 
110  MyDigitalCurve digitalCurve;
111  MyMetaData metaData;
112  MyHelix helix( 30, 20, 1 );
113 
114  double angle = M_PI/3.;
115  RealVector axis ( 1., 0., 1. );
116  ForwardTrans trans ( RealPoint ( 0, 0, 0 ), axis, angle, RealVector ( 0,0,0 ) );
117  MyRotatedCurve rotCurve ( helix, trans );
118 
119  Digitizer digitize;
120  digitize.attach ( &rotCurve );
121  digitize.init ( 0, MyHelix::getPeriod(), 0.001 );
122  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
123 
124  SECTION("Data")
125  {
126  REQUIRE( digitalCurve.size ( ) > 0 );
127  }
128 
129  digitalCurve.clear ( );
130 
131  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
132 
133  SECTION("Size Comparisons")
134  {
135  REQUIRE( digitalCurve.size ( ) > 0 );
136  REQUIRE( metaData.size ( ) > 0 );
137  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
138  }
139 }
140 
141 
142 TEST_CASE( "Knot 3_1 test" )
143 {
144  typedef Knot_3_1 < Space > MyKnot;
148 
149  MyDigitalCurve digitalCurve;
150  MyMetaData metaData;
151  MyKnot knot( 10, 10, 10 );
152  Digitizer digitize;
153  digitize.init ( -3., 3, 0.0001 );
154  digitize.attach ( &knot );
155  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
156 
157  SECTION("Data")
158  {
159  REQUIRE( digitalCurve.size ( ) > 0 );
160  }
161 
162  digitalCurve.clear ( );
163 
164  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
165 
166  SECTION("Size Comparisons")
167  {
168  REQUIRE( digitalCurve.size ( ) > 0 );
169  REQUIRE( metaData.size ( ) > 0 );
170  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
171  }
172 }
173 
174 
175 TEST_CASE( "Knot 3_2 test" )
176 {
177  typedef Knot_3_2 < Space > MyKnot;
181 
182  MyDigitalCurve digitalCurve;
183  MyMetaData metaData;
184  MyKnot knot( 10, 10, 10 );
185  Digitizer digitize;
186  digitize.init ( -3., 3, 0.0001 );
187  digitize.attach ( &knot );
188  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
189 
190  SECTION("Data")
191  {
192  REQUIRE( digitalCurve.size ( ) > 0 );
193  }
194 
195  digitalCurve.clear ( );
196 
197  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
198 
199  SECTION("Size Comparisons")
200  {
201  REQUIRE( digitalCurve.size ( ) > 0 );
202  REQUIRE( metaData.size ( ) > 0 );
203  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
204  }
205 }
206 
207 
208 TEST_CASE( "Knot 4_1 test" )
209 {
210  typedef Knot_4_1 < Space > MyKnot;
214 
215  MyDigitalCurve digitalCurve;
216  MyMetaData metaData;
217  MyKnot knot( 10, 10, 10 );
218  Digitizer digitize;
219  digitize.init ( -3., 3, 0.0001 );
220  digitize.attach ( &knot );
221  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
222 
223  SECTION("Data")
224  {
225  REQUIRE( digitalCurve.size ( ) > 0 );
226  }
227 
228  digitalCurve.clear ( );
229 
230  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
231 
232  SECTION("Size Comparisons")
233  {
234  REQUIRE( digitalCurve.size ( ) > 0 );
235  REQUIRE( metaData.size ( ) > 0 );
236  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
237  }
238 }
239 
240 
241 TEST_CASE( "Knot 4_3 test" )
242 {
243  typedef Knot_4_3 < Space > MyKnot;
247 
248  MyDigitalCurve digitalCurve;
249  MyMetaData metaData;
250  MyKnot knot( 10, 10, 10 );
251  Digitizer digitize;
252  digitize.init ( -3., 3, 0.0001 );
253  digitize.attach ( &knot );
254  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
255 
256  SECTION("Data")
257  {
258  REQUIRE( digitalCurve.size ( ) > 0 );
259  }
260 
261  digitalCurve.clear ( );
262 
263  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
264 
265  SECTION("Size Comparisons")
266  {
267  REQUIRE( digitalCurve.size ( ) > 0 );
268  REQUIRE( metaData.size ( ) > 0 );
269  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
270  }
271 }
272 
273 
274 TEST_CASE( "Knot 5_1 test" )
275 {
276  typedef Knot_5_1 < Space > MyKnot;
280 
281  MyDigitalCurve digitalCurve;
282  MyMetaData metaData;
283  MyKnot knot( 10, 10, 10 );
284  Digitizer digitize;
285  digitize.init ( -3., 3, 0.0001 );
286  digitize.attach ( &knot );
287  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
288 
289  SECTION("Data")
290  {
291  REQUIRE( digitalCurve.size ( ) > 0 );
292  }
293 
294  digitalCurve.clear ( );
295 
296  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
297 
298  SECTION("Size Comparisons")
299  {
300  REQUIRE( digitalCurve.size ( ) > 0 );
301  REQUIRE( metaData.size ( ) > 0 );
302  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
303  }
304 }
305 
306 
307 TEST_CASE( "Knot 5_2 test" )
308 {
309  typedef Knot_5_2 < Space > MyKnot;
313 
314  MyDigitalCurve digitalCurve;
315  MyMetaData metaData;
316  MyKnot knot( 10, 10, 10 );
317  Digitizer digitize;
318  digitize.init ( -3., 3, 0.0001 );
319  digitize.attach ( &knot );
320  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
321 
322  SECTION("Data")
323  {
324  REQUIRE( digitalCurve.size ( ) > 0 );
325  }
326 
327  digitalCurve.clear ( );
328 
329  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
330 
331  SECTION("Size Comparisons")
332  {
333  REQUIRE( digitalCurve.size ( ) > 0 );
334  REQUIRE( metaData.size ( ) > 0 );
335  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
336  }
337 }
338 
339 
340 TEST_CASE( "Knot 6_2 test" )
341 {
342  typedef Knot_6_2 < Space > MyKnot;
346 
347  MyDigitalCurve digitalCurve;
348  MyMetaData metaData;
349  MyKnot knot( 10, 10, 10 );
350  Digitizer digitize;
351  digitize.init ( -3., 3, 0.0001 );
352  digitize.attach ( &knot );
353  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
354 
355  SECTION("Data")
356  {
357  REQUIRE( digitalCurve.size ( ) > 0 );
358  }
359 
360  digitalCurve.clear ( );
361 
362  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
363 
364  SECTION("Size Comparisons")
365  {
366  REQUIRE( digitalCurve.size ( ) > 0 );
367  REQUIRE( metaData.size ( ) > 0 );
368  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
369  }
370 }
371 
372 
373 TEST_CASE( "Knot 7_4 test" )
374 {
375  typedef Knot_7_4 < Space > MyKnot;
379 
380  MyDigitalCurve digitalCurve;
381  MyMetaData metaData;
382  MyKnot knot( 10, 10, 10 );
383  Digitizer digitize;
384  digitize.init ( -3., 3, 0.0001 );
385  digitize.attach ( &knot );
386  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ) );
387 
388  SECTION("Data")
389  {
390  REQUIRE( digitalCurve.size ( ) > 0 );
391  }
392 
393  digitalCurve.clear ( );
394 
395  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
396 
397  SECTION("Size Comparisons")
398  {
399  REQUIRE( digitalCurve.size ( ) > 0 );
400  REQUIRE( metaData.size ( ) > 0 );
401  REQUIRE( metaData.size ( ) == digitalCurve.size ( ) );
402  }
403 }
404 // //
Aim: Implement a parametrized knot 7, 4.
Definition: Knot_7_4.h:59
std::vector< std::pair< long double, unsigned int > > MetaData
Aim: Implement a parametric curve – elliptic helix.
Definition: EllipticHelix.h:59
Aim: Digitization of 3D parametric curves. This method produces, for good parameters step and k_next,...
Aim: Implement a parametrized knot 3, 1.
Definition: Knot_3_1.h:59
Aim: Implement a parametrized knot 5, 1.
Definition: Knot_5_1.h:59
Aim: Implement a parametrized knot 4, 1.
Definition: Knot_4_1.h:59
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
Aim: Implement a parametrized knot 6, 2.
Definition: Knot_6_2.h:59
Aim: Implement a parametrized knot 3, 2.
Definition: Knot_3_2.h:59
REQUIRE(domain.isInside(aPoint))
Aim: Implement a parametrized knot 5, 2.
Definition: Knot_5_2.h:59
TEST_CASE("Elliptic Helix test")
DGtal is the top-level namespace which contains all DGtal functions and types.
std::vector< Point > DigitalCurve
Digital curve type.
void digitize(Shape &shape, std::vector< SCell > &sCells0, std::vector< SCell > &sCells1, KSpace &kspace, const double h)
Aim: Implement a parametrized knot 4, 3.
Definition: Knot_4_3.h:59
SECTION("Testing constant forward iterators")
Aim: Implements a decorator for applying transformations to parametric curves.