Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
exampleParamCurve3dDigitizationTransformationDecorator.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "ConfigExamples.h"
35
36#include "DGtal/geometry/curves/parametric/EllipticHelix.h"
37#include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
39#include "DGtal/geometry/curves/parametric/DecoratorParametricCurveTransformation.h"
40#include "DGtal/images/RigidTransformation3D.h"
42
43#ifdef DGTAL_WITH_POLYSCOPE
44#include "DGtal/io/viewers/PolyscopeViewer.h"
45#endif
46
48
49using namespace std;
50using namespace DGtal;
51using namespace Z3i;
52using namespace functors;
53
54template <typename T>
55inline
56unsigned char findMainAxis ( const T & curve, const long double & t )
57{
58 RealPoint value;
59 value[0] = std::abs ( curve.xp ( t )[0] );
60 value[1] = std::abs ( curve.xp ( t )[1] );
61 value[2] = std::abs ( curve.xp ( t )[2] );
62
63 if ( value[0] >= value[1] && value[0] >= value[2] )
64 return 0;
65 else if ( value[1] >= value[0] && value[1] >= value[2] )
66 return 1;
67 else
68 return 2;
69}
70
72int main( int argc, char** argv )
73{
75 typedef EllipticHelix < Space > MyHelix;
76 typedef ForwardRigidTransformation3D < Space, RealPoint, RealPoint, Identity > ForwardTrans;
77 typedef DecoratorParametricCurveTransformation < MyHelix, ForwardTrans > MyRotatedCurve;
78 typedef NaiveParametricCurveDigitizer3D < MyRotatedCurve > Digitizer;
82 trace.info() << "exampleParamCurve3dDigitizationTransformationDecorator" << endl;
83
84 PolyscopeViewer<> viewer;
85
86 MyMetaData metaData;
87
89 MyDigitalCurve digitalCurve;
90 MyHelix helix( 30, 20, 1 );
92
94 double angle = M_PI/3.;
95 RealVector axis ( 1., 0., 1. );
96 ForwardTrans trans ( RealPoint ( 0, 0, 0 ), axis, angle, RealVector ( 0, 0, 0 ) );
97 MyRotatedCurve rotCurve ( helix, trans );
99
101 Digitizer digitize;
102 digitize.attach ( &rotCurve );
103 digitize.init ( 0, MyHelix::getPeriod() * 10., 0.0001 );
104 digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
106
107 trace.info() << "Number of points: " << digitalCurve.size () << " number of metadata: " << metaData.size () << endl;
108
109 for ( unsigned int i = 0; i < digitalCurve.size ( ); i++ )
110 {
111 if ( findMainAxis ( rotCurve, metaData.at ( i ).first ) == 0 )
112 viewer.drawColor ( Color ( 255, 0, 0, 128 ) );
113 if ( findMainAxis ( rotCurve, metaData.at ( i ).first ) == 1 )
114 viewer.drawColor ( Color ( 0, 255, 0, 128 ) );
115 if ( findMainAxis ( rotCurve, metaData.at ( i ).first ) == 2 )
116 viewer.drawColor ( Color ( 0, 0, 255, 128 ) );
117 viewer << digitalCurve.at ( i );
118 }
119
120 viewer.show();
121 return 0;
122}
123// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
void drawColor(const DGtal::Color &color)
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)
unsigned char findMainAxis(const T &curve, const long double &t)
Z3i this namespace gathers the standard of types for 3D imagery.
Space::RealVector RealVector
Definition StdDefs.h:171
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)
double angle(const DGtal::Z2i::RealPoint &point)