DGtal 1.4.0
Loading...
Searching...
No Matches
exampleParamCurve3dDigitization.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <iterator>
33#include "DGtal/base/Common.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "ConfigExamples.h"
36#include "DGtal/io/viewers/Viewer3D.h"
37
39#include "DGtal/geometry/curves/parametric/EllipticHelix.h"
40#include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
42
43#ifdef WITH_VISU3D_QGLVIEWER
44#include "DGtal/io/DrawWithDisplay3DModifier.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{
74 QApplication application(argc,argv);
76 typedef EllipticHelix < Space > MyHelix;
77 typedef NaiveParametricCurveDigitizer3D < MyHelix > DigitizerHelix;
81 trace.info() << "exampleParamCurve3dDigitization" << endl;
82
83 Viewer3D<> viewer;
84
86 MyDigitalCurve digitalCurve;
87 MyMetaData metaData;
88 MyHelix helix( 15, 10, 1 );
89 DigitizerHelix digitize;
90 digitize.init ( M_PI / 2., ( MyHelix::getPeriod() * 10. ) + M_PI / 2., 0.0001 );
91 digitize.attach ( &helix );
93
95 digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
97
98 trace.info() << "Number of points: " << digitalCurve.size () << " number of metadata: " << metaData.size () << endl;
99
100 viewer.show();
101
103 for ( unsigned int i = 0; i < digitalCurve.size ( ); i++ )
104 {
105 if ( findMainAxis ( helix, metaData.at ( i ).first ) == 0 )
106 viewer.setFillColor ( Color ( 255, 0, 0, 128 ) );
107 if ( findMainAxis ( helix, metaData.at ( i ).first ) == 1 )
108 viewer.setFillColor ( Color ( 0, 255, 0, 128 ) );
109 if ( findMainAxis ( helix, metaData.at ( i ).first ) == 2 )
110 viewer.setFillColor ( Color ( 0, 0, 255, 128 ) );
111 viewer << SetMode3D ( digitalCurve.at ( i ).className ( ), "PavingWired" ) << digitalCurve.at ( i );
112 }
114 viewer << Viewer3D<>::updateDisplay;
115
116 return application.exec();
117}
118// //
Structure representing an RGB triple with alpha component.
Definition Color.h:68
virtual void setFillColor(DGtal::Color aColor)
std::vector< std::pair< long double, unsigned int > > MetaData
std::vector< Point > DigitalCurve
Digital curve type.
Aim: Implements basic operations that will be used in Point and Vector classes.
std::ostream & info()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
unsigned char findMainAxis(const T &curve, const long double &t)
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
int main()
Definition testBits.cpp:56
void digitize(Shape &shape, std::vector< SCell > &sCells0, std::vector< SCell > &sCells1, KSpace &kspace, const double h)