read.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "read.h"
  9. #include "readOBJ.h"
  10. #include "readOFF.h"
  11. #include "pathinfo.h"
  12. #include <cstdio>
  13. #include <iostream>
  14. template <typename Scalar, typename Index>
  15. IGL_INLINE bool igl::read(
  16. const std::string str,
  17. std::vector<std::vector<Scalar> > & V,
  18. std::vector<std::vector<Index> > & F)
  19. {
  20. using namespace std;
  21. using namespace igl;
  22. // dirname, basename, extension and filename
  23. string d,b,e,f;
  24. pathinfo(str,d,b,e,f);
  25. // Convert extension to lower case
  26. std::transform(e.begin(), e.end(), e.begin(), ::tolower);
  27. vector<vector<Scalar> > TC, N;
  28. vector<vector<Index> > FTC, FN;
  29. if(e == "obj")
  30. {
  31. return readOBJ(str,V,TC,N,F,FTC,FN);
  32. }else if(e == "off")
  33. {
  34. return readOFF(str,V,F,N);
  35. }
  36. cerr<<"Error: "<<__FUNCTION__<<": "<<
  37. str<<" is not a recognized mesh file format."<<endl;
  38. return false;
  39. }
  40. #ifndef IGL_NO_EIGN
  41. template <typename DerivedV, typename DerivedF>
  42. IGL_INLINE bool igl::read(
  43. const std::string str,
  44. Eigen::PlainObjectBase<DerivedV>& V,
  45. Eigen::PlainObjectBase<DerivedF>& F)
  46. {
  47. const char* p;
  48. for (p = str.c_str(); *p != '\0'; p++)
  49. ;
  50. while (*p != '.')
  51. p--;
  52. if (!strcmp(p, ".obj") || !strcmp(p, ".OBJ"))
  53. {
  54. return igl::readOBJ(str,V,F);
  55. }else if (!strcmp(p, ".off") || !strcmp(p, ".OFF"))
  56. {
  57. return igl::readOFF(str,V,F);
  58. }
  59. else
  60. {
  61. fprintf(stderr,"read() does not recognize extension: %s\n",p);
  62. return false;
  63. }
  64. }
  65. #endif
  66. #ifndef IGL_HEADER_ONLY
  67. // Explicit template specialization
  68. // generated by autoexplicit.sh
  69. 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> >&);
  70. 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> > > >&);
  71. template bool igl::read<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::string, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
  72. #endif