DGtal 2.0.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 argc, 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 argc,
char ** argv )

Definition at line 57 of file volDTGranulo.cpp.

58{
59
60 //Loarding the image
63 trace.info() << image << std::endl;
64
65 //Viewer
66 PolyscopeViewer<> viewer;
67
68 for(Image::Domain::ConstIterator it = image.domain().begin(),
69 itend = image.domain().end(); it != itend; ++it)
70 if (image(*it) != 0)
71 viewer << *it;
72
73 trace.info() << "viewer launched..."<<std::endl;
74 viewer.show();
75
76
77 //DT
80 Predicate binaryshape(image, 0);
81
83
84 DT distancemap(image.domain(), binaryshape, l2);
85
86 //Viewer
87 PolyscopeViewer<> viewer2;
88 DT::Value maxDT = (*boost::first_max_element(distancemap.constRange().begin(),
89 distancemap.constRange().end()));
90 trace.info() << "we display the dt map"<<std::endl;
91 int cpt=0;
92 viewer2 << DGtal::ClippingPlane(1,0,0,-10.1);
93
94 for(DT::Domain::ConstIterator it = distancemap.domain().begin(),
95 itend = distancemap.domain().end(); it != itend;
96 ++it)
97 if (distancemap(*it) > 0)
98 {
99 viewer2 << DGtal::WithQuantity(*it, "value", distancemap(*it));
100 cpt++;
101 }
102 trace.info() << "Got "<<cpt<<" points."<<std::endl;
103 trace.info() << "viewer2 launched..."<<std::endl;
104 viewer2.show();
105
106 //Granulo
107 Image imageGranulo ( image.domain() );
108 for(Image::Range::Iterator it = imageGranulo.range().begin(), itend= imageGranulo.range().end();
109 it != itend; ++it)
110 *it = 0;
111
112
113 trace.info() << "Computing the granulometry"<<std::endl;
114 cpt=0;
115 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
116 itend = imageGranulo.domain().end(); it != itend; ++it)
117 {
118 if (distancemap(*it) > 0)
119 {
120 //Construct the sphere with radius from distancemap(*it)
122 unsigned int radius = (unsigned int)distancemap(*it);
123 ImplicitBall<Z3i::Space> ball(center,radius);
124 Z3i::Point low(ball.getLowerBound() - Z3i::RealPoint::diagonal(1.0), functors::Floor<>());
125 Z3i::Point up (ball.getUpperBound() + Z3i::RealPoint::diagonal(1.0), functors::Ceil<>());
126 Z3i::Domain dom(low,up);
127
128 for(Z3i::Domain::ConstIterator itball = dom.begin(), itendball= dom.end();
129 itball != itendball; itball++)
130 if (imageGranulo.domain().isInside(*itball) &&
131 ( ball(*itball) > 0) &&
132 (imageGranulo(*itball) < radius))
133 imageGranulo.setValue(*itball, radius);
134
135 cpt++;
136 }
137 }
138
139 trace.info() << "Granulometry ok nbBalls="<<cpt<< std::endl;
140 VolWriter<Image, functors::Cast<unsigned char> >::exportVol("granulo.vol", imageGranulo);
141 trace.info() << "Save OK"<< std::endl;
142
143
144 //Viewer
145 PolyscopeViewer<> viewer3;
146 Image::Value maxG = (*boost::first_max_element(imageGranulo.constRange().begin(),
147 imageGranulo.constRange().end()));
148
149 viewer3 << DGtal::ClippingPlane(1,0,0,-10.1);
150 cpt=0;
151 for(Image::Domain::ConstIterator it = imageGranulo.domain().begin(),
152 itend = imageGranulo.domain().end(); it != itend;
153 ++it)
154 if (imageGranulo(*it) > 0)
155 {
156 viewer3 << DGtal::WithQuantity(*it, "value", imageGranulo(*it));
157 cpt++;
158 }
159 trace.info() << "Got "<<cpt<<" points."<<std::endl;
160 trace.info() << "viewer3 launched..."<<std::endl;
161 viewer3.show();
162 return 0;
163
164}
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
static Self diagonal(Component val=1)
void show() override
Starts the event loop and display of elements.
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
HyperRectDomain< Space > Domain
Definition StdDefs.h:172
Space::RealPoint RealPoint
Definition StdDefs.h:170
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition StdDefs.h:199
Space::Point Point
Definition StdDefs.h:168
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:327
Functor that rounds up.
Functor that rounds down.
Image image(domain)

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::SimpleRandomAccessConstRangeFromPoint< TConstIterator, DistanceFunctor >::begin(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::begin(), DGtal::Image< TImageContainer >::constRange(), DGtal::PointVector< dim, double >::diagonal(), DGtal::Image< TImageContainer >::domain(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::SimpleRandomAccessConstRangeFromPoint< TConstIterator, DistanceFunctor >::end(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::end(), DGtal::ImplicitBall< TSpace >::getLowerBound(), DGtal::ImplicitBall< TSpace >::getUpperBound(), image(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::HyperRectDomain< TSpace >::isInside(), DGtal::Image< TImageContainer >::range(), DGtal::Image< TImageContainer >::setValue(), DGtal::PolyscopeViewer< Space, KSpace >::show(), and DGtal::trace.