DGtal  0.9.3
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 dependency graph for toricdomainvolumetric.cpp:

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 ( )

[DTDef]

[DTDef]

[DTPredicate]

[DTPredicate]

[DTComputeToric]

[DTComputeToric]

[DTComputePartialToric]

[DTComputePartialToric]

[DTColormaps]

[DTColormaps]

Definition at line 59 of file toricdomainvolumetric.cpp.

References DGtal::TickedColorMap< TValue, TColorMap >::addRegularTicks(), DGtal::Trace::beginBlock(), DGtal::TickedColorMap< TValue, TColorMap >::colormap(), draw(), DGtal::Trace::endBlock(), DGtal::TickedColorMap< TValue, TColorMap >::finalize(), image(), max(), LibBoard::Board::setUnit(), DGtal::Image< TImageContainer >::setValue(), DGtal::trace, LibBoard::Board::UCentimeter, and DGtal::Trace::warning().

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