32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/images/ImageSelector.h"
35 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
36 #include "DGtal/geometry/volumes/distance/ReverseDistanceTransformation.h"
37 #include "DGtal/io/colormaps/HueShadeColorMap.h"
38 #include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
39 #include "DGtal/io/boards/Board2D.h"
40 #include "DGtal/images/imagesSetsUtils/SimpleThresholdForegroundPredicate.h"
45 using namespace DGtal;
49 template<
typename Image>
50 void randomSeeds(
Image &input,
const unsigned int nb,
const int value)
57 for (
unsigned int k = 0 ; k < nb; k++)
59 for (
unsigned int dim = 0; dim < Image::dimension; dim++)
61 p[dim] = rand() % (ext[dim]) + low[dim];
78 unsigned int nbok = 0;
91 for (
unsigned k = 0; k < 49; k++ )
95 image.setValue ( a, 128 );
101 Predicate aPredicate(image,0);
106 ImageDT result = dt.compute ( );
110 ImageDT::ConstIterator it = result.begin();
111 for (
unsigned int y = 2; y < 16; y++)
113 for (
unsigned int x = 2; x < 16; x++)
115 std::cout << (*it) <<
" ";
118 std::cout << std::endl;
132 ImageRDT::ConstIterator it2 = reconstruction.begin();
133 for (
unsigned int y = 2; y < 16; y++)
135 for (
unsigned int x = 2; x < 16; x++)
137 std::cout << (int)(*it2) <<
" ";
140 std::cout << std::endl;
145 ImageRDT::ConstIterator itrec = reconstruction.begin(), itend = reconstruction.end();
147 for( ; itrec != itend; ++itrec,++itinit)
149 ok = ok & ((*itinit) == 0);
153 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
154 <<
"true == true" << std::endl;
160 bool testReverseDTL1()
162 unsigned int nbok = 0;
175 for (
unsigned k = 0; k < 49; k++ )
177 a[0] = ( k / 7 ) + 5;
178 a[1] = ( k % 7 ) + 5;
179 image.setValue ( a, 128 );
185 Predicate aPredicate(image,0);
190 ImageDT result = dt.compute ( );
195 ImageDT::ConstIterator it = result.begin();
196 for (
unsigned int y = 2; y < 16; y++)
198 for (
unsigned int x = 2; x < 16; x++)
200 std::cout << (int)(*it) <<
" ";
203 std::cout << std::endl;
213 ImageRDT::ConstIterator it2 = reconstruction.begin();
214 for (
unsigned int y = 2; y < 16; y++)
216 for (
unsigned int x = 2; x < 16; x++)
218 std::cout << (int)(*it2) <<
" ";
221 std::cout << std::endl;
226 ImageRDT::ConstIterator itrec = reconstruction.begin(), itend = reconstruction.end();
228 for( ; itrec != itend; ++itrec,++itinit)
230 ok = ok & ((*itinit) == 0);
234 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
235 <<
"true == true" << std::endl;
240 bool testReverseDTL1simple()
242 unsigned int nbok = 0;
265 ImageDT::ConstIterator it = result.begin();
266 for (
unsigned int y = 2; y < 16; y++)
268 for (
unsigned int x = 2; x < 16; x++)
270 std::cout << (int)(*it) <<
" ";
273 std::cout << std::endl;
283 ImageRDT::ConstIterator it2 = reconstruction.begin();
284 for (
unsigned int y = 2; y < 16; y++)
286 for (
unsigned int x = 2; x < 16; x++)
288 std::cout << (int)(*it2) <<
" ";
291 std::cout << std::endl;
295 nbok +=
true ? 1 : 0;
297 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
298 <<
"true == true" << std::endl;
308 bool testReverseDTSet()
310 unsigned int nbok = 0;
323 for (
unsigned k = 0; k < 49; k++ )
325 a[0] = ( k / 7 ) + 5;
326 a[1] = ( k % 7 ) + 5;
327 image.setValue ( a, 128 );
333 Predicate aPredicate(image,0);
339 ImageDT result = dt.compute ( );
344 ImageDT::ConstIterator it = result.begin();
345 for (
unsigned int y = 2; y < 16; y++)
347 for (
unsigned int x = 2; x < 16; x++)
349 std::cout << (*it) <<
" ";
352 std::cout << std::endl;
361 Set reconstruction(result.domain());
365 board << reconstruction;
366 board.
saveSVG (
"image-REDTtestSet.svg" );
369 for(Set::ConstIterator it2 = reconstruction.begin(),
370 itend2 = reconstruction.end();
380 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
381 <<
"true == true" << std::endl;
392 int main(
int argc,
char** argv )
396 for (
int i = 0; i < argc; ++i )
400 bool res = testReverseDT() && testReverseDTSet()
401 && testReverseDTL1() && testReverseDTL1simple();
403 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;