DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
distancetransform3D.cpp
1 
30 
31 #include <iostream>
32 
33 #include <QtGui/qapplication.h>
34 
35 #include "DGtal/base/Common.h"
36 #include "DGtal/kernel/SpaceND.h"
37 #include "DGtal/kernel/domains/HyperRectDomain.h"
38 #include "DGtal/images/ImageSelector.h"
39 #include "DGtal/io/readers/VolReader.h"
40 #include "DGtal/io/viewers/Viewer3D.h"
41 
42 #include "DGtal/io/Color.h"
43 #include "DGtal/io/colormaps/GradientColorMap.h"
44 #include "DGtal/io/DrawWithDisplay3DModifier.h"
45 
46 #include "DGtal/kernel/SpaceND.h"
47 #include "DGtal/kernel/domains/HyperRectDomain.h"
48 #include "DGtal/images/ImageSelector.h"
49 
50 #include "DGtal/geometry/volumes/distance/SeparableMetricHelper.h"
51 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
52 #include "DGtal/images/imagesSetsUtils/SimpleThresholdForegroundPredicate.h"
53 
54 #include "ConfigExamples.h"
55 
56 
58 
59 using namespace std;
60 using namespace DGtal;
61 
63 
64 
72 template<typename Image>
73 void randomSeeds(Image &image, const unsigned int nb, const int value)
74 {
75  typename Image::Point p, low = image.domain().lowerBound();
76  typename Image::Vector ext;
77  srand ( time(NULL) );
78 
79  ext = image.extent();
80 
81  for (unsigned int k = 0 ; k < nb; k++)
82  {
83  for (unsigned int dim = 0; dim < Image::dimension; dim++)
84  p[dim] = rand() % (ext[dim]) + low[dim];
85 
86  image.setValue(p, value);
87  }
88 }
89 
90 int main( int argc, char** argv )
91 {
92 
93  std::string inputFilename = examplesPath + "samples/Al.100.vol";
94 
95  //------------
96 
97  typedef SpaceND<3> Space4Type;
98  typedef HyperRectDomain<Space4Type> TDomain;
99 
100  typedef TDomain::Point Point;
101 
102 
103  QApplication application(argc,argv);
104  Viewer3D viewer;
105  viewer.setWindowTitle("simpleViewer");
106  viewer.show();
107 
108 
109 
110  //Default image selector = STLVector
112  Image image = VolReader<Image>::importVol( inputFilename );
113  TDomain domain = image.domain();
114 
115 
116  Image imageSeeds ( domain);
117  for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
118  (*it)=1;
119  Z3i::Point p0(10,10,10);
120  //imageSeeds.setValue(p0, 0 );
121  randomSeeds(imageSeeds, 70, 0);
122 
123 
124  //Distance transformation computation
125  typedef ImageSelector<TDomain, long int>::Type ImageLong;
126 
128  Predicate aPredicate(imageSeeds,0);
129 
133 
134  DTL2 dtL2(domain, aPredicate);
135  DTLInf dtLinf(domain, aPredicate);
136  DTL1 dtL1(domain, aPredicate);
137 
138 
139  DTL1::OutputImage resultL1 = dtL1.compute ( );
140 
141  unsigned int min = 0;
142  unsigned int max = 0;
143  for(DTL1::OutputImage::ConstIterator it = resultL1.begin(), itend=resultL1.end();
144  it!=itend;
145  ++it)
146  {
147  if( (*it) < min )
148  min=(*it);
149  if( (*it) > max )
150  max=(*it);
151  }
152 
153 
154  GradientColorMap<long> gradient( 0,30);
155  gradient.addColor(Color::Red);
156  gradient.addColor(Color::Yellow);
157  gradient.addColor(Color::Green);
158  gradient.addColor(Color::Cyan);
159  gradient.addColor(Color::Blue);
160  gradient.addColor(Color::Magenta);
161  gradient.addColor(Color::Red);
162 
163 
164  viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
165 
166  for(TDomain::ConstIterator it = domain.begin(), itend=domain.end();
167  it!=itend;
168  ++it){
169 
170  unsigned int valDist= resultL1( (*it) );
171  Color c= gradient(valDist);
172 
173  if(resultL1(*it)<=30 ){
174  viewer << CustomColors3D(Color((float)(c.red()),
175  (float)(c.green()),
176  (float)(c.blue(),205)),
177  Color((float)(c.red()),
178  (float)(c.green()),
179  (float)(c.blue()),205));
180  viewer << *it ;
181  }
182  }
183 
184  //viewer << ClippingPlane(1,0,0,-60);
185  viewer<< Viewer3D::updateDisplay;
186 
187  return application.exec();
188 }
189 // //
191