DGtal 1.3.0
Loading...
Searching...
No Matches
testReducedMedialAxis.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <array>
33
34#include "DGtal/base/Common.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/geometry/volumes/distance/PowerMap.h"
37#include "DGtal/geometry/volumes/distance/ReducedMedialAxis.h"
38#include "DGtal/geometry/volumes/distance/ExactPredicateLpPowerSeparableMetric.h"
39#include "DGtal/kernel/sets/DigitalSetDomain.h"
40#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
42
43using namespace std;
44using namespace DGtal;
45
47// Functions for testing class PowerMap.
49
53bool testReducedMedialAxis( std::array<bool, 2> const& aPeriodicity = {{ false, false }} )
54{
55 unsigned int nbok = 0;
56 unsigned int nb = 0;
57
58 trace.beginBlock ( "Testing PowerMap2D ..." );
59
61 Z2i::Domain domainLarge(Z2i::Point(0,0),Z2i::Point(10,10));
62
64 set.insertNew(Z2i::Point(3,3));
65 //set.insertNew(Z2i::Point(3,7));
66 set.insertNew(Z2i::Point(7,7));
67
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, aPeriodicity );
79
80 for(unsigned int i=0; i<11; i++)
81 {
82 for(unsigned int j=0; j<11; j++)
83 if (image.domain().isInside(Z2i::Point(i,j)))
84 trace.info()<< image(Z2i::Point(i,j))<<" ";
85 else
86 trace.info()<< "0 ";
87
88 trace.info()<<std::endl;
89 }
90 trace.info()<<std::endl;
91
92 //Power Map
93 for(unsigned int i=0; i<11; i++)
94 {
95 for(unsigned int j=0; j<11; j++)
96 trace.info()<< power(Z2i::Point(i,j))[0]<<","<<power(Z2i::Point(i,j))[1]<<" ";
97 trace.info()<<std::endl;
98 }
99
100 trace.info()<<std::endl;
101 //Reconstruction
102 for(unsigned int i=0; i<11; i++)
103 {
104 for(unsigned int j=0; j<11; j++)
105 {
106 Z2i::Point p(i,j);
107 auto dist = (i-power(p)[0])*(i-power(p)[0]) +
108 ( j-power(p)[1])*(j-power(p)[1]) - image(power.projectPoint(power(p)));
109 trace.info()<< dist;
110 }
111 std::cerr<<std::endl;
112 }
113 trace.info()<<std::endl;
114
115 //Medial Axis extraction
117
118 //Reconstruction
119 for(unsigned int i=0; i<11; i++)
120 {
121 for(unsigned int j=0; j<11; j++)
122 {
123 Z2i::Point p(i,j);
124 if (rdma.domain().isInside(p) )
125 trace.info()<< rdma(p);
126 else
127 trace.info()<< " - ";
128
129 }
130 std::cerr<<std::endl;
131 }
132 trace.info()<<std::endl;
133
134
135 ++nbok;
136 nb++;
137 trace.info() << "(" << nbok << "/" << nb << ") "
138 << "true == true" << std::endl;
139 trace.endBlock();
140
141 bool isEqual = true;
142 for ( auto const & pt : domain )
143 {
144 const Image::Value a = image.domain().isInside(pt) ? image(pt) : 0;
145 const Image::Value b = rdma.domain().isInside(pt) ? rdma(pt) : 0;
146 if ( a != b )
147 {
148 isEqual = false;
149 break;
150 }
151 }
152
153 trace.info() << "Equality ? " << isEqual << std::endl;
154
155 return nbok == nb;
156}
157
159// Standard services - public :
160
161int main( int argc, char** argv )
162{
163 trace.beginBlock ( "Testing class ReducedMedialAxis" );
164 trace.info() << "Args:";
165 for ( int i = 0; i < argc; ++i )
166 trace.info() << " " << argv[ i ];
167 trace.info() << endl;
168
169 bool res =
171 && testReducedMedialAxis( {{ true, false }} )
172 && testReducedMedialAxis( {{ false, true }} )
173 && testReducedMedialAxis( {{ true, true }} )
174 ; // && ... other tests
175
176 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
177 trace.endBlock();
178 return res ? 0 : 1;
179}
180// //
Aim: A container class for storing sets of digital points within some given domain.
Aim: Constructs a domain limited to the given digital set.
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:70
Aim: Implementation of the linear in time Power map construction.
Definition: PowerMap.h:111
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
T power(const T &aVal, const unsigned int exponent)
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Aim: Implementation of the separable medial axis extraction.
int main()
Definition: testBits.cpp:56
bool isEqual(Container1 &c1, Container2 &c2)
Domain domain
bool testReducedMedialAxis(std::array< bool, 2 > const &aPeriodicity={{ false, false }})