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