DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testPointListReader.cpp
1 
30 
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 
41 using namespace std;
42 using namespace DGtal;
43 
44 
46 // Functions for testing class PointListReader.
48 
52 bool testPointListReader()
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
57  trace.beginBlock ( "Testing reading point list ..." );
58 
59  std::string filename = testPath + "samples/pointList1.pl";
60  std::vector<unsigned int> vectPos;
61  vectPos.push_back(1);
62  vectPos.push_back(2);
63  vector<Z2i::Point> vectPoints = PointListReader<Z2i::Point>::getPointsFromFile(filename,
64  vectPos);
65  for(unsigned int k=0;k < vectPoints.size(); k++){
66  trace.info() << " pt: "<< vectPoints.at(k)<< endl;
67  }
68  nbok += (vectPoints.size()==4) ? 1 : 0;
69  nb++;
70  trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
71  trace.endBlock();
72  trace.beginBlock ( "Testing reading point list ..." );
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++;
81  trace.endBlock();
82  return nbok == nb;
83 }
84 
86 // Standard services - public :
87 
88 int main( int argc, char** argv )
89 {
90  trace.beginBlock ( "Testing class PointListReader" );
91  trace.info() << "Args:";
92  for ( int i = 0; i < argc; ++i )
93  trace.info() << " " << argv[ i ];
94  trace.info() << endl;
95 
96 
97  bool res = testPointListReader(); // && ... other tests
98  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
99  trace.endBlock();
100  return res ? 0 : 1;
101 }
102 // //