33 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/CanonicEmbedder.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/graph/CUndirectedSimpleGraph.h"
37 #include "DGtal/graph/CGraphVisitor.h"
38 #include "DGtal/graph/GraphVisitorRange.h"
39 #include "DGtal/graph/DistanceBreadthFirstVisitor.h"
40 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
41 #include "DGtal/io/boards/Board2D.h"
42 #include "DGtal/io/Color.h"
43 #include "DGtal/io/colormaps/GradientColorMap.h"
44 #include "DGtal/shapes/Shapes.h"
49 using namespace DGtal;
57 bool testDistancePropagation()
70 Domain domain( p1, p2 );
76 DigitalSet shape_set( domain );
84 Object obj(Z2i::dt4_8, shape_set);
88 cmap_grad.addColor(
Color( 0, 0, 255 ) );
89 cmap_grad.addColor(
Color( 0, 255, 0 ) );
90 cmap_grad.addColor(
Color( 255, 0, 0 ) );
95 <<
SetMode( p1.className(),
"Paving" );
102 typedef RealPoint::Coordinate Scalar;
104 typedef std::binder1st< Distance > DistanceToPoint;
111 VertexEmbedder embedder;
113 DistanceToPoint distanceToPoint = std::bind1st( distance, embedder( c1 ) );
114 VertexFunctor vfunctor( embedder, distanceToPoint );
115 Visitor visitor( obj, vfunctor, c1 );
117 while( ! visitor.finished() )
119 Scalar v = visitor.current().second;
120 image.setValue( visitor.current().first, v );
124 string specificStyle = p1.className() +
"/Paving";
126 for ( DigitalSet::ConstIterator it = shape_set.begin();
127 it != shape_set.end();
134 else if( image(*it) > 0 )
137 cmap_grad( image(*it) ) ) );
145 trace.
info() <<
"- Output file testDistancePropagation.eps" << std::endl;
146 board.
saveEPS(
"testDistancePropagation.eps");
151 VisitorRange range(
new Visitor( obj, vfunctor, c1 ) );
154 unsigned int nbok = 0;
155 unsigned int nbperfect = 0;
156 for ( VisitorRange::NodeConstIterator it = range.beginNode(), itEnd = range.endNode();
159 Scalar next_d = (*it).second;
160 ++nb, nbok += (next_d >= d-0.75 ) ? 1 : 0;
161 nbperfect += (next_d >= d ) ? 1 : 0;
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;
172 int main(
int ,
char** )
174 bool res = testDistancePropagation();
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...
void beginBlock(const std::string &keyword="")
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
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.
Aim: Define utilities to convert a digital set into an image.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Aim: Gathers several functions useful for concept checks.
Aim: implements separable l_p metrics with exact predicates.
Aim: Define a new Functor from the composition of two other functors.
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
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...
Aim: This class is useful to perform a breadth-first exploration of a graph given a starting point or...
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Structure representing an RGB triple with alpha component.
Space::RealPoint RealPoint
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Aim: Defines the concept of a visitor onto a graph, that is an object that traverses vertices of the ...