DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PointListReader.ih
1 
29 
30 // IMPLEMENTATION of inline methods.
32 
34 #include <cstdlib>
35 #include <sstream>
36 #include <fstream>
38 
39 
40 
42 // Implementation of inline methods //
43 
44 
45 
46 
47 template<typename TPoint>
48 inline
49 std::vector<TPoint>
50 DGtal::PointListReader<TPoint>::getPointsFromFile (const std::string &filename, std::vector<unsigned int> aVectPosition)
51 {
52  ifstream infile;
53  infile.open (filename.c_str(), ifstream::in);
54  return PointListReader<TPoint>::getPointsFromInputStream(infile, aVectPosition);
55 }
56 
57 
58 
59 template<typename TPoint>
60 inline
61 std::vector<TPoint>
62 DGtal::PointListReader<TPoint>::getPointsFromInputStream (std::istream &in, std::vector<unsigned int> aVectPosition)
63 {
64  if(aVectPosition.size()==0){
65  for(unsigned int i=0; i<TPoint::dimension; i++){
66  aVectPosition.push_back(i);
67  }
68  }
69  vector<TPoint> vectResult;
70  string str;
71  getline(in, str );
72  while ( in.good() ){
73  if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
74  istringstream in_str( str );
75  unsigned int idx = 0;
76  typename TPoint::Component val;
77  unsigned int nbFound=0;
78  TPoint p;
79  while ( in_str.good()&& (nbFound<TPoint::dimension)){
80  bool isOK = (in_str >> val);
81  for(unsigned int j=0; j< TPoint::dimension; j++){
82  if (isOK && (idx == aVectPosition.at(j)) ){
83  nbFound++;
84  p[j]=val;
85  }
86  }
87  ++idx;
88  }
89  if(nbFound==TPoint::dimension){
90  vectResult.push_back(p);
91  }
92  }
93  getline(in, str );
94  }
95  return vectResult;
96 
97 }
98 
99 
100 
101 
102 template<typename TPoint>
103 inline
104 std::vector< std::vector<TPoint> >
106  ifstream infile;
107  infile.open (filename.c_str(), ifstream::in);
109 }
110 
111 
112 template<typename TPoint>
113 inline
114 std::vector< std::vector<TPoint> >
116  vector< vector< TPoint > > vectResult;
117  string str;
118  getline(in, str );
119  while ( in.good() ){
120  if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
121  vector <TPoint> aContour;
122  istringstream in_str( str );
123  double x=0.0, y=0.0;
124  while ( in_str.good()){
125  bool isOK = (in_str >> x);
126  isOK = isOK && (in_str >>y);
127  if(isOK){
128  TPoint p;
129  p[0]=x;
130  p[1]=y;
131  aContour.push_back(p);
132  }
133  }
134  vectResult.push_back(aContour);
135  }
136  getline(in, str );
137  }
138  return vectResult;
139 
140 }
141 
142 
143 
144 
145 
146 
147 
148 template<typename TPoint>
149 template<typename TInteger>
150 inline
151 std::vector< FreemanChain< TInteger> >
153  std::vector< FreemanChain< TInteger> > vectResult;
154  ifstream infile;
155  infile.open (filename.c_str(), ifstream::in);
156  string str;
157  getline(infile, str );
158  while ( infile.good() ){
159  if ( ( str != "" ) && ( str[ 0 ] != '#' ) ){
160  istringstream in_str( str );
161  int x0, y0;
162  string fcChain;
163  bool isOK = (in_str >> x0) && (in_str >> y0) && (in_str >> fcChain);
164  FreemanChain< TInteger> fc(fcChain, x0, y0);
165  if(isOK){
166  vectResult.push_back(fc);
167  }else{
168  cerr << "Ignoring entry invalid FreemanChain" << endl;
169  }
170  }
171  getline(infile, str );
172  }
173  return vectResult;
174 }
175 
176 
177 
178 
179 // //
181 
182