DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
3dKSSurfaceExtraction.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include <QtGui/qapplication.h>
35 #include "DGtal/base/Common.h"
36 #include "DGtal/io/readers/VolReader.h"
37 #include "DGtal/io/viewers/Viewer3D.h"
38 #include "DGtal/io/DrawWithDisplay3DModifier.h"
39 #include "DGtal/io/Color.h"
40 
41 #include "DGtal/images/ImageSelector.h"
42 #include "DGtal/helpers/StdDefs.h"
43 #include "ConfigExamples.h"
44 #include "DGtal/io/Color.h"
45 #include "DGtal/io/colormaps/GradientColorMap.h"
46 #include "DGtal/topology/KhalimskySpaceND.h"
47 #include "DGtal/topology/helpers/Surfaces.h"
48 
49 
51 
52 using namespace std;
53 using namespace DGtal;
54 using namespace Z3i;
55 
57 
58 int main( int argc, char** argv )
59 {
60 
61  Point p1( 0, 0, 0 );
62  Point p2( 20, 20, 20 );
63  Point c( 10, 10, 10 );
64  Domain domain( p1, p2);
65 
66  // Generate the digital set from randam seeds and distance threshold.
67  DigitalSet diamond_set( domain );
68  //srand ( time(NULL) );
69  uint nbSeeds = 35;
70  vector<Point> vCenters;
71  vector<uint> vRad;
72  for(uint i=0;i<nbSeeds; i++){
73  vCenters.push_back(Point(rand()%p2[0], rand()%p2[1],
74  rand()%p2[2]));
75  vRad.push_back(rand()%7);
76  }
77  for ( Domain::ConstIterator it = domain.begin(); it != domain.end(); ++it ){
78  for(unsigned int i=0;i<nbSeeds; i++){
79  if ( (*it - vCenters.at(i) ).norm1() <= vRad.at(i) && domain.isInside(*it) &&
80  domain.isInside(*it+Point(1,1,1)) && domain.isInside(*it-Point(1,1,1)) ){
81  diamond_set.insertNew( *it );
82  break;
83  }
84  }
85  }
86 
87 
88  //A KhalimskySpace is constructed from the domain boundary points.
89  KSpace K;
90  K.init(p1, p2, true);
91 
92  SurfelAdjacency<3> SAdj( true );
93  vector<vector<SCell> > vectConnectedSCell;
94 
95 
96  //Here since the last argument is set to true, the resulting
97  //SignedKhalimskySpaceND are signed in order to indicate the direction
98  //of exterior. You can also get the SignefKhalimskySpaceND with default
99  //sign:
100 
101  SetPredicate<DigitalSet> shape_set_predicate( diamond_set );
102  Surfaces<KSpace>::extractAllConnectedSCell(vectConnectedSCell,K, SAdj, shape_set_predicate, false);
103 
104 
105  QApplication application(argc,argv);
106  Viewer3D viewer;
107  viewer.show();
108 
109 
110  // Each connected compoments are simply displayed with a specific color.
111  GradientColorMap<long> gradient(0, (const long)vectConnectedSCell.size());
112  gradient.addColor(Color::Red);
113  gradient.addColor(Color::Yellow);
114  gradient.addColor(Color::Green);
115  gradient.addColor(Color::Cyan);
116  gradient.addColor(Color::Blue);
117  gradient.addColor(Color::Magenta);
118  gradient.addColor(Color::Red);
119 
120 
121  for(uint i=0; i< vectConnectedSCell.size();i++){
122  DGtal::Color col= gradient(i);
123  viewer << CustomColors3D(Color(250, 0,0), Color(col.red(),
124  col.green(),
125  col.blue()));
126 
127  for(uint j=0; j< vectConnectedSCell.at(i).size();j++){
128  viewer << vectConnectedSCell.at(i).at(j);
129  }
130  }
131 
132 
133  viewer << CustomColors3D(Color(250, 0,0),Color(250, 200,200, 200));
134  viewer << diamond_set;
135  //viewer << ClippingPlane(0,1,0.0,-2);
136  viewer << Viewer3D::updateDisplay;
137  return application.exec();
138 }
139 // //