readOBJ.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // IGL Lib - Simple C++ mesh library
  3. //
  4. // Copyright 2011, Daniele Panozzo. All rights reserved.
  5. // History:
  6. // return type changed from void to bool Alec 18 Sept 2011
  7. // added pure vector of vectors version that has much more support Alec 31 Oct
  8. // 2011
  9. #ifndef IGL_READOBJ_H
  10. #define IGL_READOBJ_H
  11. #include "igl_inline.h"
  12. #include <Eigen/Core>
  13. #include <string>
  14. #include <vector>
  15. namespace igl
  16. {
  17. // Read a mesh from an ascii obj file, filling in vertex positions, normals
  18. // and texture coordinates. Mesh may have faces of any number of degree
  19. //
  20. // Templates:
  21. // Scalar type for positions and vectors (will be read as double and cast
  22. // to Scalar)
  23. // Index type for indices (will be read as int and cast to Index)
  24. // Inputs:
  25. // str path to .obj file
  26. // Outputs:
  27. // V double matrix of vertex positions #V by 3
  28. // F #F list of face indices into vertex positions
  29. // TC double matrix of texture coordinats #TC by 2
  30. // FTC #F list of face indices into vertex texture coordinates
  31. // N double matrix of corner normals #N by 3
  32. // FN #F list of face indices into vertex normals
  33. // Returns true on success, false on errors
  34. template <typename Scalar, typename Index>
  35. IGL_INLINE bool readOBJ(
  36. const std::string obj_file_name,
  37. std::vector<std::vector<Scalar > > & V,
  38. std::vector<std::vector<Scalar > > & TC,
  39. std::vector<std::vector<Scalar > > & N,
  40. std::vector<std::vector<Index > > & F,
  41. std::vector<std::vector<Index > > & FTC,
  42. std::vector<std::vector<Index > > & FN);
  43. //! Read a mesh from an ascii obj file
  44. // Inputs:
  45. // str path to .obj file
  46. // Outputs:
  47. // V eigen matrix #V by 3
  48. // F eigen matrix #F by 3
  49. //
  50. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  51. // crash or give garbage on anything else.
  52. //
  53. // KNOWN BUG: This only knows how to face lines without normal or texture
  54. // indices. It will probably crash or give garbage on anything else.
  55. template <typename DerivedV, typename DerivedF, typename DerivedT>
  56. IGL_INLINE bool readOBJ(
  57. const std::string str,
  58. Eigen::PlainObjectBase<DerivedV>& V,
  59. Eigen::PlainObjectBase<DerivedF>& F,
  60. Eigen::PlainObjectBase<DerivedV>& CN,
  61. Eigen::PlainObjectBase<DerivedF>& FN,
  62. Eigen::PlainObjectBase<DerivedT>& TC,
  63. Eigen::PlainObjectBase<DerivedF>& FTC);
  64. //! Read a mesh from an ascii obj file
  65. // Inputs:
  66. // str path to .obj file
  67. // Outputs:
  68. // V eigen matrix #V by 3
  69. // F eigen matrix #F by 3
  70. //
  71. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  72. // crash or give garbage on anything else.
  73. //
  74. // KNOWN BUG: This only knows how to face lines without normal or texture
  75. // indices. It will probably crash or give garbage on anything else.
  76. template <typename DerivedV, typename DerivedF, typename DerivedT>
  77. IGL_INLINE bool readOBJ(
  78. const std::string str,
  79. Eigen::PlainObjectBase<DerivedV>& V,
  80. Eigen::PlainObjectBase<DerivedF>& F);
  81. }
  82. #ifdef IGL_HEADER_ONLY
  83. # include "readOBJ.cpp"
  84. #endif
  85. #endif