DGtal  1.4.2
exampleParamCurve3dDigitizationTransformationDecorator.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "ConfigExamples.h"
35 #include "DGtal/io/viewers/Viewer3D.h"
36 
37 #include "DGtal/geometry/curves/parametric/EllipticHelix.h"
38 #include "DGtal/geometry/curves/parametric/NaiveParametricCurveDigitizer3D.h"
40 #include "DGtal/geometry/curves/parametric/DecoratorParametricCurveTransformation.h"
41 #include "DGtal/images/RigidTransformation3D.h"
43 
44 #ifdef WITH_VISU3D_QGLVIEWER
45 #include "DGtal/io/DrawWithDisplay3DModifier.h"
46 #endif
47 
49 
50 using namespace std;
51 using namespace DGtal;
52 using namespace Z3i;
53 using namespace functors;
54 
55 template <typename T>
56 inline
57 unsigned char findMainAxis ( const T & curve, const long double & t )
58 {
59  RealPoint value;
60  value[0] = std::abs ( curve.xp ( t )[0] );
61  value[1] = std::abs ( curve.xp ( t )[1] );
62  value[2] = std::abs ( curve.xp ( t )[2] );
63 
64  if ( value[0] >= value[1] && value[0] >= value[2] )
65  return 0;
66  else if ( value[1] >= value[0] && value[1] >= value[2] )
67  return 1;
68  else
69  return 2;
70 }
71 
73 int main( int argc, char** argv )
74 {
75  QApplication application(argc,argv);
77  typedef EllipticHelix < Space > MyHelix;
84  trace.info() << "exampleParamCurve3dDigitizationTransformationDecorator" << endl;
85 
86  Viewer3D<> viewer;
87 
88  MyMetaData metaData;
89 
91  MyDigitalCurve digitalCurve;
92  MyHelix helix( 30, 20, 1 );
94 
96  double angle = M_PI/3.;
97  RealVector axis ( 1., 0., 1. );
98  ForwardTrans trans ( RealPoint ( 0, 0, 0 ), axis, angle, RealVector ( 0, 0, 0 ) );
99  MyRotatedCurve rotCurve ( helix, trans );
101 
103  Digitizer digitize;
104  digitize.attach ( &rotCurve );
105  digitize.init ( 0, MyHelix::getPeriod() * 10., 0.0001 );
106  digitize.digitize( back_insert_iterator < MyDigitalCurve> ( digitalCurve ), back_insert_iterator < MyMetaData > ( metaData ) );
108 
109  trace.info() << "Number of points: " << digitalCurve.size () << " number of metadata: " << metaData.size () << endl;
110 
111  viewer.show();
112  for ( unsigned int i = 0; i < digitalCurve.size ( ); i++ )
113  {
114  if ( findMainAxis ( rotCurve, metaData.at ( i ).first ) == 0 )
115  viewer.setFillColor ( Color ( 255, 0, 0, 128 ) );
116  if ( findMainAxis ( rotCurve, metaData.at ( i ).first ) == 1 )
117  viewer.setFillColor ( Color ( 0, 255, 0, 128 ) );
118  if ( findMainAxis ( rotCurve, metaData.at ( i ).first ) == 2 )
119  viewer.setFillColor ( Color ( 0, 0, 255, 128 ) );
120  viewer << SetMode3D ( digitalCurve.at ( i ).className ( ), "PavingWired" ) << digitalCurve.at ( i );
121  }
122  viewer << Viewer3D<>::updateDisplay;
123 
124  return application.exec();
125 }
126 // //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: Implements a decorator for applying transformations to parametric curves.
virtual void setFillColor(DGtal::Color aColor)
Aim: Implement a parametric curve – elliptic helix.
Definition: EllipticHelix.h:60
Aim: Digitization of 3D parametric curves. This method produces, for good parameters step and k_next,...
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.
Definition: PointVector.h:593
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...
Aim: implements forward rigid transformation of point in 3D integer space around any arbitrary axis....
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
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
void digitize(Shape &shape, std::vector< SCell > &sCells0, std::vector< SCell > &sCells1, KSpace &kspace, const double h)