DGtal  0.9.2
testPowerMap.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/volumes/distance/PowerMap.h"
35 #include "DGtal/geometry/volumes/distance/ExactPredicateLpPowerSeparableMetric.h"
36 #include "DGtal/kernel/sets/DigitalSetDomain.h"
37 #include "DGtal/images/ImageContainerBySTLMap.h"
38 #include "DGtal/images/ImageContainerBySTLVector.h"
39 #include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 // Functions for testing class PowerMap.
48 
52 bool testPowerMap()
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
57  trace.beginBlock ( "Testing PowerMap2D ..." );
58 
59  Z2i::Domain domain(Z2i::Point(0,0),Z2i::Point(10,10));
60  Z2i::Domain domainLarge(Z2i::Point(0,0),Z2i::Point(10,10));
61 
63  set.insertNew(Z2i::Point(3,3));
64  //set.insertNew(Z2i::Point(3,7));
65  set.insertNew(Z2i::Point(7,7));
66 
69 
70  Image image( new SetDomain( set ) );
71 
72  //Setting some values
73  image.setValue(Z2i::Point(3,3), 9);
74  // image.setValue(Z2i::Point(3,7), 0);
75  image.setValue(Z2i::Point(7,7), 16);
76 
77  Z2i::L2PowerMetric l2power;
78  PowerMap<Image, Z2i::L2PowerMetric> power(&domainLarge, &image, &l2power);
79  for(unsigned int i=0; i<11; i++)
80  {
81  for(unsigned int j=0; j<11; j++)
82  if (image.domain().isInside(Z2i::Point(i,j)))
83  trace.info()<< image(Z2i::Point(i,j))<<" ";
84  else
85  trace.info()<< "0 ";
86  trace.info()<<std::endl;
87  }
88  trace.info()<<std::endl;
89 
90  //Power Map
91  for(unsigned int i=0; i<11; i++)
92  {
93  for(unsigned int j=0; j<11; j++)
94  trace.info()<< power(Z2i::Point(i,j))[0]<<","<<power(Z2i::Point(i,j))[1]<<" ";
95  trace.info()<<std::endl;
96  }
97  trace.info() << "REDT"<<std::endl;
98  trace.info()<<std::endl;
99  //Reconstruction
100  for(unsigned int i=0; i<11; i++)
101  {
102  for(unsigned int j=0; j<11; j++)
103  {
104  Z2i::Point p(i,j);
105  DGtal::int64_t dist = (i-power(p)[0])*(i-power(p)[0]) +
106  ( j-power(p)[1])*(j-power(p)[1]) - image(power(p));
107  trace.info()<< dist;
108  }
109  std::cerr<<std::endl;
110  }
111  trace.info()<<std::endl;
112 
113  //Reconstruction
114  for(unsigned int i=0; i<11; i++)
115  {
116  for(unsigned int j=0; j<11; j++)
117  {
118  Z2i::Point p(i,j);
119  DGtal::int32_t dist = (i-power(p)[0])*(i-power(p)[0]) +
120  ( j-power(p)[1])*(j-power(p)[1]) - image(power(p));
121  if (dist>=0)
122  std::cerr<< "0 ";
123  else
124  std::cerr<< "X ";
125  }
126  std::cerr<<std::endl;
127  }
128 
129  nbok += true ? 1 : 0;
130  nb++;
131  trace.info() << "(" << nbok << "/" << nb << ") "
132  << "true == true" << std::endl;
133  trace.endBlock();
134 
135  return nbok == nb;
136 }
137 
139 // Standard services - public :
140 
141 int main( int argc, char** argv )
142 {
143  trace.beginBlock ( "Testing class PowerMap" );
144  trace.info() << "Args:";
145  for ( int i = 0; i < argc; ++i )
146  trace.info() << " " << argv[ i ];
147  trace.info() << endl;
148 
149  bool res = testPowerMap(); // && ... other tests
150  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
151  trace.endBlock();
152  return res ? 0 : 1;
153 }
154 // //
void beginBlock(const std::string &keyword="")
Aim: implements weighted separable l_p metrics with exact predicates.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
T power(const T &aVal, const unsigned int exponent)
std::ostream & emphase()
Aim: Implementation of the linear in time Power map construction.
Definition: PowerMap.h:98
Aim: Constructs a domain limited to the given digital set.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Aim: A container class for storing sets of digital points within some given domain.