32 #include "DGtal/base/Common.h"
33 #include "DGtal/kernel/PointVector.h"
34 #include "DGtal/topology/KhalimskySpaceND.h"
35 #include "DGtal/geometry/curves/GridCurve.h"
37 #include "DGtal/geometry/curves/CBidirectionalSegmentComputer.h"
39 #include "DGtal/geometry/curves/GeometricalDSS.h"
41 #include "DGtal/geometry/curves/GreedySegmentation.h"
42 #include "DGtal/geometry/curves/SaturatedSegmentation.h"
44 #include "DGtal/io/boards/Board2D.h"
45 #include "DGtal/io/boards/CDrawableWithBoard2D.h"
47 #include "ConfigTest.h"
52 using namespace DGtal;
60 template <
typename TCurve>
61 bool testGeometricalDSS(
const TCurve& curve)
64 typedef typename TCurve::IncidentPointsRange
Range;
65 typedef typename Range::ConstIterator ConstIterator;
66 typedef typename Range::ConstReverseIterator ConstReverseIterator;
68 unsigned int nbok = 0;
73 Range r = curve.getIncidentPointsRange();
85 trace.
info() << s4.isValid() << s4 << endl;
86 trace.
info() << s5.isValid() << s5 << endl;
89 &&(s2.
isValid())&&(s4.isValid())&&(s5.isValid())
90 &&(s2 == s4)&&(s3 != s5)&&(s1 == s3)&&(s2 != s5);
92 nbok += myFlag ? 1 : 0;
99 Range r = curve.getIncidentPointsRange();
103 trace.
info() <<
"forward extension " << endl;
104 ConstIterator itBegin (r.
begin());
105 ConstIterator itEnd (r.
end());
111 trace.
info() << a <<
" " << b <<
" " << c << endl;
113 t.
init( (itBegin + (itEnd - itBegin)/2) );
118 trace.
info() <<
"backward extension " << endl;
120 ConstReverseIterator ritBegin (t.
end());
121 ConstReverseIterator ritEnd (r.rend());
127 trace.
info() << ap <<
" " << bp <<
" " << cp << endl;
130 rt.
init( (ritBegin + (ritEnd - ritBegin)/2) );
135 trace.
info() <<
"comparison... " << endl;
136 bool myFlag = ( (s == t)&&(rs == rt) )
146 nbok += myFlag ? 1 : 0;
151 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
158 template <
typename TCurve>
159 bool drawingTestGeometricalDSS(
const TCurve& curve)
162 typedef typename TCurve::IncidentPointsRange Range;
163 typedef typename Range::ConstIterator ConstIterator;
165 Range r = curve.getIncidentPointsRange();
168 ConstIterator itEnd (r.
end());
177 board.
saveEPS(
"GeometricalDSSdrawingTest.eps");
181 void testGeometricalDSSConceptChecking()
184 typedef std::vector<Pair>::const_iterator ConstIterator;
190 template <
typename TCurve>
191 bool testSegmentation(
const TCurve& curve)
194 typedef typename TCurve::IncidentPointsRange Range;
195 Range r = curve.getIncidentPointsRange();
197 typedef typename Range::ConstIterator ConstIterator;
200 unsigned int nbok = 0;
207 Segmentation theSegmentation( r.
begin(), r.
end(), SegmentComputer() );
212 typename Segmentation::SegmentComputerIterator it = theSegmentation.
begin();
213 typename Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
215 unsigned int suml = 0;
216 for ( ; it != itEnd; ++it, ++n) {
218 for (ConstIterator i = it->begin(); i != it->end(); ++i)
222 board.saveEPS(
"GeometricalDSSGreedySegmentationTest.eps", Board2D::BoundingBox, 5000 );
224 trace.
info() << r.size() <<
";" << n <<
";" << suml << endl;
226 nbok += ((r.size()==85)&&(n==10)&&(suml==94)) ? 1 : 0;
234 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer() );
239 typename Segmentation::SegmentComputerIterator it = theSegmentation.begin();
240 typename Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
242 unsigned int suml = 0;
243 for ( ; it != itEnd; ++it, ++n) {
245 for (ConstIterator i = it->begin(); i != it->end(); ++i)
249 board.
saveEPS(
"GeometricalDSSSaturatedSegmentationTest.eps", Board2D::BoundingBox, 5000 );
251 trace.
info() << r.size() <<
";" << n <<
";" << suml << endl;
253 nbok += ((r.size()==85)&&(n==25)&&(suml==255)) ? 1 : 0;
259 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
265 int main(
int argc,
char** argv )
269 for (
int i = 0; i < argc; ++i )
276 testGeometricalDSSConceptChecking();
280 std::string filename = testPath +
"samples/DSS.dat";
282 instream.open (filename.c_str(), ifstream::in);
288 res = testGeometricalDSS(c)
289 && drawingTestGeometricalDSS(c);
293 std::string filename = testPath +
"samples/sinus2D4.dat";
295 instream.open (filename.c_str(), ifstream::in);
301 res = res && testSegmentation(c);
304 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;