DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testFP.cpp
1 
30 
31 #include <iostream>
32 #include <fstream>
33 
34 #include "DGtal/base/Common.h"
35 #include "DGtal/kernel/SpaceND.h"
36 #include "DGtal/kernel/domains/HyperRectDomain.h"
37 #include "DGtal/geometry/curves/FreemanChain.h"
38 #include "DGtal/geometry/curves/FP.h"
39 #include "DGtal/io/boards/Board2D.h"
40 
41 #include "ConfigTest.h"
43 
44 using namespace std;
45 using namespace DGtal;
46 using namespace LibBoard;
47 
49 // Functions for testing class FP.
51 
52 template<typename Coordinate>
53 void
54 drawVectorOfPointsAsPolygon( const vector<PointVector<2,Coordinate> >& v, Board2D & aBoard)
55 {
56  //polyline to draw
57  vector<LibBoard::Point> polyline;
58 
59  typename vector<PointVector<2,Coordinate> >::const_iterator i = v.begin();
60  for ( ;i != v.end();++i) {
62  double xp = (double) p[0];
63  double yp = (double) p[1];
64  polyline.push_back(LibBoard::Point(xp,yp));
65  }
66 
67  aBoard.drawPolyline(polyline);
68 
69 }
70 
75 bool testDrawingFP()
76 {
77 
78  typedef int Coordinate;
81  typedef PointVector<2,double> RealPoint;
84 
85  std::string filename = testPath + "samples/france.fc";
86  std::cout << filename << std::endl;
87 
88  std::fstream fst;
89  fst.open (filename.c_str(), std::ios::in);
90  Contour theContour(fst);
91 
92  trace.beginBlock ( "FP of a 4-connected digital curve..." );
93 
94  FP theFP( theContour.begin(),theContour.end(),true );
95  //trace.info() << theFP << std::endl;
96 
97  // Draw the FP
98  Board2D aBoard;
99  aBoard << SetMode( "PointVector", "Grid" ) << theContour;
100  aBoard << theFP;
101  aBoard.saveEPS("FP.eps");
102 
103  //accessors:
104  Board2D newBoard;
105  newBoard << SetMode( "PointVector", "Grid" ) << theContour;
106 
107  trace.info() << "FP" << endl;
108  vector<Point> v( theFP.size() );
109  theFP.copyFP( v.begin() );
110 // copy( v.begin(),v.end(),ostream_iterator<Point>(cout, "\n") );
111  drawVectorOfPointsAsPolygon<int>(v, newBoard);
112 
113  trace.info() << "MLP" << endl;
114  vector<RealPoint> v2( theFP.size() );
115  theFP.copyMLP( v2.begin() );
116 // copy( v2.begin(),v2.end(),ostream_iterator<RealPoint>(cout, "\n") );
117  drawVectorOfPointsAsPolygon<double>(v2, newBoard);
118 
119  newBoard.saveEPS("FP_MLP.eps");
120 
121  trace.endBlock();
122 
123  return true;
124 }
125 
127 // Standard services - public :
128 
129 int main( int argc, char** argv )
130 {
131  trace.beginBlock ( "Testing class FP" );
132  trace.info() << "Args:";
133  for ( int i = 0; i < argc; ++i )
134  trace.info() << " " << argv[ i ];
135  trace.info() << endl;
136 
137  bool res = testDrawingFP(); // && ... other tests
138  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
139  trace.endBlock();
140  return res ? 0 : 1;
141 }
142 // //