DGtal 1.3.0
Loading...
Searching...
No Matches
testPointListReader.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/io/readers/PointListReader.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/geometry/curves/FreemanChain.h"
36
37#include "ConfigTest.h"
38
40
41using namespace std;
42using namespace DGtal;
43
44
46// Functions for testing class PointListReader.
48
53{
54 unsigned int nbok = 0;
55 unsigned int nb = 0;
56
57 trace.beginBlock ( "Testing reading point list ..." );
58 std::string filename = testPath + "samples/pointList1.pl";
59 std::vector<unsigned int> vectPos;
60 vectPos.push_back(1);
61 vectPos.push_back(2);
62 vector<Z2i::Point> vectPoints = PointListReader<Z2i::Point>::getPointsFromFile(filename,
63 vectPos);
64 for(unsigned int k=0;k < vectPoints.size(); k++){
65 trace.info() << " pt: "<< vectPoints.at(k)<< endl;
66 }
67 nbok += (vectPoints.size()==4) ? 1 : 0;
68 nb++;
69 trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
71
72 trace.beginBlock ( "Testing reading freemanchain ..." );
73 std::string filenameFC = testPath + "samples/freemanChainSample.fc";
74 std::vector< FreemanChain< int > > vectFC = PointListReader< Z2i::Point>:: getFreemanChainsFromFile<int> (filenameFC);
75 for(unsigned int i=0; i< vectFC.size(); i++){
76 FreemanChain<int> fc = vectFC.at(i);
77 trace.info() << "Freeman chain " << i << ": " << fc.x0 << " " << fc.y0 << " " << fc.chain << endl;
78 }
79 nbok += (vectFC.size()==5) ? 1 : 0;
80 nb++;
82
83 trace.beginBlock ( "Testing reading 3D polygons (one each line)..." );
84 std::string filenamePoly = testPath + "samples/polygons.dat";
85 std::vector< std::vector< Z3i::Point > > vectPolygons = PointListReader< Z3i::Point >::getPolygonsFromFile(filenamePoly);
86 for(unsigned int i=0; i< vectPolygons.size(); i++){
87 std::vector< Z3i::Point > aPolygon = vectPolygons.at(i);
88 trace.info() << "Polygon " << i << ": " ;
89 for(unsigned int j =0; j <aPolygon.size(); j++){
90 trace.info()<< "Point :" << aPolygon.at(j);
91 }
92 trace.info()<< std::endl;
93 }
94 nbok += (vectPolygons.at(0).size()==2 && vectPolygons.at(1).size()==2 && vectPolygons.at(0).at(0)==Z3i::Point(1,2,3)
95 && vectPolygons.at(0).at(1)==Z3i::Point(4,5,6) && vectPolygons.at(1).at(0)==Z3i::Point(0,0,10)
96 && vectPolygons.at(1).at(1)==Z3i::Point(0,5,5)) ? 1 : 0;
97 nb++;
99
100 trace.beginBlock ( "Testing reading 2D polygons (one each line)..." );
101
102 std::vector< std::vector< Z2i::Point > > vectPolygons2D = PointListReader< Z2i::Point >::getPolygonsFromFile(filenamePoly);
103 for(unsigned int i=0; i< vectPolygons2D.size(); i++){
104 std::vector< Z2i::Point > aPolygon2D = vectPolygons2D.at(i);
105 trace.info() << "Polygon " << i << ": " ;
106 for(unsigned int j =0; j <aPolygon2D.size(); j++){
107 trace.info()<< "Point :" << aPolygon2D.at(j);
108 }
109 trace.info()<< std::endl;
110 }
111 nbok += (vectPolygons2D.at(0).size()==3 && vectPolygons2D.at(1).size()==3 && vectPolygons2D.at(0).at(0)==Z2i::Point(1,2)
112 && vectPolygons2D.at(0).at(1)==Z2i::Point(3,4) && vectPolygons2D.at(0).at(2)==Z2i::Point(5,6)
113 && vectPolygons2D.at(1).at(0)==Z2i::Point(0,0) && vectPolygons2D.at(1).at(1)==Z2i::Point(10, 0)
114 && vectPolygons2D.at(1).at(2)==Z2i::Point(5,5)) ? 1 : 0;
115
116 nb++;
117 trace.endBlock();
118
119 return nbok == nb;
120}
121
123// Standard services - public :
124
125int main( int argc, char** argv )
126{
127 trace.beginBlock ( "Testing class PointListReader" );
128 trace.info() << "Args:";
129 for ( int i = 0; i < argc; ++i )
130 trace.info() << " " << argv[ i ];
131 trace.info() << endl;
132
133
134 bool res = testPointListReader(); // && ... other tests
135 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
136 trace.endBlock();
137 return res ? 0 : 1;
138}
139// //
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Space::Point Point
Definition: StdDefs.h:95
Space::Point Point
Definition: StdDefs.h:168
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Aim: Implements method to read a set of points represented in each line of a file.
static std::vector< TPoint > getPointsFromFile(const std::string &filename, std::vector< unsigned int > aVectPosition=std::vector< unsigned int >())
static std::vector< std::vector< TPoint > > getPolygonsFromFile(const std::string &filename)
int main()
Definition: testBits.cpp:56
bool testPointListReader()