MRSL DecompUtil Library  0.1
An implementaion of convex decomposition over point cloud
txt_reader.hpp
1 #include <iterator>
2 #include <iostream>
3 #include <fstream>
5 
6 template <int Dim>
7 bool read_obs(std::string file_name, vec_Vecf<Dim>& obs) {
8  std::ifstream myfile(file_name);
9  if (!myfile) {
10  std::cout << "Unable to open file: " << file_name << std::endl;
11  return false;
12  }
13 
14  if (myfile.is_open()) {
15  std::string line;
16  while ( getline (myfile,line) ) {
18  std::istringstream buf(line);
19  std::istream_iterator<std::string> beg(buf), end;
20 
21  std::vector<std::string> tokens(beg, end);
22 
23  if(tokens.size() != Dim) {
24  std::cout << "Invalid format!" << std::endl;
25  std::cout << line << '\n';
26  return false;
27  }
28 
30  Vecf<Dim> pt;
31  for(int i = 0; i < Dim; i++)
32  pt(i) = atof(tokens[i].c_str());
33  obs.push_back(pt);
34  }
35  myfile.close();
36  }
37 
38  return true;
39 }
vec_E< Vecf< N >> vec_Vecf
Vector of Eigen 1D float vector.
Definition: data_type.h:69
Defines all data types used in this lib.
Eigen::Matrix< decimal_t, N, 1 > Vecf
Eigen 1D float vector.
Definition: data_type.h:57