DGtal  1.5.beta
testDigitalMetricAdapter.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/geometry/volumes/distance/CDigitalMetricSpace.h"
36 #include "DGtal/geometry/volumes/distance/DigitalMetricAdapter.h"
38 
39 using namespace std;
40 using namespace DGtal;
41 
43 // Functions for testing class DigitalMetricAdapter.
45 
50 {
51  unsigned int nbok = 0;
52  unsigned int nb = 0;
53 
54  typedef Z2i::L2Metric L2;
55  L2 l2;
56  typedef DigitalMetricAdapter<L2> Adapted;
57 
58  Adapted adapted(l2);
59 
60  BOOST_CONCEPT_ASSERT(( concepts::CDigitalMetricSpace<Adapted> ));
61 
62  return nbok == nb;
63 }
67 bool testVal()
68 {
69  unsigned int nbok = 0;
70  unsigned int nb = 0;
71 
72  typedef Z2i::L2Metric L2;
73  L2 l2;
74  typedef DigitalMetricAdapter<L2> Adapted;
75  Adapted adapted(l2);
76 
77  BOOST_CONCEPT_ASSERT(( concepts::CDigitalMetricSpace<Adapted> ));
78 
79  L2::Point a(0,0), b(5,2);
80 
81  Adapted::Value d = adapted(a,b);
82  trace.info() << "distance= "<< l2(a,b)<< " and adapted= "<< d << std::endl;
83  nbok += (d == 6) ? 1 : 0;
84  nb++;
85  trace.info() << "(" << nbok << "/" << nb << ") "
86  << std::endl;
87  return nbok == nb;
88 }
89 
91 // Standard services - public :
92 
93 int main( int argc, char** argv )
94 {
95  trace.beginBlock ( "Testing class DigitalMetricAdapter" );
96  trace.info() << "Args:";
97  for ( int i = 0; i < argc; ++i )
98  trace.info() << " " << argv[ i ];
99  trace.info() << endl;
100 
101  bool res = testConcepts() && testVal(); // && ... other tests
102  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
103  trace.endBlock();
104  return res ? 0 : 1;
105 }
106 // //
Aim: simple adapter class which adapts any models of concepts::CMetricSpace to a model of concepts::C...
Aim: implements separable l_p metrics with exact predicates.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: defines the concept of digital metric spaces.
MyPointD Point
Definition: testClone2.cpp:383
int main(int argc, char **argv)
bool testConcepts()
bool testVal()