read.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "read.h"
  2. #include "readOBJ.h"
  3. #include "readOFF.h"
  4. #include "pathinfo.h"
  5. #include <cstdio>
  6. #include <iostream>
  7. template <typename Scalar, typename Index>
  8. IGL_INLINE bool igl::read(
  9. const std::string str,
  10. std::vector<std::vector<Scalar> > & V,
  11. std::vector<std::vector<Index> > & F)
  12. {
  13. using namespace std;
  14. using namespace igl;
  15. // dirname, basename, extension and filename
  16. string d,b,e,f;
  17. pathinfo(str,d,b,e,f);
  18. // Convert extension to lower case
  19. std::transform(e.begin(), e.end(), e.begin(), ::tolower);
  20. vector<vector<Scalar> > TC, N;
  21. vector<vector<Index> > FTC, FN;
  22. if(e == "obj")
  23. {
  24. return readOBJ(str,V,TC,N,F,FTC,FN);
  25. }else if(e == "off")
  26. {
  27. return readOFF(str,V,F,N);
  28. }
  29. cerr<<"Error: "<<__FUNCTION__<<": "<<
  30. str<<" is not a recognized mesh file format."<<endl;
  31. return false;
  32. }
  33. #ifndef IGL_NO_EIGN
  34. template <typename DerivedV, typename DerivedF>
  35. IGL_INLINE bool igl::read(
  36. const std::string str,
  37. Eigen::PlainObjectBase<DerivedV>& V,
  38. Eigen::PlainObjectBase<DerivedF>& F)
  39. {
  40. const char* p;
  41. for (p = str.c_str(); *p != '\0'; p++)
  42. ;
  43. while (*p != '.')
  44. p--;
  45. if (!strcmp(p, ".obj") || !strcmp(p, ".OBJ"))
  46. {
  47. return igl::readOBJ(str,V,F);
  48. }else if (!strcmp(p, ".off") || !strcmp(p, ".OFF"))
  49. {
  50. return igl::readOFF(str,V,F);
  51. }
  52. else
  53. {
  54. fprintf(stderr,"read() does not recognize extension: %s\n",p);
  55. return false;
  56. }
  57. }
  58. #endif
  59. #ifndef IGL_HEADER_ONLY
  60. // Explicit template specialization
  61. // generated by autoexplicit.sh
  62. template bool igl::read<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  63. template bool igl::read<double, int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
  64. #endif