DGtal  1.5.beta
testMetricBalls.cpp
Go to the documentation of this file.
1 
31 #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>
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
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 
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 // //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Implementation of the linear in time distance transformation for separable metrics.
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements separable l_p metrics with approximated predicates.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void setUnit(Unit unit)
Definition: Board.cpp:239
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1138
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: The predicate returns true when the point predicate given at construction return false....
bool testInexactMetricBalls(double norm)
int main(int argc, char **argv)
bool testExactMetricBalls()
Domain domain