DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Static Public Member Functions
DGtal::PointListReader< TPoint > Struct Template Reference

#include <PointListReader.h>

Static Public Member Functions

static std::vector< TPoint > getPointsFromInputStream (std::istream &in, std::vector< unsigned int > aVectPosition=std::vector< unsigned int >())
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)
static std::vector
< std::vector< TPoint > > 
getPolygonsFromInputStream (std::istream &in)
template<typename TInteger >
static std::vector
< FreemanChain< TInteger > > 
getFreemanChainsFromFile (const std::string &filename)

Detailed Description

template<typename TPoint>
struct DGtal::PointListReader< TPoint >

Aim: Implements method to read a set of points represented in each line of a file.

Description of class 'PointListReader'

The main method to read a set of points as a simple format where each elements is represented in a single line. Blank line or line beginning with "#" are skipped.

Simple example:

#include "DGtal/helpers/StdDefs.h"
....
string filename= "testFile.dat";
vector<Z2i::Point> vectPoints = PointListReader<Z2i::Point>::getPointsFromFile(filename);

and you can specifying the point position:

vector<unsigned int> vIndice;
vIndice.push_back(1); // select for X coordinate the second position number of the line.
vIndice.push_back(2); // select for Y coordinate the third position number of the line.
vector<Z2i::Point> vectPoints = PointListReader<Z2i::Point>::getPointsFromFile(filename,vectPos);
See also:
testPointListReader.cpp
Examples:
io/digitalSetFromPointList.cpp.

Definition at line 84 of file PointListReader.h.


Member Function Documentation

template<typename TPoint >
template<typename TInteger >
std::vector< FreemanChain< TInteger > > DGtal::PointListReader< TPoint >::getFreemanChainsFromFile ( const std::string &  filename)
inlinestatic

Main method to FreemanChain contours. Each line of the file should represent a FreemanChain

Parameters:
filename
Returns:
the vector containing the set of FreemanChain.

Definition at line 152 of file PointListReader.ih.

{
std::vector< FreemanChain< TInteger> > vectResult;
ifstream infile;
infile.open (filename.c_str(), ifstream::in);
string str;
getline(infile, str );
while ( infile.good() ){
if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
istringstream in_str( str );
int x0, y0;
string fcChain;
bool isOK = (in_str >> x0) && (in_str >> y0) && (in_str >> fcChain);
FreemanChain< TInteger> fc(fcChain, x0, y0);
if(isOK){
vectResult.push_back(fc);
}else{
cerr << "Ignoring entry invalid FreemanChain" << endl;
}
}
getline(infile, str );
}
return vectResult;
}
template<typename TPoint >
std::vector< TPoint > DGtal::PointListReader< TPoint >::getPointsFromFile ( const std::string &  filename,
std::vector< unsigned int >  aVectPosition = std::vector<unsigned int>() 
)
inlinestatic

Main method to import a vector containing a list of points defined in a file where each line defines a point.

Parameters:
filename
aVectPositionused to specify the position of indices of value points (optional: default set to 0,..,dimension)
Returns:
a vector containing the set of points.

Definition at line 50 of file PointListReader.ih.

{
ifstream infile;
infile.open (filename.c_str(), ifstream::in);
}
template<typename TPoint >
std::vector< TPoint > DGtal::PointListReader< TPoint >::getPointsFromInputStream ( std::istream &  in,
std::vector< unsigned int >  aVectPosition = std::vector<unsigned int>() 
)
inlinestatic

Main method to import a vector containing a list of points defined in a file where each line defines a point.

Parameters:
inthe input stream.
aVectPositionused to specify the position of indices of value points (default set to 0,..,dimension).
Returns:
a vector containing the set of points.

Definition at line 62 of file PointListReader.ih.

Referenced by DGtal::GridCurve< TKSpace >::initFromVectorStream().

{
if(aVectPosition.size()==0){
for(unsigned int i=0; i<TPoint::dimension; i++){
aVectPosition.push_back(i);
}
}
vector<TPoint> vectResult;
string str;
getline(in, str );
while ( in.good() ){
if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
istringstream in_str( str );
unsigned int idx = 0;
typename TPoint::Component val;
unsigned int nbFound=0;
TPoint p;
while ( in_str.good()&& (nbFound<TPoint::dimension)){
bool isOK = (in_str >> val);
for(unsigned int j=0; j< TPoint::dimension; j++){
if (isOK && (idx == aVectPosition.at(j)) ){
nbFound++;
p[j]=val;
}
}
++idx;
}
if(nbFound==TPoint::dimension){
vectResult.push_back(p);
}
}
getline(in, str );
}
return vectResult;
}
template<typename TPoint >
std::vector< std::vector< TPoint > > DGtal::PointListReader< TPoint >::getPolygonsFromFile ( const std::string &  filename)
inlinestatic

Import a vector containing all polygons defined on each line of a given file.

Parameters:
filename
Returns:
a vector containing the vector of polygons.

Definition at line 105 of file PointListReader.ih.

{
ifstream infile;
infile.open (filename.c_str(), ifstream::in);
}
template<typename TPoint >
std::vector< std::vector< TPoint > > DGtal::PointListReader< TPoint >::getPolygonsFromInputStream ( std::istream &  in)
inlinestatic

Import a vector containing all polygons defined on each line of a given istream.

Parameters:
inthe input stream.
Returns:
a vector containing the vector of polygons.

Definition at line 115 of file PointListReader.ih.

{
vector< vector< TPoint > > vectResult;
string str;
getline(in, str );
while ( in.good() ){
if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
vector <TPoint> aContour;
istringstream in_str( str );
double x=0.0, y=0.0;
while ( in_str.good()){
bool isOK = (in_str >> x);
isOK = isOK && (in_str >>y);
if(isOK){
TPoint p;
p[0]=x;
p[1]=y;
aContour.push_back(p);
}
}
vectResult.push_back(aContour);
}
getline(in, str );
}
return vectResult;
}

The documentation for this struct was generated from the following files: