DGtal  0.9.2
3dKSSurfaceExtraction.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/base/Common.h"
35 #include "DGtal/io/readers/VolReader.h"
36 #include "DGtal/io/DrawWithDisplay3DModifier.h"
37 #include "DGtal/io/viewers/Viewer3D.h"
38 #include "DGtal/io/Color.h"
39 
40 #include "DGtal/images/ImageSelector.h"
41 #include "DGtal/helpers/StdDefs.h"
42 #include "ConfigExamples.h"
43 #include "DGtal/io/Color.h"
44 #include "DGtal/io/colormaps/GradientColorMap.h"
45 #include "DGtal/topology/KhalimskySpaceND.h"
46 #include "DGtal/topology/helpers/Surfaces.h"
47 
48 
50 
51 using namespace std;
52 using namespace DGtal;
53 using namespace Z3i;
54 
56 
57 int main( int argc, char** argv )
58 {
59 
60  Point p1( 0, 0, 0 );
61  Point p2( 20, 20, 20 );
62  Point c( 10, 10, 10 );
63  Domain domain( p1, p2);
64 
65  // Generate the digital set from randam seeds and distance threshold.
66  DigitalSet diamond_set( domain );
67  //srand ( time(NULL) );
68  unsigned int nbSeeds = 35;
69  vector<Point> vCenters;
70  vector<uint> vRad;
71  for(unsigned int i=0;i<nbSeeds; i++){
72  vCenters.push_back(Point(rand()%p2[0], rand()%p2[1],
73  rand()%p2[2]));
74  vRad.push_back(rand()%7);
75  }
76  for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it ){
77  for(unsigned int i=0;i<nbSeeds; i++){
78  if ( (*it - vCenters.at(i) ).norm1() <= vRad.at(i) && domain.isInside(*it) &&
79  domain.isInside(*it+Point(1,1,1)) && domain.isInside(*it-Point(1,1,1)) ){
80  diamond_set.insertNew( *it );
81  break;
82  }
83  }
84  }
85 
86 
87  //A KhalimskySpace is constructed from the domain boundary points.
88  KSpace K;
89  K.init(p1, p2, true);
90 
91  SurfelAdjacency<3> SAdj( true );
92  vector<vector<SCell> > vectConnectedSCell;
93 
94 
95  //Here since the last argument is set to true, the resulting
96  //SignedKhalimskySpaceND are signed in order to indicate the direction
97  //of exterior. You can also get the SignefKhalimskySpaceND with default
98  //sign:
99 
100  Surfaces<KSpace>::extractAllConnectedSCell(vectConnectedSCell,K, SAdj, diamond_set, false);
101 
102 
103  QApplication application(argc,argv);
104  Viewer3D<> viewer (K);
105  viewer.show();
106 
107 
108  // Each connected compoments are simply displayed with a specific color.
109  GradientColorMap<long> gradient(0, (const long)vectConnectedSCell.size());
110  gradient.addColor(Color::Red);
111  gradient.addColor(Color::Yellow);
112  gradient.addColor(Color::Green);
113  gradient.addColor(Color::Cyan);
114  gradient.addColor(Color::Blue);
115  gradient.addColor(Color::Magenta);
116  gradient.addColor(Color::Red);
117 
118 
119  for(unsigned int i=0; i< vectConnectedSCell.size();i++){
120  DGtal::Color col= gradient(i);
121  viewer << CustomColors3D(Color(250, 0,0), Color(col.red(),
122  col.green(),
123  col.blue()));
124 
125  for(unsigned int j=0; j< vectConnectedSCell.at(i).size();j++){
126  viewer << vectConnectedSCell.at(i).at(j);
127  }
128  }
129 
130 
131  viewer << CustomColors3D(Color(250, 0,0),Color(250, 200,200, 200));
132  viewer << diamond_set;
133  //viewer << ClippingPlane(0,1,0.0,-2);
134  viewer << Viewer3D<>::updateDisplay;
135  return application.exec();
136 }
137 // //
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
void addColor(const Color &color)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
STL namespace.
bool isInside(const Point &p) const
DGtal is the top-level namespace which contains all DGtal functions and types.
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)