readOBJ.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef IGL_READOBJ_H
  2. #define IGL_READOBJ_H
  3. #include "igl_inline.h"
  4. // History:
  5. // return type changed from void to bool Alec 18 Sept 2011
  6. // added pure vector of vectors version that has much more support Alec 31 Oct
  7. // 2011
  8. #ifndef IGL_NO_EIGEN
  9. # include <Eigen/Core>
  10. #endif
  11. #include <string>
  12. #include <vector>
  13. namespace igl
  14. {
  15. // Read a mesh from an ascii obj file, filling in vertex positions, normals
  16. // and texture coordinates. Mesh may have faces of any number of degree
  17. //
  18. // Templates:
  19. // Scalar type for positions and vectors (will be read as double and cast
  20. // to Scalar)
  21. // Index type for indices (will be read as int and cast to Index)
  22. // Inputs:
  23. // str path to .obj file
  24. // Outputs:
  25. // V double matrix of vertex positions #V by 3
  26. // F #F list of face indices into vertex positions
  27. // TC double matrix of texture coordinats #TC by 2
  28. // FTC #F list of face indices into vertex texture coordinates
  29. // N double matrix of corner normals #N by 3
  30. // FN #F list of face indices into vertex normals
  31. // Returns true on success, false on errors
  32. template <typename Scalar, typename Index>
  33. IGL_INLINE bool readOBJ(
  34. const std::string obj_file_name,
  35. std::vector<std::vector<Scalar > > & V,
  36. std::vector<std::vector<Scalar > > & TC,
  37. std::vector<std::vector<Scalar > > & N,
  38. std::vector<std::vector<Index > > & F,
  39. std::vector<std::vector<Index > > & FTC,
  40. std::vector<std::vector<Index > > & FN);
  41. #ifndef IGL_NO_EIGEN
  42. //! Read a mesh from an ascii obj file
  43. // Inputs:
  44. // str path to .obj file
  45. // Outputs:
  46. // V eigen matrix #V by 3
  47. // F eigen matrix #F by 3
  48. //
  49. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  50. // crash or give garbage on anything else.
  51. //
  52. // KNOWN BUG: This only knows how to face lines without normal or texture
  53. // indices. It will probably crash or give garbage on anything else.
  54. //
  55. // KNOWN BUG: The order of the attributes is different than the vector
  56. // version above
  57. template <typename DerivedV, typename DerivedF, typename DerivedT>
  58. IGL_INLINE bool readOBJ(
  59. const std::string str,
  60. Eigen::PlainObjectBase<DerivedV>& V,
  61. Eigen::PlainObjectBase<DerivedF>& F,
  62. Eigen::PlainObjectBase<DerivedV>& CN,
  63. Eigen::PlainObjectBase<DerivedF>& FN,
  64. Eigen::PlainObjectBase<DerivedT>& TC,
  65. Eigen::PlainObjectBase<DerivedF>& FTC);
  66. //! Read a poly mesh from an ascii obj file
  67. // Inputs:
  68. // str path to .obj file
  69. // Outputs:
  70. // V eigen matrix #V by 3
  71. // POLYF vector of vector with face indices
  72. //
  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. //
  77. // KNOWN BUG: The order of the attributes is different than the vector
  78. // version above
  79. template <
  80. typename DerivedV,
  81. typename DerivedF,
  82. typename DerivedT,
  83. typename Index>
  84. IGL_INLINE bool readOBJPoly(
  85. const std::string str,
  86. Eigen::PlainObjectBase<DerivedV>& V,
  87. std::vector<std::vector<Index> >& F,
  88. Eigen::PlainObjectBase<DerivedV>& CN,
  89. Eigen::PlainObjectBase<DerivedF>& FN,
  90. Eigen::PlainObjectBase<DerivedT>& TC,
  91. Eigen::PlainObjectBase<DerivedF>& FTC);
  92. //! Read a mesh from an ascii obj file
  93. // Inputs:
  94. // str path to .obj file
  95. // Outputs:
  96. // V eigen matrix #V by 3
  97. // F eigen matrix #F by 3
  98. //
  99. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  100. // crash or give garbage on anything else.
  101. //
  102. // KNOWN BUG: This only knows how to face lines without normal or texture
  103. // indices. It will probably crash or give garbage on anything else.
  104. template <typename DerivedV, typename DerivedF>
  105. IGL_INLINE bool readOBJ(
  106. const std::string str,
  107. Eigen::PlainObjectBase<DerivedV>& V,
  108. Eigen::PlainObjectBase<DerivedF>& F);
  109. #endif
  110. }
  111. #ifdef IGL_HEADER_ONLY
  112. # include "readOBJ.cpp"
  113. #endif
  114. #endif