Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
exampleParamCurve3dDigitization.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include <iterator>
33#include "DGtal/base/Common.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "ConfigExamples.h"
36
38#include "DGtal/geometry/curves/parametric/EllipticHelix.h"
39#include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
41
42#ifdef DGTAL_WITH_POLYSCOPE
43 #include "DGtal/io/viewers/PolyscopeViewer.h"
44#endif
45
47
48using namespace std;
49using namespace DGtal;
50using namespace Z3i;
51using namespace functors;
52
53template <typename T>
54inline
55unsigned char findMainAxis ( const T & curve, const long double & t )
56{
57 RealPoint value;
58 value[0] = std::abs ( curve.xp ( t )[0] );
59 value[1] = std::abs ( curve.xp ( t )[1] );
60 value[2] = std::abs ( curve.xp ( t )[2] );
61
62 if ( value[0] >= value[1] && value[0] >= value[2] )
63 return 0;
64 else if ( value[1] >= value[0] && value[1] >= value[2] )
65 return 1;
66 else
67 return 2;
68}
69
71int main( int argc, char** argv )
72{
74 typedef EllipticHelix < Space > MyHelix;
75 typedef NaiveParametricCurveDigitizer3D < MyHelix > DigitizerHelix;
79 trace.info() << "exampleParamCurve3dDigitization" << endl;
80
81 PolyscopeViewer<> viewer;
82
84 MyDigitalCurve digitalCurve;
85 MyMetaData metaData;
86 MyHelix helix( 15, 10, 1 );
87 DigitizerHelix digitize;
88 digitize.init ( M_PI / 2., ( MyHelix::getPeriod() * 10. ) + M_PI / 2., 0.0001 );
89 digitize.attach ( &helix );
91
93 digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
95
96 trace.info() << "Number of points: " << digitalCurve.size () << " number of metadata: " << metaData.size () << endl;
97
99 for ( unsigned int i = 0; i < digitalCurve.size ( ); i++ )
100 {
101 if ( findMainAxis ( helix, metaData.at ( i ).first ) == 0 )
102 viewer << Color ( 255, 0, 0, 128 );
103 if ( findMainAxis ( helix, metaData.at ( i ).first ) == 1 )
104 viewer << Color ( 0, 255, 0, 128 );
105 if ( findMainAxis ( helix, metaData.at ( i ).first ) == 2 )
106 viewer << Color ( 0, 0, 255, 128 );
107 viewer << digitalCurve.at ( i );
108 }
110
111 viewer.show();
112 return 0;
113}
114// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
std::vector< std::pair< long double, unsigned int > > MetaData
std::vector< Point > DigitalCurve
Digital curve type.
void show() override
Starts the event loop and display of elements.
unsigned char findMainAxis(const T &curve, const long double &t)
Z3i this namespace gathers the standard of types for 3D imagery.
Space::RealPoint RealPoint
Definition StdDefs.h:170
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
int main()
Definition testBits.cpp:56
void digitize(Shape &shape, std::vector< SCell > &sCells0, std::vector< SCell > &sCells1, KSpace &kspace, const double h)