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