DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
toricdomainvolumetric.cpp File Reference
#include <iostream>
#include <iomanip>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/TickedColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include <boost/algorithm/minmax_element.hpp>

Go to the source code of this file.

Functions

int main ()
 

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2016/10/17

An example file named toricdomainvolumetric. The aim of this example is to demonstrate the volumetric analysis functions on toric domains.

This file is part of the DGtal library.

Definition in file toricdomainvolumetric.cpp.

Function Documentation

◆ main()

int main ( void  )

[DTDef]

[DTDef]

[DTPredicate]

[DTPredicate]

[DTComputeToric]

[DTComputeToric]

[DTComputePartialToric]

[DTComputePartialToric]

[DTColormaps]

[DTColormaps]

Definition at line 61 of file toricdomainvolumetric.cpp.

62{
63
65 using namespace std;
66 using namespace DGtal;
67 using namespace Z2i;
68
69 Point a ( 0, 0 );
70 Point b ( 32, 16);
71
72 //Input image with unsigned char values
74 Image image ( Domain(a, b ));
75
76 //We fill the image with the 128 value
77 for ( Image::Iterator it = image.begin(), itend = image.end();it != itend; ++it)
78 (*it)=128;
79
80 //We add 3 seeds with 0 values.
81 image.setValue(Point(16,2), 0);
82 image.setValue(Point(2,11), 0);
83 image.setValue(Point(30,15), 0);
85
86 trace.beginBlock ( "Example toricdomainvolumetric" );
87 //Input shape output
89 Board2D board;
91 Display2DFactory::drawImage<Gray>(board, image, (unsigned int)0, (unsigned int)129);
92 board.saveSVG("toric-inputShape.svg");
93
95 //Point Predicate from random seed image
97 PointPredicate predicate(image,0);
99
103
104 //Regular 2D domain
105 DTL2 dtL2(image.domain(), predicate, l2Metric);
106 //Full toric 2D domain
107 DTL2Toric dtL2Toric(image.domain(), predicate, l2Metric, {{true, true}} );
109
113
114 // 2D domain that is periodic along the first dimension.
115 DTL2ToricX dtL2ToricX( image.domain(), predicate, l2Metric, {{true, false}} );
116 // 2D domain that is periodic along the second dimension.
117 DTL2ToricY dtL2ToricY( image.domain(), predicate, l2Metric, {{false, true}} );
119
120 //We compute the maximum DT value on the L2 map
121 const DTL2::Value maxv2 = * (boost::first_max_element(dtL2.constRange().begin(), dtL2.constRange().end()));
122 const DTL2Toric::Value maxvtoric = * (boost::first_max_element(dtL2Toric.constRange().begin(), dtL2Toric.constRange().end()));
123 const DTL2ToricX::Value maxvtoricX = * (boost::first_max_element(dtL2ToricX.constRange().begin(), dtL2ToricX.constRange().end()));
124 const DTL2ToricY::Value maxvtoricY = * (boost::first_max_element(dtL2ToricY.constRange().begin(), dtL2ToricY.constRange().end()));
125
126 // Color map based on the maximal value for all maps (in order to compare results with similar colors).
127 const auto maxvall = std::max( { maxv2, maxvtoric, maxvtoricX, maxvtoricY } );
128
130 //Colormap used for the SVG output
131 typedef HueShadeColorMap<DTL2::Value, 1> HueTwice;
133
134 trace.warning() << "DT maxValue= " << maxv2 << endl;
135 board.clear();
136 Display2DFactory::drawImage<HueTwice>(board, dtL2, 0.0, maxvall + 1);
137 board.saveSVG ( "toric-example-DT-L2.svg" );
138
139 trace.warning() << "Full toric maxValue= " << maxvtoric << endl;
140 board.clear();
141 Display2DFactory::drawImage<HueTwice>(board, dtL2Toric, 0.0, maxvall + 1);
142 board.saveSVG ( "toric-example-DT-L2-toric.svg" );
143
144 trace.warning() << "1th dimension periodic maxValue= " << maxvtoricX << endl;
145 board.clear();
146 Display2DFactory::drawImage<HueTwice>(board, dtL2ToricX, 0.0, maxvall + 1);
147 board.saveSVG ( "toric-example-DT-L2-toricX.svg" );
148
149 trace.warning() << "2nd dimension periodic maxValue= " << maxvtoricY << endl;
150 board.clear();
151 Display2DFactory::drawImage<HueTwice>(board, dtL2ToricY, 0.0, maxvall + 1);
152 board.saveSVG ( "toric-example-DT-L2-toricY.svg" );
153
154 //Explicit export with ticked colormap
155 //We compute the maximum DT value on the L2 map
156 TickedColorMap<double, GradientColorMap<double> > ticked(0.0,maxv2, Color::White);
157 ticked.addRegularTicks(3, 0.5);
158 ticked.finalize();
159 ticked.colormap()->addColor( Color::Red );
160 ticked.colormap()->addColor( Color::Black );
161 board.clear();
162 for ( auto it = dtL2.domain().begin(), itend = dtL2.domain().end();it != itend; ++it)
163 {
164 board<< CustomStyle((*it).className(),new CustomColors(ticked(dtL2(*it)),ticked(dtL2(*it))));
165 board << *it;
166 }
167 board.saveSVG("toric-example-DT-L2-ticked.svg");
168
169 board.clear();
170 for ( auto it = dtL2Toric.domain().begin(), itend = dtL2Toric.domain().end();it != itend; ++it)
171 {
172 board<< CustomStyle((*it).className(),new CustomColors(ticked(dtL2Toric(*it)),ticked(dtL2Toric(*it))));
173 board << *it;
174 }
175 board.saveSVG("toric-example-DT-L2-ticked-toric.svg");
176
177 board.clear();
178 for ( auto it = dtL2ToricX.domain().begin(), itend = dtL2ToricX.domain().end();it != itend; ++it)
179 {
180 board<< CustomStyle((*it).className(),new CustomColors(ticked(dtL2ToricX(*it)),ticked(dtL2ToricX(*it))));
181 board << *it;
182 }
183 board.saveSVG("toric-example-DT-L2-ticked-toricX.svg");
184
185 board.clear();
186 for ( auto it = dtL2ToricY.domain().begin(), itend = dtL2ToricY.domain().end();it != itend; ++it)
187 {
188 board<< CustomStyle((*it).className(),new CustomColors(ticked(dtL2ToricY(*it)),ticked(dtL2ToricY(*it))));
189 board << *it;
190 }
191 board.saveSVG("toric-example-DT-L2-ticked-toricY.svg");
192
193 //Voronoi vector output
194 board.clear();
195 board << dtL2.domain();
196 for ( auto it = dtL2.domain().begin(), itend = dtL2.domain().end();it != itend; ++it)
197 if ( dtL2.getVoronoiSite(*it) != *it )
198 Display2DFactory::draw(board,dtL2.getVoronoiSite(*it) - (*it), (*it));
199 board.saveSVG("toric-example-Voro-L2.svg");
200
201 board.clear();
202 board << dtL2Toric.domain();
203 for ( auto it = dtL2Toric.domain().begin(), itend = dtL2Toric.domain().end();it != itend; ++it)
204 if ( dtL2Toric.getVoronoiSite(*it) != *it )
205 Display2DFactory::draw(board, dtL2Toric.getVoronoiSite(*it) - (*it), (*it));
206 board.saveSVG("toric-example-Voro-L2-toric.svg");
207
208 board.clear();
209 board << dtL2Toric.domain();
210 for ( auto it = dtL2Toric.domain().begin(), itend = dtL2Toric.domain().end();it != itend; ++it)
211 if ( dtL2Toric.getVoronoiSite(*it) != *it )
212 Display2DFactory::draw(board, dtL2Toric.projectPoint(dtL2Toric.getVoronoiSite(*it)) - (*it), (*it));
213 board.saveSVG("toric-example-Voro-L2-toric-projected.svg");
214
215 board.clear();
216 board << dtL2ToricX.domain();
217 for ( auto it = dtL2ToricX.domain().begin(), itend = dtL2ToricX.domain().end();it != itend; ++it)
218 if ( dtL2ToricX.getVoronoiSite(*it) != *it )
219 Display2DFactory::draw(board, dtL2ToricX.getVoronoiSite(*it) - (*it), (*it));
220 board.saveSVG("toric-example-Voro-L2-toricX.svg");
221
222 board.clear();
223 board << dtL2ToricY.domain();
224 for ( auto it = dtL2ToricY.domain().begin(), itend = dtL2ToricY.domain().end();it != itend; ++it)
225 if ( dtL2ToricY.getVoronoiSite(*it) != *it )
226 Display2DFactory::draw(board, dtL2ToricY.getVoronoiSite(*it) - (*it), (*it));
227 board.saveSVG("toric-example-Voro-L2-toricY.svg");
228
229 trace.endBlock();
230 return 0;
231}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: This class adapts any colormap to add "ticks" in the colormap colors.
void beginBlock(const std::string &keyword="")
std::ostream & warning()
double endBlock()
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void setUnit(Unit unit)
Definition: Board.cpp:240
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
MyPointD Point
Definition: testClone2.cpp:383
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain

References DGtal::Trace::beginBlock(), LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), and LibBoard::Board::UCentimeter.