DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
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"

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 125 of file testPointListReader.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
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 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}
Space::Point Point
Definition: StdDefs.h:95
Space::Point Point
Definition: StdDefs.h:168
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)

References DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::chain, DGtal::Trace::endBlock(), 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().