DGtal 1.4.0
Loading...
Searching...
No Matches
testPointListReader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/PointListReader.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "ConfigTest.h"
Include dependency graph for testPointListReader.cpp:

Go to the source code of this file.

Functions

bool testPointListReader ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2011/04/01

Functions for testing class PointListReader.

This file is part of the DGtal library.

Definition in file testPointListReader.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 145 of file testPointListReader.cpp.

146{
147 trace.beginBlock ( "Testing class PointListReader" );
148 trace.info() << "Args:";
149 for ( int i = 0; i < argc; ++i )
150 trace.info() << " " << argv[ i ];
151 trace.info() << endl;
152
153
154 bool res = testPointListReader(); // && ... other tests
155 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
156 trace.endBlock();
157 return res ? 0 : 1;
158}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool testPointListReader()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testPointListReader(), and DGtal::trace.

◆ testPointListReader()

bool testPointListReader ( )

Example of a test. To be completed.

Definition at line 52 of file testPointListReader.cpp.

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 trace.beginBlock ( "Testing reading special 1 dimension elements (polygon of 1 dimension point)..." );
95
96 typedef PointVector<1, int> Point1D;
97 std::vector< std::vector< Point1D > > vectPt1D = PointListReader< Point1D >::getPolygonsFromFile(filenamePoly);
98 for(unsigned int i=0; i< vectPt1D.size(); i++){
99 std::vector< Point1D > aPolygon = vectPt1D.at(i);
100 trace.info() << "Polygon " << i << ": " ;
101 for(unsigned int j =0; j <aPolygon.size(); j++){
102 trace.info()<< "Point :" << aPolygon.at(j);
103 }
104 trace.info()<< std::endl;
105 }
106 Point1D p1, p2, p3, p4, p5, p6; p1[0]=1; p2[0]=2; p3[0]=3; p4[0]=4; p5[0]=5; p6[0]=6;
107 Point1D p7, p8, p9, p10, p11, p12; p7[0]=0; p8[0]=0; p9[0]=10; p10[0]=0; p11[0]=5; p12[0]=5;
108
109 nbok += (vectPt1D.at(0).size()==6 && vectPt1D.at(1).size()==6 && vectPt1D.at(0).at(0) == p1 &&
110 vectPt1D.at(0).at(1)==p2 && vectPt1D.at(0).at(2) == p3 && vectPt1D.at(0).at(3) == p4
111 && vectPt1D.at(0).at(4)==p5 && vectPt1D.at(0).at(5)==p6
112 && vectPt1D.at(1).at(0)==p7
113 && vectPt1D.at(1).at(1)==p8 && vectPt1D.at(1).at(2)==p9 && vectPt1D.at(1).at(3)==p10
114 && vectPt1D.at(1).at(4)==p11 && vectPt1D.at(1).at(5)==p12);
115
116
117 nb++;
118 trace.endBlock();
119
120 trace.beginBlock ( "Testing reading 2D polygons (one each line)..." );
121
122 std::vector< std::vector< Z2i::Point > > vectPolygons2D = PointListReader< Z2i::Point >::getPolygonsFromFile(filenamePoly);
123 for(unsigned int i=0; i< vectPolygons2D.size(); i++){
124 std::vector< Z2i::Point > aPolygon2D = vectPolygons2D.at(i);
125 trace.info() << "Polygon " << i << ": " ;
126 for(unsigned int j =0; j <aPolygon2D.size(); j++){
127 trace.info()<< "Point :" << aPolygon2D.at(j);
128 }
129 trace.info()<< std::endl;
130 }
131 nbok += (vectPolygons2D.at(0).size()==3 && vectPolygons2D.at(1).size()==3 && vectPolygons2D.at(0).at(0)==Z2i::Point(1,2)
132 && vectPolygons2D.at(0).at(1)==Z2i::Point(3,4) && vectPolygons2D.at(0).at(2)==Z2i::Point(5,6)
133 && vectPolygons2D.at(1).at(0)==Z2i::Point(0,0) && vectPolygons2D.at(1).at(1)==Z2i::Point(10, 0)
134 && vectPolygons2D.at(1).at(2)==Z2i::Point(5,5)) ? 1 : 0;
135
136 nb++;
137 trace.endBlock();
138
139 return nbok == nb;
140}
Aim: Implements basic operations that will be used in Point and Vector classes.
Space::Point Point
Definition StdDefs.h:95
static std::vector< FreemanChain< TInteger > > getFreemanChainsFromFile(const std::string &filename)
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)

References DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::chain, DGtal::Trace::endBlock(), DGtal::PointListReader< TPoint >::getFreemanChainsFromFile(), DGtal::PointListReader< TPoint >::getPointsFromFile(), DGtal::PointListReader< TPoint >::getPolygonsFromFile(), DGtal::Trace::info(), DGtal::trace, DGtal::FreemanChain< TInteger >::x0, and DGtal::FreemanChain< TInteger >::y0.

Referenced by main().