DGtal  1.4.beta
geometry/volumes/distance/distancetransform3D.cpp

Example of distance transformation in dimension 3 with DGtal Viewer3D. This program outputs this image:

nD Volumetric Analysis using Separable Processes
#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/Color.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
using namespace std;
using namespace DGtal;
template<typename Image>
void randomSeeds(Image &image, const unsigned int nb, const int value)
{
typename Image::Point p, low = image.domain().lowerBound();
typename Image::Vector ext;
srand ( time(NULL) );
ext = image.extent();
for (unsigned int k = 0 ; k < nb; k++)
{
for (unsigned int dim = 0; dim < Image::dimension; dim++)
p[dim] = rand() % (ext[dim]) + low[dim];
image.setValue(p, value);
}
}
using namespace DGtal;
int main( int argc, char** argv )
{
std::string inputFilename = examplesPath + "samples/Al.100.vol";
//------------
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.setWindowTitle("simpleViewer");
viewer.show();
//Default image selector = STLVector
typedef ImageSelector<Z3i::Domain, unsigned char>::Type Image;
Image image = VolReader<Image>::importVol( inputFilename );
Z3i::Domain domain = image.domain();
Image imageSeeds ( domain);
for ( Image::Iterator it = imageSeeds.begin(), itend = imageSeeds.end();it != itend; ++it)
(*it)=1;
Z3i::Point p0(10,10,10);
//imageSeeds.setValue(p0, 0 );
randomSeeds(imageSeeds, 70, 0);
//Distance transformation computation
typedef functors::SimpleThresholdForegroundPredicate<Image> Predicate;
Predicate aPredicate(imageSeeds,0);
typedef DistanceTransformation<Z3i::Space,Predicate, Z3i::L2Metric> DTL2;
DTL2 dtL2(&domain, &aPredicate, &Z3i::l2Metric);
unsigned int min = 0;
unsigned int max = 0;
for(DTL2::ConstRange::ConstIterator it = dtL2.constRange().begin(),
itend=dtL2.constRange().end();
it!=itend;
++it)
{
if( (*it) < min )
min=(*it);
if( (*it) > max )
max=(*it);
}
viewer << SetMode3D( (*(domain.begin())).className(), "Paving" );
for(Z3i::Domain::ConstIterator it = domain.begin(), itend=domain.end();
it!=itend;
++it){
double valDist= dtL2( (*it) );
if(dtL2(*it)<=30 && image(*it)>0){
viewer << CustomColors3D(Color((float)(c.red()),
(float)(c.green()),
(float)(c.blue(),205)),
Color((float)(c.red()),
(float)(c.green()),
(float)(c.blue()),205));
viewer << *it ;
}
}
viewer<< Viewer3D<>::updateDisplay;
return application.exec();
}
// //
DigitalPlane::Point Vector
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
int max(int a, int b)
MyPointD Point
Definition: testClone2.cpp:383
srand(0)
void randomSeeds(Image &input, const unsigned int nb, const int value)
Domain domain
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain
unsigned int dim(const Vector &z)