DGtal  1.3.beta
Functions
distancetransform3D.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
Include dependency graph for distancetransform3D.cpp:

Go to the source code of this file.

Functions

template<typename Image >
void randomSeeds (Image &image, const unsigned int nb, const int value)
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2011/01/04

This file is part of the DGtal library.

Definition in file distancetransform3D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 100 of file distancetransform3D.cpp.

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 
160  for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end();
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 }

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::HyperRectDomain< TSpace >::begin(), domain, DGtal::HyperRectDomain< TSpace >::end(), image(), max(), randomSeeds(), and DGtal::Viewer3D< TSpace, TKSpace >::show().

◆ randomSeeds()

template<typename Image >
void randomSeeds ( Image image,
const unsigned int  nb,
const int  value 
)

Set to a given value a random set of nb points.

Parameters
imagethe image
nbthe number of random points to insert
valuethe value to add at each random point

Definition at line 81 of file distancetransform3D.cpp.

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 }

References dim(), and srand().

Referenced by main().

ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
image
Image image(domain)
DGtal::HyperRectDomain< Space >
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
srand
srand(0)
dim
unsigned int dim(const Vector &z)
Definition: viewDualSurface.cpp:174
DGtal::Viewer3D
Definition: Viewer3D.h:135
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal::ImageContainerBySTLVector< Domain, Value >::Iterator
std::vector< Value >::iterator Iterator
Definition: ImageContainerBySTLVector.h:264
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector< dim, Integer >
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
randomSeeds
void randomSeeds(Image &image, const unsigned int nb, const int value)
Definition: distancetransform3D.cpp:81
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition: DistanceTransformation.h:98
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Definition: SimpleThresholdForegroundPredicate.h:65