DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testBall3D.cpp
1 
29 
30 #include <QtGui/QApplication>
31 #include "DGtal/shapes/parametric/Ball3D.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include <iostream>
34 #include "DGtal/shapes/GaussDigitizer.h"
35 #include "DGtal/io/Color.h"
36 #include "DGtal/kernel/sets/SetPredicate.h"
37 #include "DGtal/topology/SurfelAdjacency.h"
38 #include "DGtal/topology/DigitalSurface.h"
39 #include "DGtal/topology/helpers/BoundaryPredicate.h"
40 #include "DGtal/io/viewers/Viewer3D.h"
41 #include "DGtal/topology/SetOfSurfels.h"
42 #include "DGtal/io/colormaps/GradientColorMap.h"
43 #include "DGtal/topology/SCellsFunctors.h"
45 
46  using namespace std;
47  using namespace DGtal;
48  using namespace Z3i;
49 
51 // Standard services - public :
52 
53 
54  int main(int argc, char** argv)
55  {
56 
57 
58 
59  // -------------------------------------------------------------------------- Type declaring
61  typedef Ball3D<Space> EuclideanShape;
64 
65 
66 
67  // -------------------------------------------------------------------------- Creating the shape
68  RealPoint c1(0, 0, 0 );
69  EuclideanShape ball1( c1, 12.2 );
70 
71  // -------------------------------------------------------------------------- GaussDigitizing
72  DigitalShape dshape;
73  dshape.attach( ball1 );
74  RealPoint p1 =RealPoint( -15.0, -15.0, -15.0 );
75  RealPoint p2 =RealPoint( 15.0, 15.0, 15.0 );
76  dshape.init( RealPoint( p1 ), RealPoint( p2 ), 1.0);
77  Domain domain = dshape.getDomain();
78 
79 
80  // -------------------------------------------------------------------------- Khalimskhy
81  KSpace K;
82  bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true );
83  if (!space_ok)
84  {
85  return 2;
86  }
87 
88 
89  // -------------------------------------------------------------------------- Other types
90  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
91  typedef KSpace::Surfel Surfel;
92  typedef KSpace::SurfelSet SurfelSet;
93  typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
95 
96 
97  // -------------------------------------------------------------------------- Tracking the boudnadry
98  MySurfelAdjacency surfAdj( true ); // interior in all directions.
99  MySetOfSurfels theSetOfSurfels( K, surfAdj );
100  Surfel bel = Surfaces<KSpace>::findABel( K, dshape, 1000 );
101  Surfaces<KSpace>::trackBoundary( theSetOfSurfels.surfelSet(), K, surfAdj, dshape, bel );
102 
103 
104 
105  QApplication application(argc,argv);
106  Viewer3D viewer;
107  viewer.show();
108  viewer << SetMode3D( domain.className(), "BoundingBox" ) << domain;
109 
110 
111 
112 
113 
114 //-----------------------------------------------------------------------
115 // Looking for the min and max values
116 
117  double minCurv=1;
118  double maxCurv=0;
119  SCellToMidPoint<KSpace> midpoint(K);
120  for ( std::set<SCell>::iterator it = theSetOfSurfels.begin(), it_end = theSetOfSurfels.end();
121  it != it_end; ++it)
122  {
123 
124  RealPoint A = midpoint( *it );
125  DGtal::StarShaped3D<Space>::AngularCoordinates Angles= ball1.parameter(A);
126  double a =ball1.meanCurvature(Angles);
127 // double a =ball1.gaussianCurvature(Angles);
128 
129  if(a>maxCurv)
130  {
131  maxCurv=a;
132  }
133  if(a<minCurv)
134  {
135  minCurv=a;
136  }
137  }
138 
139 //-----------------------------------------------------------------------
140 //Specifing a color map
141 
142  GradientColorMap<double> cmap_grad( minCurv, maxCurv+1 );
143  cmap_grad.addColor( Color( 50, 50, 255 ) );
144  cmap_grad.addColor( Color( 255, 0, 0 ) );
145  cmap_grad.addColor( Color( 255, 255, 10 ) );
146 
147 
148 //-----------------------------------------------------------------------
149 //Drawing the ball && giving a color to the surfels( depending on the
150 //curvature)
151 
152  unsigned int nbSurfels = 0;
153 
154 
155  for ( std::set<SCell>::iterator it = theSetOfSurfels.begin(), it_end = theSetOfSurfels.end();
156 it != it_end; ++it, ++nbSurfels )
157  {
158  RealPoint A = midpoint( *it );
159 
161  double curvature =ball1.meanCurvature(Angles);
162 // double curvature =ball1.gaussianCurvature(Angles);
163  viewer << CustomColors3D( Color::Black, cmap_grad( curvature));
164  viewer << *it;
165  }
166 
167 
168 
169  viewer << Viewer3D::updateDisplay;
170 
171  return application.exec();
172 }
173 // //
175 
176