readBF.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "readBF.h"
  2. #include "list_to_matrix.h"
  3. #include <vector>
  4. #include <cstdio>
  5. #include <fstream>
  6. template <
  7. typename DerivedWI,
  8. typename DerivedP,
  9. typename DerivedC>
  10. IGL_INLINE bool igl::readBF(
  11. const std::string & filename,
  12. Eigen::PlainObjectBase<DerivedWI> & WI,
  13. Eigen::PlainObjectBase<DerivedP> & P,
  14. Eigen::PlainObjectBase<DerivedC> & C)
  15. {
  16. using namespace std;
  17. ifstream is(filename);
  18. if(!is.is_open())
  19. {
  20. return false;
  21. }
  22. string line;
  23. std::vector<typename DerivedWI::Scalar> vWI;
  24. std::vector<typename DerivedP::Scalar> vP;
  25. std::vector<std::vector<typename DerivedC::Scalar> > vC;
  26. while(getline(is, line))
  27. {
  28. int wi,p;
  29. double cx,cy,cz;
  30. if(sscanf(line.c_str(), "%d %d %lg %lg %lg",&wi,&p,&cx,&cy,&cz) != 5)
  31. {
  32. return false;
  33. }
  34. vWI.push_back(wi);
  35. vP.push_back(p);
  36. vC.push_back({cx,cy,cz});
  37. }
  38. list_to_matrix(vWI,WI);
  39. list_to_matrix(vP,P);
  40. list_to_matrix(vC,C);
  41. return true;
  42. }
  43. #ifdef IGL_STATIC_LIBRARY
  44. template bool igl::readBF<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  45. #endif