DGtal 1.3.0
Loading...
Searching...
No Matches
distancetransform3D.cpp
Go to the documentation of this file.
1
40#include <iostream>
41
42#include "DGtal/base/Common.h"
43#include "DGtal/kernel/SpaceND.h"
44#include "DGtal/kernel/domains/HyperRectDomain.h"
45#include "DGtal/images/ImageSelector.h"
46#include "DGtal/io/readers/VolReader.h"
47
48#include "DGtal/io/Color.h"
49#include "DGtal/io/colormaps/GradientColorMap.h"
50#include "DGtal/io/DrawWithDisplay3DModifier.h"
51#include "DGtal/io/viewers/Viewer3D.h"
52
53#include "DGtal/kernel/SpaceND.h"
54#include "DGtal/kernel/domains/HyperRectDomain.h"
55#include "DGtal/images/ImageSelector.h"
56
57#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
58#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
59#include "DGtal/helpers/StdDefs.h"
60
61#include "ConfigExamples.h"
62
63#include "DGtal/helpers/StdDefs.h"
64
66
67using namespace std;
68using namespace DGtal;
69
71
72
80template<typename Image>
81void randomSeeds(Image &image, const unsigned int nb, const int value)
82{
83 typename Image::Point p, low = image.domain().lowerBound();
84 typename Image::Vector ext;
85 srand ( time(NULL) );
86
87 ext = image.extent();
88
89 for (unsigned int k = 0 ; k < nb; k++)
90 {
91 for (unsigned int dim = 0; dim < Image::dimension; dim++)
92 p[dim] = rand() % (ext[dim]) + low[dim];
93
94 image.setValue(p, value);
95 }
96}
97
98using namespace DGtal;
99
100int main( int argc, char** argv )
101{
102
103 std::string inputFilename = examplesPath + "samples/Al.100.vol";
104
105 //------------
106 QApplication application(argc,argv);
107 Viewer3D<> viewer;
108 viewer.setWindowTitle("simpleViewer");
109 viewer.show();
110
111
112
113 //Default image selector = STLVector
115 Image image = VolReader<Image>::importVol( inputFilename );
116 Z3i::Domain domain = image.domain();
117
118
119 Image imageSeeds ( domain);
120 for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
121 (*it)=1;
122 Z3i::Point p0(10,10,10);
123 //imageSeeds.setValue(p0, 0 );
124 randomSeeds(imageSeeds, 70, 0);
125
126
127 //Distance transformation computation
129 Predicate aPredicate(imageSeeds,0);
130
132 DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
133
134 unsigned int min = 0;
135 unsigned int max = 0;
136 for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
137 itend=dtL2.constRange().end();
138 it!=itend;
139 ++it)
140 {
141 if( (*it) < min )
142 min=(*it);
143 if( (*it) > max )
144 max=(*it);
145 }
146
147
148 GradientColorMap<long> gradient( 0,30);
149 gradient.addColor(Color::Red);
150 gradient.addColor(Color::Yellow);
151 gradient.addColor(Color::Green);
152 gradient.addColor(Color::Cyan);
153 gradient.addColor(Color::Blue);
154 gradient.addColor(Color::Magenta);
155 gradient.addColor(Color::Red);
156
157
158 viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
159
161 it!=itend;
162 ++it){
163
164 double valDist= dtL2( (*it) );
165 Color c= gradient(valDist);
166
167 if(dtL2(*it)<=30 && image(*it)>0){
168 viewer << CustomColors3D(Color((float)(c.red()),
169 (float)(c.green()),
170 (float)(c.blue(),205)),
171 Color((float)(c.red()),
172 (float)(c.green()),
173 (float)(c.blue()),205));
174 viewer << *it ;
175 }
176 }
177 viewer<< Viewer3D<>::updateDisplay;
178
179 return application.exec();
180}
181// //
183
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color Yellow
Definition: Color.h:422
static const Color Cyan
Definition: Color.h:420
static const Color Green
Definition: Color.h:417
static const Color Red
Definition: Color.h:416
static const Color Blue
Definition: Color.h:419
static const Color Magenta
Definition: Color.h:421
Aim: Implementation of the linear in time distance transformation for separable metrics.
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.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
void randomSeeds(Image &image, const unsigned int nb, const int value)
static const L2Metric l2Metric
Definition: StdDefs.h:204
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
int max(int a, int b)
int main()
Definition: testBits.cpp:56
srand(0)
Domain domain