DGtal  1.3.beta
tutorial-examples/volDTGranulo.cpp

Example of tutorial 3: Volumetric analysis and Granulometry

See also
Tutorial: Volumetric analysis and Granulometry
result on obtained examples/samples/Al.100.vol.
#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/writers/VolWriter.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include <boost/algorithm/minmax_element.hpp>
using namespace DGtal;
int main(int argc, char ** argv)
{
//Loarding the image
trace.info() << image << std::endl;
//Viewer
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.show();
for(Image::Domain::ConstIterator it = image.domain().begin(),
itend = image.domain().end(); it != itend; ++it)
if (image(*it) != 0)
viewer << *it;
viewer << DGtal::Viewer3D<>::updateDisplay;
trace.info() << "viewer launched..."<<std::endl;
bool res = application.exec();
//DT
Predicate binaryshape(image, 0);
DT distancemap(image.domain(), binaryshape, l2);
//Viewer
QApplication application2(argc,argv);
Viewer3D<> viewer2;
viewer2.show();
DT::Value maxDT = (*boost::first_max_element(distancemap.constRange().begin(),
distancemap.constRange().end()));
GradientColorMap<DT::Value> gradient( 0, maxDT);
trace.info() << "we display the dt map"<<std::endl;
int cpt=0;
viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
itend = distancemap.domain().end(); it != itend;
++it)
if (distancemap(*it) > 0)
{
DT::Value val= distancemap( *it );
DGtal::Color c= gradient(val);
viewer2 << DGtal::CustomColors3D(c,c) << *it ;
cpt++;
}
trace.info() << "Got "<<cpt<<" points."<<std::endl;
viewer2 << DGtal::Viewer3D<>::updateDisplay;
trace.info() << "viewer2 launched..."<<std::endl;
res = res && application2.exec();
//Granulo
Image imageGranulo ( image.domain() );
for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
it != itend; ++it)
*it = 0;
trace.info() << "Computing the granulometry"<<std::endl;
cpt=0;
for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
itend = imageGranulo.domain().end(); it != itend; ++it)
{
if (distancemap(*it) > 0)
{
//Construct the sphere with radius from distancemap(*it)
unsigned int radius = (unsigned int)distancemap(*it);
Z3i::Domain dom(low,up);
for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
itball != itendball; itball++)
if (imageGranulo.domain().isInside(*itball) &&
( ball(*itball) > 0) &&
(imageGranulo(*itball) < radius))
imageGranulo.setValue(*itball, radius);
cpt++;
}
}
trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
trace.info() << "Save OK"<< std::endl;
//Viewer
QApplication application3(argc,argv);
Viewer3D<> viewer3;
viewer3.show();
Image::Value maxG = (*boost::first_max_element(imageGranulo.constRange().begin(),
imageGranulo.constRange().end()));
GradientColorMap<Image::Value> gradient2( 0, maxG);
viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
cpt=0;
for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
itend = imageGranulo.domain().end(); it != itend;
++it)
if (imageGranulo(*it) > 0)
{
Image::Value val= imageGranulo( *it );
DGtal::Color c = gradient2(val);
viewer3 << DGtal::CustomColors3D(c,c) << *it ;
cpt++;
}
trace.info() << "Got "<<cpt<<" points."<<std::endl;
viewer3 << DGtal::Viewer3D<>::updateDisplay;
trace.info() << "viewer3 launched..."<<std::endl;
return res && application3.exec();
}
DGtal::Image::constRange
ConstRange constRange() const
Definition: Image.h:203
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::Image::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition: Image.h:247
image
Image image(domain)
DGtal::HyperRectDomain< Space >
DGtal::ImplicitBall::getUpperBound
RealPoint getUpperBound() const
Definition: ImplicitBall.h:120
DGtal::VolReader::importVol
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
DGtal::ImageContainerBySTLVector< Domain, Value >::Value
Value Value
Definition: ImageContainerBySTLVector.h:153
DGtal::ImplicitBall::getLowerBound
RealPoint getLowerBound() const
Definition: ImplicitBall.h:114
DGtal::detail::center
Point center(const std::vector< Point > &points)
Definition: QuickHullKernels.h:66
DGtal::Image::domain
const Domain & domain() const
Definition: Image.h:192
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::Color::Green
static const Color Green
Definition: Color.h:393
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::Color::Yellow
static const Color Yellow
Definition: Color.h:398
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition: ImageContainerBySTLVector.h:265
DGtal::PointVector::diagonal
static Self diagonal(Component val=1)
DGtal::Color::Blue
static const Color Blue
Definition: Color.h:395
DGtal::Trace::info
std::ostream & info()
DGtal::VolWriter
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:68
DGtal::Color::Red
static const Color Red
Definition: Color.h:392
DGtal::Viewer3D
Definition: Viewer3D.h:135
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal::functors::Ceil
Functor that rounds up.
Definition: BasicFunctors.h:217
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ImplicitBall
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:64
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::ClippingPlane
Class for adding a Clipping plane through the Viewer3D stream. Realizes the concept CDrawableWithView...
Definition: DrawWithDisplay3DModifier.h:156
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::Image::range
Range range()
Definition: Image.h:214
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition: ExactPredicateLpSeparableMetric.h:87
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
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...
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::functors::Floor
Functor that rounds down.
Definition: BasicFunctors.h:184
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
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38
DGtal::functors::SimpleThresholdForegroundPredicate
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Definition: SimpleThresholdForegroundPredicate.h:65