aimstil  5.0.5
readTXTFile.h
Go to the documentation of this file.
1 #ifndef TIL_READTXTFILE_H
2 #define TIL_READTXTFILE_H
3 
4 #include <fstream>
5 #include <iostream>
6 #include <limits>
7 #include <vector>
8 
9 // includes from TIL
10 #include "til/numeric_array.h"
11 
12 
13 template < class T >
14 void readTXT3DPoints(const char *filename, std::vector<numeric_array<T,3> > &v)
15 {
16 
17  ifstream f (filename); // ios::nocreate not defined???
18 
19  if (!f)
20  {
21  throw std::runtime_error("Unable to open file");
22  }
23 
24 
25  // Read points from file
26 
27  int count = 0;
28  numeric_array<T,3> tv;
29  double x, y, z;
30 
31  for (;;)
32  {
33  const int SIZE_BUFF = 100;
34  char buff[SIZE_BUFF];
35 
36  f >> x >> y >> z;
37  if (!f.good()) break;
38 
39  // Convert to vector's type
40 
41  tv[0] = castValue<double, T>(x);
42  tv[1] = castValue<double, T>(y);
43  tv[2] = castValue<double, T>(z);
44 
45  v.push_back(tv);
46  ++count;
47 
48  // Skip the remaining of the line
49 
50  f.getline(buff, SIZE_BUFF);
51  if (!f.good()) break;
52  }
53 
54 }
55 
56 #endif
void readTXT3DPoints(const char *filename, std::vector< numeric_array< T, 3 > > &v)
Definition: readTXTFile.h:14