DGtal  0.9.3
Typedefs | Functions
testDistancePropagation.cpp File Reference
#include <iostream>
#include <set>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/CanonicEmbedder.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/graph/CUndirectedSimpleGraph.h"
#include "DGtal/graph/CGraphVisitor.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/shapes/Shapes.h"
Include dependency graph for testDistancePropagation.cpp:

Go to the source code of this file.

Typedefs

typedef ImageSelector< Z2i::Domain, int >::Type Image
 

Functions

bool testDistancePropagation ()
 
int main (int, char **)
 

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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2012/06/18

Functions for testing objects as graph.

This file is part of the DGtal library.

Definition in file testDistancePropagation.cpp.

Typedef Documentation

◆ Image

typedef ImageSelector< Z2i::Domain, int>::Type Image

Definition at line 56 of file testDistancePropagation.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 172 of file testDistancePropagation.cpp.

References testDistancePropagation().

173 {
174  bool res = testDistancePropagation();
175  return res ? 0 : 1;
176 }
bool testDistancePropagation()

◆ testDistancePropagation()

bool testDistancePropagation ( )

Definition at line 57 of file testDistancePropagation.cpp.

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::current(), domain(), DGtal::Trace::endBlock(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::expand(), DGtal::BreadthFirstVisitor< TGraph, TMarkSet >::finished(), image(), DGtal::Trace::info(), LibBoard::Board::saveEPS(), and DGtal::trace.

Referenced by main().

58 {
59  typedef Z2i::Space Space;
60  typedef Z2i::Point Point;
61  typedef Z2i::Domain Domain;
63  typedef Z2i::Object4_8 Object;
64 
65  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> ));
66 
67  trace.beginBlock( "Distance propagation in 2D object" );
68  Point p1( -41, -36 );
69  Point p2( 18, 18 );
70  Domain domain( p1, p2 );
71  Point c1( -2, -1 );
72  Point c2( -14, 5 );
73  Point c3( -30, -15 );
74  Point c4( -10, -20 );
75  Point c5( 12, -1 );
76  DigitalSet shape_set( domain );
77 
78  Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 );
79  Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 );
80  Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 );
81  Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 );
82  Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 );
83 
84  Object obj(Z2i::dt4_8, shape_set);
85 
86 
87  GradientColorMap<int> cmap_grad( 0, 25);
88  cmap_grad.addColor( Color( 0, 0, 255 ) );
89  cmap_grad.addColor( Color( 0, 255, 0 ) );
90  cmap_grad.addColor( Color( 255, 0, 0 ) );
91 
92  Board2D board;
93  board << SetMode( domain.className(), "Paving" )
94  << domain
95  << SetMode( p1.className(), "Paving" );
96 
97  Image image = ImageFromSet<Image>::create(shape_set, 1);
98 
99  // Type definitions
100  typedef CanonicEmbedder<Space> VertexEmbedder;
102  typedef RealPoint::Coordinate Scalar;
104  typedef std::binder1st< Distance > DistanceToPoint;
107 
108  BOOST_CONCEPT_ASSERT(( CGraphVisitor<Visitor> ));
109 
110 
111  VertexEmbedder embedder;
112  Distance distance;
113  DistanceToPoint distanceToPoint = std::bind1st( distance, embedder( c1 ) );
114  VertexFunctor vfunctor( embedder, distanceToPoint );
115  Visitor visitor( obj, vfunctor, c1 );
116 
117  while( ! visitor.finished() )
118  {
119  Scalar v = visitor.current().second;
120  image.setValue( visitor.current().first, v );
121  visitor.expand();
122  }
123 
124  string specificStyle = p1.className() + "/Paving";
125 
126  for ( DigitalSet::ConstIterator it = shape_set.begin();
127  it != shape_set.end();
128  ++it )
129  {
130  if( image(*it) == 0)
131  board << CustomStyle( specificStyle,
132  new CustomColors( Color::Black,
133  Color::Red ) );
134  else if( image(*it) > 0 )
135  board << CustomStyle( specificStyle,
136  new CustomColors( Color::Black,
137  cmap_grad( image(*it) ) ) );
138  else
139  board << CustomStyle( specificStyle,
140  new CustomColors( Color::Black,
141  cmap_grad( 0 ) ) );
142  board << *it;
143  }
144 
145  trace.info() << "- Output file testDistancePropagation.eps" << std::endl;
146  board.saveEPS("testDistancePropagation.eps");
147  trace.endBlock();
148 
149  trace.beginBlock( "Distance visitor as a range." );
150  typedef GraphVisitorRange<Visitor> VisitorRange;
151  VisitorRange range( new Visitor( obj, vfunctor, c1 ) );
152  Scalar d = -1.0;
153  unsigned int nb = 0;
154  unsigned int nbok = 0;
155  unsigned int nbperfect = 0;
156  for ( VisitorRange::NodeConstIterator it = range.beginNode(), itEnd = range.endNode();
157  it != itEnd; ++it )
158  { // Vertex is *it.first
159  Scalar next_d = (*it).second;
160  ++nb, nbok += (next_d >= d-0.75 ) ? 1 : 0;
161  nbperfect += (next_d >= d ) ? 1 : 0;
162  d = next_d;
163  }
164  trace.info() << "(" << nbok << "/" << nb
165  << ") number of vertices in approximate Euclidean distance ordering."<< std::endl;
166  trace.info() << "(" << nbperfect << "/" << nb
167  << ") number of vertices in perfect Euclidean distance ordering."<< std::endl;
168  trace.endBlock();
169  return nb == nbok;
170 }
Aim: This class is useful to perform an exploration of a graph given a starting point or set (called ...
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:119
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
HyperRectDomain< Space > Domain
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
Aim: Define utilities to convert a digital set into an image.
Definition: ImageFromSet.h:63
double endBlock()
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
BreadthFirstVisitor< MyDigitalSurface > Visitor
Aim: implements separable l_p metrics with exact predicates.
Aim: Define a new Functor from the composition of two other functors.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
std::string className() const
MyPointD Point
Definition: testClone2.cpp:383
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Transforms a graph visitor into a single pass input range.
Aim: A trivial embedder for digital points, which corresponds to the canonic injection of Zn into Rn...
Aim: Represents the concept of local graph: each vertex has neighboring vertices, but we do not neces...
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Space::RealPoint RealPoint
Definition: StdDefs.h:97
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Image image(domain)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70
Aim: Defines the concept of a visitor onto a graph, that is an object that traverses vertices of the ...