44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/Exceptions.h"
46 #include "DGtal/io/boards/Board2D.h"
47 #include "DGtal/io/Color.h"
49 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
50 #include "DGtal/geometry/curves/FreemanChain.h"
51 #include "DGtal/geometry/curves/MaximalSegments.h"
54 #include "ConfigTest.h"
57 using namespace DGtal;
58 using namespace DGtal::deprecated;
60 using namespace LibBoard;
73 typedef int Coordinate;
81 std::string filename = testPath +
"samples/france.fc";
82 std::cout << filename << std::endl;
85 fst.open (filename.c_str(), std::ios::in);
86 ContourType theContour(fst);
90 PrimitiveType primitive;
91 DecompositionType theDecomposition(theContour.begin(), theContour.end(), primitive,
false);
95 aBoard.
setUnit(Board::UCentimeter);
97 aBoard <<
SetMode(
"PointVector",
"Grid")
101 unsigned int compteur = 0;
102 DecompositionType::SegmentIterator i = theDecomposition.begin();
103 for ( ; i != theDecomposition.end(); ++i) {
106 PrimitiveType segment(*i);
108 aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" )
113 aBoard.saveEPS(
"segmentationDSS4.eps");
115 trace.
info() <<
"# segments" << compteur << std::endl;
121 bool testDisconnectedCurve()
123 typedef int Coordinate;
129 std::vector<Point> curve;
130 curve.push_back(Point(0,0));
131 curve.push_back(Point(1,0));
132 curve.push_back(Point(1,1));
133 curve.push_back(Point(2,1));
134 curve.push_back(Point(3,2));
135 curve.push_back(Point(4,2));
136 curve.push_back(Point(5,2));
137 curve.push_back(Point(6,2));
138 curve.push_back(Point(6,3));
139 curve.push_back(Point(6,4));
140 curve.push_back(Point(7,4));
141 curve.push_back(Point(8,4));
142 curve.push_back(Point(9,3));
143 curve.push_back(Point(9,2));
144 curve.push_back(Point(10,2));
145 curve.push_back(Point(11,2));
149 PrimitiveType primitive;
150 DecompositionType theDecomposition(curve.begin(), curve.end(), primitive,
false);
154 aBoard.
setUnit(Board::UCentimeter);
155 aBoard <<
SetMode(
"PointVector",
"Grid");
156 for (std::vector<Point>::iterator it = curve.begin(); it != curve.end(); ++it) {
162 unsigned int compteur = 0;
163 DecompositionType::SegmentIterator i = theDecomposition.begin();
164 for ( ; i != theDecomposition.end(); ++i) {
167 trace.
info() <<
"Segment " << compteur << std::endl;
168 PrimitiveType segment(*i);
170 aBoard <<
SetMode(
"ArithmeticalDSS",
"Points" )
172 aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" )
176 aBoard.saveSVG(
"specialCase.svg");
180 return (compteur==5);
188 bool testClosedCurves(
const bool& aFlag)
198 std::stringstream ss(stringstream::in | stringstream::out);
199 ss <<
"31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
202 Contour4 theContour( ss );
206 Decomposition4 theDecomposition( theContour.begin(),theContour.end(),dss,aFlag );
209 aBoard <<
SetMode(
"PointVector",
"Grid" )
212 aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" );
213 string className =
"ArithmeticalDSS/BoundingBox";
214 for ( Decomposition4::SegmentIterator i = theDecomposition.begin();
215 i != theDecomposition.end(); ++i )
219 cout << segment << endl;
225 std::string filename =
"testClosedCurves";
226 if (aFlag) filename +=
"ProcessedAsClosed";
227 else filename +=
"ProcessedAsOpen";
229 aBoard.saveSVG(filename.c_str());
243 typedef int Coordinate;
245 typedef ArithmeticalDSS<std::vector<Point>::iterator,Coordinate,4> PrimitiveType;
249 std::vector<Point> curve;
253 PrimitiveType primitive;
254 DecompositionType theDecomposition(curve.begin(), curve.end(), primitive,
false);
256 for ( DecompositionType::SegmentIterator i = theDecomposition.begin();
257 i != theDecomposition.end(); ++i )
262 }
catch (std::exception e) {
275 typedef int Coordinate;
277 typedef ArithmeticalDSS<std::vector<Point>::iterator,Coordinate,4> PrimitiveType;
281 std::vector<Point> curve;
282 curve.push_back(Point(5,5));
284 PrimitiveType primitive;
286 DecompositionType theDecomposition(curve.begin(), curve.end(), primitive,
false);
289 aBoard << curve.at(0);
291 aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" );
292 for ( DecompositionType::SegmentIterator i = theDecomposition.begin();
293 i != theDecomposition.end(); ++i )
295 PrimitiveType primitive2(*i);
297 aBoard << primitive2;
300 aBoard.saveSVG(
"testOnePoint.svg");
304 }
catch (std::exception e) {
314 bool testTwoEndIterators()
316 typedef int Coordinate;
318 typedef ArithmeticalDSS<std::vector<Point>::iterator,Coordinate,4> PrimitiveType;
321 std::vector<Point> curve;
322 curve.push_back(Point(5,5));
327 PrimitiveType primitive;
328 DecompositionType theDecomposition(curve.begin(), curve.end(), primitive,
false);
330 for ( DecompositionType::SegmentIterator i = theDecomposition.begin();
331 i != theDecomposition.end(); ++i )
337 }
catch (std::exception e) {
352 typedef int Coordinate;
354 typedef ArithmeticalDSS<std::vector<Point>::iterator,Coordinate,8> PrimitiveType;
357 std::vector<Point> curve;
358 curve.push_back(Point(0,0));
359 curve.push_back(Point(1,1));
360 curve.push_back(Point(2,1));
361 curve.push_back(Point(3,2));
362 curve.push_back(Point(4,2));
363 curve.push_back(Point(5,2));
364 curve.push_back(Point(6,3));
365 curve.push_back(Point(7,3));
369 PrimitiveType primitive;
370 DecompositionType theDecomposition(curve.begin(), curve.end(), primitive,
false);
374 aBoard.
setUnit(Board::UCentimeter);
375 aBoard <<
SetMode(
"PointVector",
"Both");
376 for (std::vector<Point>::iterator it = curve.begin(); it != curve.end(); ++it) {
381 unsigned int compteur = 0;
382 DecompositionType::SegmentIterator i = theDecomposition.begin();
383 for ( ; i != theDecomposition.end(); ++i) {
386 PrimitiveType segment(*i);
388 aBoard <<
SetMode(
"ArithmeticalDSS",
"BoundingBox" )
392 aBoard.saveSVG(
"oneDSS.svg");
396 return (compteur==1);
403 int main(
int argc,
char **argv)
408 for (
int i = 0; i < argc; ++i )
412 bool res = testCover4()
413 && testDisconnectedCurve()
414 && testClosedCurves(
true)
415 && testClosedCurves(
false)
418 && testTwoEndIterators()
421 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;