DGtal  0.9.2
testReducedMedialAxis.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/ReducedMedialAxis.h"
36 #include "DGtal/geometry/volumes/distance/ExactPredicateLpPowerSeparableMetric.h"
37 #include "DGtal/kernel/sets/DigitalSetDomain.h"
38 #include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Functions for testing class PowerMap.
47 
51 bool testReducedMedialAxis()
52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
55 
56  trace.beginBlock ( "Testing PowerMap2D ..." );
57 
58  Z2i::Domain domain(Z2i::Point(0,0),Z2i::Point(10,10));
59  Z2i::Domain domainLarge(Z2i::Point(0,0),Z2i::Point(10,10));
60 
62  set.insertNew(Z2i::Point(3,3));
63  //set.insertNew(Z2i::Point(3,7));
64  set.insertNew(Z2i::Point(7,7));
65 
68  Image image( new SetDomain( set ) );
69 
70  //Setting some values
71  image.setValue(Z2i::Point(3,3), 9);
72  // image.setValue(Z2i::Point(3,7), 0);
73  image.setValue(Z2i::Point(7,7), 16);
74 
75  Z2i::L2PowerMetric l2power;
76  PowerMap<Image, Z2i::L2PowerMetric> power(&domainLarge, &image, &l2power);
77  for(unsigned int i=0; i<11; i++)
78  {
79  for(unsigned int j=0; j<11; j++)
80  if (image.domain().isInside(Z2i::Point(i,j)))
81  trace.info()<< image(Z2i::Point(i,j))<<" ";
82  else
83  trace.info()<< "0 ";
84  trace.info()<<std::endl;
85  }
86  trace.info()<<std::endl;
87 
88  //Power Map
89  for(unsigned int i=0; i<11; i++)
90  {
91  for(unsigned int j=0; j<11; j++)
92  trace.info()<< power(Z2i::Point(i,j))[0]<<","<<power(Z2i::Point(i,j))[1]<<" ";
93  trace.info()<<std::endl;
94  }
95 
96  trace.info()<<std::endl;
97  //Reconstruction
98  for(unsigned int i=0; i<11; i++)
99  {
100  for(unsigned int j=0; j<11; j++)
101  {
102  Z2i::Point p(i,j);
103  DGtal::int32_t dist = (i-power(p)[0])*(i-power(p)[0]) +
104  ( j-power(p)[1])*(j-power(p)[1]) - image(power(p));
105  trace.info()<< dist;
106  }
107  std::cerr<<std::endl;
108  }
109  trace.info()<<std::endl;
110 
111  //Medial Axis extraction
113 
114  //Reconstruction
115  for(unsigned int i=0; i<11; i++)
116  {
117  for(unsigned int j=0; j<11; j++)
118  {
119  Z2i::Point p(i,j);
120  if (rdma.domain().isInside(p) )
121  trace.info()<< rdma(p);
122  else
123  trace.info()<< " - ";
124 
125  }
126  std::cerr<<std::endl;
127  }
128  trace.info()<<std::endl;
129 
130 
131  nbok += true ? 1 : 0;
132  nb++;
133  trace.info() << "(" << nbok << "/" << nb << ") "
134  << "true == true" << std::endl;
135  trace.endBlock();
136 
137  return nbok == nb;
138 }
139 
141 // Standard services - public :
142 
143 int main( int argc, char** argv )
144 {
145  trace.beginBlock ( "Testing class ReducedMedialAxis" );
146  trace.info() << "Args:";
147  for ( int i = 0; i < argc; ++i )
148  trace.info() << " " << argv[ i ];
149  trace.info() << endl;
150 
151  bool res = testReducedMedialAxis(); // && ... other tests
152  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
153  trace.endBlock();
154  return res ? 0 : 1;
155 }
156 // //
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
Aim: Implementation of the separable medial axis extraction.
Aim: A container class for storing sets of digital points within some given domain.