DGtal 2.1.0
Loading...
Searching...
No Matches
volDTGranulo.cpp File Reference

An example of generating a grid curve from a parametric shape and estimating its length. More...

#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/PolyscopeViewer.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include <boost/algorithm/minmax_element.hpp>
Include dependency graph for volDTGranulo.cpp:

Go to the source code of this file.

Functions

int main (int, char **argv)
 

Detailed Description

An example of generating a grid curve from a parametric shape and estimating its length.

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr)
Date
2010/10/17

This file is part of the DGtal library.

Definition in file volDTGranulo.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **  argv 
)

Definition at line 57 of file volDTGranulo.cpp.

58{
59 //Loarding the image
62 trace.info() << image << std::endl;
63
64 //Viewer
65 PolyscopeViewer<> viewer;
66
67 for(Image::Domain::ConstIterator it = image.domain().begin(),
68 itend = image.domain().end(); it != itend; ++it)
69 if (image(*it) != 0)
70 viewer << *it;
71
72 trace.info() << "viewer launched..."<<std::endl;
73 viewer.show();
74
75
76 //DT
79 Predicate binaryshape(image, 0);
80
82
83 DT distancemap(image.domain(), binaryshape, l2);
84
85 //Viewer
86 PolyscopeViewer<> viewer2;
87 trace.info() << "we display the dt map"<<std::endl;
88 int cpt=0;
89 viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
90
91 for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
92 itend = distancemap.domain().end(); it != itend;
93 ++it)
94 if (distancemap(*it) > 0)
95 {
96 viewer2 << DGtal::WithQuantity(*it, "value", distancemap(*it));
97 cpt++;
98 }
99 trace.info() << "Got "<<cpt<<" points."<<std::endl;
100 trace.info() << "viewer2 launched..."<<std::endl;
101 viewer2.show();
102
103 //Granulo
104 Image imageGranulo ( image.domain() );
105 for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
106 it != itend; ++it)
107 *it = 0;
108
109
110 trace.info() << "Computing the granulometry"<<std::endl;
111 cpt=0;
112 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
113 itend = imageGranulo.domain().end(); it != itend; ++it)
114 {
115 if (distancemap(*it) > 0)
116 {
117 //Construct the sphere with radius from distancemap(*it)
119 unsigned int radius = (unsigned int)distancemap(*it);
120 ImplicitBall<Z3i::Space> ball(center,radius);
121 Z3i::Point low(ball.getLowerBound() - Z3i::RealPoint::diagonal(1.0), functors::Floor<>());
122 Z3i::Point up (ball.getUpperBound() + Z3i::RealPoint::diagonal(1.0), functors::Ceil<>());
123 Z3i::Domain dom(low,up);
124
125 for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
126 itball != itendball; itball++)
127 if (imageGranulo.domain().isInside(*itball) &&
128 ( ball(*itball) > 0) &&
129 (imageGranulo(*itball) < radius))
130 imageGranulo.setValue(*itball, radius);
131
132 cpt++;
133 }
134 }
135
136 trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
137 VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
138 trace.info() << "Save OK"<< std::endl;
139
140
141 //Viewer
142 PolyscopeViewer<> viewer3;
143
144 viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
145 cpt=0;
146 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
147 itend = imageGranulo.domain().end(); it != itend;
148 ++it)
149 if (imageGranulo(*it) > 0)
150 {
151 viewer3 << DGtal::WithQuantity(*it, "value", imageGranulo(*it));
152 cpt++;
153 }
154 trace.info() << "Got "<<cpt<<" points."<<std::endl;
155 trace.info() << "viewer3 launched..."<<std::endl;
156 viewer3.show();
157 return 0;
158
159}
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements separable l_p metrics with exact predicates.
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Aim: Implements basic operations that will be used in Point and Vector classes.
static Self diagonal(Component val=1)
void show() override
Starts the event loop and display of elements.
std::ostream & info()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
Point center(const std::vector< Point > &points)
Trace trace
Clipping plane.
Definition Display3D.h:299
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Aim: Export a 3D Image using the Vol formats.
Definition VolWriter.h:69
Attach a property to an element.
Definition Display3D.h:331
Functor that rounds up.
Functor that rounds down.
Image image(domain)

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::diagonal(), DGtal::Image< TImageContainer >::domain(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::ImplicitBall< TSpace >::getLowerBound(), DGtal::ImplicitBall< TSpace >::getUpperBound(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), DGtal::Image< TImageContainer >::range(), DGtal::Image< TImageContainer >::setValue(), DGtal::PolyscopeViewer< Space, KSpace >::show(), and DGtal::trace.