DGtal  0.9.2
testMetricBalls.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
35 #include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
36 #include "DGtal/io/boards/Board2D.h"
37 #include "DGtal/kernel/BasicPointPredicates.h"
38 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
39 #include "DGtal/io/colormaps/HueShadeColorMap.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 using namespace DGtal::functors;
45 
47 // Functions for testing class MetricBalls.
49 
50 
51 template <int norm>
52 bool testExactMetricBalls()
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
57  Z2i::Domain domain(Z2i::Point(0,0), Z2i::Point(64,64));
59  Z2i::DigitalSet set(domain);
60 
61  set.insertNew(Z2i::Point(32,32));
63  // SetPredicate<Z2i::DigitalSet> setpred(set);
64  NegPred predicate( set );
65 
67  Metric metric;
68  DT dt( &domain, &predicate, &metric);
69 
70 
71  Board2D board;
74  Display2DFactory::drawImage<Hue> (board, dt,
75  0.0,
76  32*sqrt(2)/2.0);
77 
78  std::string title = "image-ball-" + boost::lexical_cast<string>( norm )+".png" ;
79 #ifdef WITH_CAIRO
80  board.saveCairo(title.c_str(), Board2D::CairoPNG );
81 #endif
82  return nbok == nb;
83 }
84 
85 bool testInexactMetricBalls(double norm)
86 {
87  unsigned int nbok = 0;
88  unsigned int nb = 0;
89 
90  Z2i::Domain domain(Z2i::Point(0,0), Z2i::Point(64,64));
92  Z2i::DigitalSet set(domain);
93 
94  set.insertNew(Z2i::Point(32,32));
96  // SetPredicate<Z2i::DigitalSet> setpred(set);
97  NegPred predicate( set );
98 
100  Metric metric(norm);
101  DT dt( &domain, &predicate, &metric);
102 
103 
104  Board2D board;
105  typedef HueShadeColorMap< DT::Value,2> Hue;
107  Display2DFactory::drawImage<Hue> (board, dt,
108  0.0,
109  32*sqrt(2)/2.0);
110 
111  std::string title = "image-ball-" + boost::lexical_cast<string>( norm )+".png" ;
112 #ifdef WITH_CAIRO
113  board.saveCairo(title.c_str(), Board2D::CairoPNG );
114 #endif
115  return nbok == nb;
116 }
117 
119 // Standard services - public :
120 
121 int main( int argc, char** argv )
122 {
123  trace.beginBlock ( "Testing class MetricBalls" );
124  trace.info() << "Args:";
125  for ( int i = 0; i < argc; ++i )
126  trace.info() << " " << argv[ i ];
127  trace.info() << endl;
128 
129  bool res = testExactMetricBalls<2>()
130  && testExactMetricBalls<1>()
131  && testExactMetricBalls<4>()
132  && testExactMetricBalls<8>()
133  && testInexactMetricBalls(1.4)
134  && testInexactMetricBalls(43.1)
135  && testInexactMetricBalls(0.8)
136  ; // && ... other tests
137  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
138  trace.endBlock();
139  return res ? 0 : 1;
140 }
141 // //
void beginBlock(const std::string &keyword="")
Aim: The predicate returns true when the point predicate given at construction return false...
Aim: Implementation of the linear in time distance transformation for separable metrics.
Trace trace
Definition: Common.h:130
Aim: implements separable l_p metrics with approximated predicates.
STL namespace.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
functors namespace gathers all DGtal functors.
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
Aim: implements separable l_p metrics with exact predicates.
std::ostream & emphase()
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...
std::ostream & info()
void setUnit(Unit unit)
Definition: Board.cpp:240
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70