2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file PointListReader.ih
19 * @author Bertrand Kerautret (\c kerautre@loria.fr )
20 * LORIA (CNRS, UMR 7503), University of Nancy, France
24 * Implementation of inline methods defined in PointListReader.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
33//////////////////////////////////////////////////////////////////////////////
38//////////////////////////////////////////////////////////////////////////////
42///////////////////////////////////////////////////////////////////////////////
43// Implementation of inline methods //
48template<typename TPoint>
51DGtal::PointListReader<TPoint>::getPointsFromFile (const std::string &filename, std::vector<unsigned int> aVectPosition)
54 infile.open (filename.c_str(), std::ifstream::in);
55 return DGtal::PointListReader<TPoint>::getPointsFromInputStream(infile, aVectPosition);
60template<typename TPoint>
63DGtal::PointListReader<TPoint>::getPointsFromInputStream (std::istream &in, std::vector<unsigned int> aVectPosition)
65 if(aVectPosition.size()==0){
66 for(unsigned int i=0; i<TPoint::dimension; i++){
67 aVectPosition.push_back(i);
70 std::vector<TPoint> vectResult;
74 if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
75 std::istringstream in_str( str );
78 unsigned int nbFound=0;
80 while ( !in_str.fail()&& (nbFound<TPoint::dimension)){
81 std::operator>>(in_str,val);
83 std::istringstream valFromStr( val );
84 typename TPoint::Component valConverted;
85 valFromStr >> valConverted;
86 if(!valFromStr.fail()){
87 for(unsigned int j=0; j< TPoint::dimension; j++){
88 if (idx == aVectPosition.at(j) ){
97 if(nbFound==TPoint::dimension){
98 vectResult.push_back(p);
109template<typename TPoint>
111std::vector< std::vector<TPoint> >
112DGtal::PointListReader<TPoint>::getPolygonsFromFile(const std::string &filename){
113 std::ifstream infile;
114 infile.open (filename.c_str(), std::ifstream::in);
115 return DGtal::PointListReader<TPoint>::getPolygonsFromInputStream(infile);
119template<typename TPoint>
121std::vector< std::vector<TPoint> >
122DGtal::PointListReader<TPoint>::getPolygonsFromInputStream(std::istream & in){
123 std::vector< std::vector< TPoint > > vectResult;
127 if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
128 std::vector <TPoint> aContour;
129 std::istringstream in_str( str );
130 std::string valStr="";
133 unsigned int index =0;
134 while ( in_str.good() ){
135 std::operator>>(in_str, valStr);
136 std::istringstream word_str( valStr );
137 word_str >> p[index];
138 isOK = isOK && !word_str.fail();
140 if(isOK && index % (TPoint::dimension)==0){
141 aContour.push_back(p);
145 vectResult.push_back(aContour);
160template<typename TPoint>
161template<typename TInteger>
163std::vector< DGtal::FreemanChain< TInteger> >
164DGtal::PointListReader<TPoint>::getFreemanChainsFromFile (const std::string &filename){
165 std::vector< FreemanChain< TInteger> > vectResult;
166 std::ifstream infile;
167 infile.open (filename.c_str(), std::ifstream::in);
169 getline(infile, str );
170 while ( infile.good() ){
171 if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
172 std::istringstream in_str( str );
175 bool isOK = (in_str.operator>> ( x0 ) ) &&
176 (in_str.operator>> (y0) ) &&
177 std::operator>> (in_str, fcChain);
178 FreemanChain< TInteger> fc(fcChain, x0, y0);
181 vectResult.push_back(fc);
185 std::cerr << "Ignoring entry invalid FreemanChain" << std::endl;
188 getline(infile, str );
193///////////////////////////////////////////////////////////////////////////////