Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
exampleTrofoliKnot.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
37#include "DGtal/geometry/curves/parametric/Knot_3_1.h"
38#include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
39
40#ifdef DGTAL_WITH_POLYSCOPE
41#include "DGtal/io/viewers/PolyscopeViewer.h"
42#endif
43
45
46using namespace std;
47using namespace DGtal;
48using namespace Z3i;
49using namespace functors;
50
51template <typename T>
52inline
53unsigned char findMainAxis ( const T & curve, const long double & t )
54{
55 RealPoint value;
56 value[0] = std::abs ( curve.xp ( t )[0] );
57 value[1] = std::abs ( curve.xp ( t )[1] );
58 value[2] = std::abs ( curve.xp ( t )[2] );
59
60 if ( value[0] >= value[1] && value[0] >= value[2] )
61 return 0;
62 else if ( value[1] >= value[0] && value[1] >= value[2] )
63 return 1;
64 else
65 return 2;
66}
67
69int main( int argc, char** argv )
70{
71 typedef Knot_3_1< Space > MyKnot;
72 typedef NaiveParametricCurveDigitizer3D < MyKnot > Digitizer;
75
76 trace.info() << "exampleParamCurve3dDigitization" << endl;
77
78 PolyscopeViewer<> viewer;
79
80 MyDigitalCurve digitalCurve;
81 MyMetaData metaData;
82 MyKnot knot ( 10, 10, 10 );
83 Digitizer digitize;
84 digitize.attach ( &knot );
85 digitize.init ( -2.1, 2.1, 0.0001 );
86 digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
87
88 trace.info() << "Number of points: " << digitalCurve.size () << " number of metadata: " << metaData.size () << endl;
89
90 for ( unsigned int i = 0; i < digitalCurve.size ( ); i++ )
91 {
92 if ( findMainAxis ( knot, metaData.at ( i ).first ) == 0 )
93 viewer.drawColor ( Color ( 255, 0, 0, 128 ) );
94 if ( findMainAxis ( knot, metaData.at ( i ).first ) == 1 )
95 viewer.drawColor ( Color ( 0, 255, 0, 128 ) );
96 if ( findMainAxis ( knot, metaData.at ( i ).first ) == 2 )
97 viewer.drawColor ( Color ( 0, 0, 255, 128 ) );
98 viewer << digitalCurve.at ( i );
99 }
100
101 viewer.show();
102 return 0;
103}
104// //
Structure representing an RGB triple with alpha component.
Definition Color.h:77
void drawColor(const DGtal::Color &color)
Aim: Implement a parametrized knot 3, 1.
Definition Knot_3_1.h:60
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::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)