DGtal  0.9.3beta
distancetransform3D.cpp
1 
28 #include <iostream>
30 
31 #include "DGtal/base/Common.h"
32 #include "DGtal/kernel/SpaceND.h"
33 #include "DGtal/kernel/domains/HyperRectDomain.h"
34 #include "DGtal/images/ImageSelector.h"
35 #include "DGtal/io/readers/VolReader.h"
36 
37 #include "DGtal/io/Color.h"
38 #include "DGtal/io/colormaps/GradientColorMap.h"
39 #include "DGtal/io/DrawWithDisplay3DModifier.h"
40 #include "DGtal/io/viewers/Viewer3D.h"
41 
42 #include "DGtal/kernel/SpaceND.h"
43 #include "DGtal/kernel/domains/HyperRectDomain.h"
44 #include "DGtal/images/ImageSelector.h"
45 
46 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
47 #include "DGtal/images/SimpleThresholdForegroundPredicate.h"
48 #include "DGtal/helpers/StdDefs.h"
49 
50 #include "ConfigExamples.h"
51 
52 #include "DGtal/helpers/StdDefs.h"
53 
55 
56 using namespace std;
57 using namespace DGtal;
58 
60 
61 
69 template<typename Image>
70 void randomSeeds(Image &image, const unsigned int nb, const int value)
71 {
72  typename Image::Point p, low = image.domain().lowerBound();
73  typename Image::Vector ext;
74  srand ( time(NULL) );
75 
76  ext = image.extent();
77 
78  for (unsigned int k = 0 ; k < nb; k++)
79  {
80  for (unsigned int dim = 0; dim < Image::dimension; dim++)
81  p[dim] = rand() % (ext[dim]) + low[dim];
82 
83  image.setValue(p, value);
84  }
85 }
86 
87 using namespace DGtal;
88 
89 int main( int argc, char** argv )
90 {
91 
92  std::string inputFilename = examplesPath + "samples/Al.100.vol";
93 
94  //------------
95  QApplication application(argc,argv);
96  Viewer3D<> viewer;
97  viewer.setWindowTitle("simpleViewer");
98  viewer.show();
99 
100 
101 
102  //Default image selector = STLVector
104  Image image = VolReader<Image>::importVol( inputFilename );
105  Z3i::Domain domain = image.domain();
106 
107 
108  Image imageSeeds ( domain);
109  for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
110  (*it)=1;
111  Z3i::Point p0(10,10,10);
112  //imageSeeds.setValue(p0, 0 );
113  randomSeeds(imageSeeds, 70, 0);
114 
115 
116  //Distance transformation computation
118  Predicate aPredicate(imageSeeds,0);
119 
121  DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
122 
123  unsigned int min = 0;
124  unsigned int max = 0;
125  for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
126  itend=dtL2.constRange().end();
127  it!=itend;
128  ++it)
129  {
130  if( (*it) < min )
131  min=(*it);
132  if( (*it) > max )
133  max=(*it);
134  }
135 
136 
137  GradientColorMap<long> gradient( 0,30);
138  gradient.addColor(Color::Red);
139  gradient.addColor(Color::Yellow);
140  gradient.addColor(Color::Green);
141  gradient.addColor(Color::Cyan);
142  gradient.addColor(Color::Blue);
143  gradient.addColor(Color::Magenta);
144  gradient.addColor(Color::Red);
145 
146 
147  viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
148 
149  for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end();
150  it!=itend;
151  ++it){
152 
153  double valDist= dtL2( (*it) );
154  Color c= gradient(valDist);
155 
156  if(dtL2(*it)<=30 && image(*it)>0){
157  viewer << CustomColors3D(Color((float)(c.red()),
158  (float)(c.green()),
159  (float)(c.blue(),205)),
160  Color((float)(c.red()),
161  (float)(c.green()),
162  (float)(c.blue()),205));
163  viewer << *it ;
164  }
165  }
166  viewer<< Viewer3D<>::updateDisplay;
167 
168  return application.exec();
169 }
170 // //
172 
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
const ConstIterator & begin() const
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
const ConstIterator & end() const
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
STL namespace.
void setValue(const Point &aPoint, const Value &aValue)
Definition: Image.h:247
Aim: Define a simple Foreground predicate thresholding image values given a single thresold...
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
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)
const Domain & domain() const
Definition: Image.h:192
void red(const unsigned char aRedValue)
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.
void blue(const unsigned char aBlueValue)