39 #include "DGtal/base/Common.h"
40 #include "DGtal/helpers/StdDefs.h"
41 #include "DGtal/io/boards/Board2D.h"
42 #include "DGtal/geometry/curves/CombinatorialDSS.h"
43 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
44 #include "ConfigTest.h"
45 #include "DGtal/geometry/curves/CBidirectionalSegmentComputer.h"
46 #include "DGtal/geometry/curves/GreedySegmentation.h"
51 using namespace DGtal;
67 bool testCombinatorialDSS()
69 typedef Contour::ConstIterator ConstIterator;
70 typedef string::const_iterator codeIterator;
79 std::string filename = testPath +
"samples/france.fc";
81 fst.open (filename.c_str(), std::ios::in);
85 for ( string::const_iterator it = theContour.chain.begin(); it != theContour.chain.end(); ++it )
90 list<char>::iterator it = l.begin();
92 CombinatorialDSS_list C1;
93 C1.init( it, theContour.firstPoint() );
95 CombinatorialDSS_list C2;
96 C2.init( C1.begin() );
98 CombinatorialDSS_string C3;
99 C3.init( theContour );
101 CombinatorialDSS_string C4;
102 C4.init( theContour.begin() );
105 while ( C3.end() != theContour.chain.end() )
107 bool b1 = C1.extendForward();
108 bool b2 = C2.extendForward();
109 bool b3 = C3.extendForward();
110 bool b4 = C4.extendForward();
111 if ( b1 && b2 && b3 && b4 )
114 else if ( !b1 && !b2 && !b3 && !b4 )
124 cout << b1 <<
" " << b2 <<
" " << b3 <<
" " << b4 << endl;
133 return (nbRetract == 3485) ;
141 bool CompareToArithmetical()
143 typedef string::const_iterator codeIterator;
149 std::string filename = testPath +
"samples/manche.fc";
151 fst.open (filename.c_str(), std::ios::in);
153 Contour::ConstIterator it = theContour.begin();
159 while ( C.end() != theContour.chain.end() )
161 bool a = A.extendForward();
162 bool c = C.extendForward();
166 cout <<
"Extension test error\n";
175 if ( ( C.getFirstPoint() != A.getFirstPoint() ) || ( C.getLastPoint() != A.getLastPoint() ) )
178 cout <<
"Equality test error\n";
182 if ( ( C.getA() != A.getA() ) || ( C.getB() != A.getB() ) ||
183 ( C.getMu() != A.getMu() ) || ( C.getOmega() != A.getOmega() ) ||
184 ( C.getUf() != A.getUf() ) || ( C.getUl() != A.getUl() ) ||
185 ( C.getLf() != A.getLf() ) || ( C.getLl() != A.getLl() )
188 cout <<
"Arithmetic parameters error\n";
191 cout <<
"getA() " << C.getA() <<
" --- " << A.getA() <<
"\n";
192 cout <<
"getB() " << C.getB() <<
" --- " << A.getB() <<
"\n";
193 cout <<
"getMu() " << C.getMu() <<
" --- " << A.getMu() <<
"\n";
194 cout <<
"getOmega()" << C.getOmega() <<
" --- " << A.getOmega() <<
"\n";
195 cout <<
"getUf() " << C.getUf() <<
" --- " << A.getUf() <<
"\n";
196 cout <<
"getUl() " << C.getUl() <<
" --- " << A.getUl() <<
"\n";
197 cout <<
"getLf() " << C.getLf() <<
" --- " << A.getLf() <<
"\n";
198 cout <<
"getLl() " << C.getLl() <<
" --- " << A.getLl() << endl;
209 bool testInGreedySegmentation( )
215 std::string filename = testPath +
"samples/BigBall.fc";
217 fst.open (filename.c_str(), std::ios::in);
221 combinSegmentation combin_dec( theContour.chain.begin(), theContour.chain.end(), combinDSS() );
222 vector<combinDSS> theCombinDSS;
223 for ( combinSegmentation::SegmentComputerIterator i = combin_dec.begin();
224 i != combin_dec.end(); ++i )
227 theCombinDSS.push_back( c );
229 bool ok = ( theCombinDSS.size() == 1593 );
245 bool showGreedySegmantation()
253 std::stringstream ss(stringstream::in | stringstream::out);
254 ss <<
"31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
257 Decomposition theDecomposition( theContour.chain.begin(), theContour.chain.end(), combinDSS() );
262 aBoard <<
SetMode( domain.className(),
"Grid" )
264 <<
SetMode(
"PointVector",
"Grid" )
267 aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" );
268 string className =
"ArithmeticalDSS/BoundingBox";
272 for ( Decomposition::SegmentComputerIterator i = theDecomposition.begin();
273 i != theDecomposition.end(); ++i )
275 combinDSS segment(*i);
277 segment.setPosition( p );
280 p = *( --( --( segment.pointEnd() )));
283 arithDSS toShow( segment.pointBegin() );
284 while( toShow.end() != segment.pointEnd() )
286 toShow.extendForward();
291 aBoard.
saveSVG(
"testCombinDSS-greedy.svg");
299 int main(
int argc,
char** argv )
303 for (
int i = 0; i < argc; ++i )
307 bool res = testCombinatorialDSS()
308 && CompareToArithmetical()
309 && testInGreedySegmentation()
310 && showGreedySegmantation();
312 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;