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 //
48 template<typename TPoint>
51 DGtal::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);
60 template<typename TPoint>
63 DGtal::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);
109 template<typename TPoint>
111 std::vector< std::vector<TPoint> >
112 DGtal::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);
119 template<typename TPoint>
121 std::vector< std::vector<TPoint> >
122 DGtal::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() ){
136 std::operator>>(in_str, valStr);
137 std::istringstream word_str( valStr );
138 word_str >> p[index];
139 isOK = isOK && !word_str.fail();
141 if(isOK && index % (TPoint::dimension)==0){
142 aContour.push_back(p);
146 vectResult.push_back(aContour);
161 template<typename TPoint>
162 template<typename TInteger>
164 std::vector< DGtal::FreemanChain< TInteger> >
165 DGtal::PointListReader<TPoint>::getFreemanChainsFromFile (const std::string &filename){
166 std::vector< FreemanChain< TInteger> > vectResult;
167 std::ifstream infile;
168 infile.open (filename.c_str(), std::ifstream::in);
170 getline(infile, str );
171 while ( infile.good() ){
172 if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
173 std::istringstream in_str( str );
176 bool isOK = (in_str.operator>> ( x0 ) ) &&
177 (in_str.operator>> (y0) ) &&
178 std::operator>> (in_str, fcChain);
179 FreemanChain< TInteger> fc(fcChain, x0, y0);
182 vectResult.push_back(fc);
186 std::cerr << "Ignoring entry invalid FreemanChain" << std::endl;
189 getline(infile, str );
194 ///////////////////////////////////////////////////////////////////////////////