readOBJ.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #ifndef IGL_NO_EIGEN
  13. # include <Eigen/Core>
  14. #endif
  15. #include <string>
  16. #include <vector>
  17. namespace igl
  18. {
  19. // Read a mesh from an ascii obj file, filling in vertex positions, normals
  20. // and texture coordinates. Mesh may have faces of any number of degree
  21. //
  22. // Templates:
  23. // Scalar type for positions and vectors (will be read as double and cast
  24. // to Scalar)
  25. // Index type for indices (will be read as int and cast to Index)
  26. // Inputs:
  27. // str path to .obj file
  28. // Outputs:
  29. // V double matrix of vertex positions #V by 3
  30. // F #F list of face indices into vertex positions
  31. // TC double matrix of texture coordinats #TC by 2
  32. // FTC #F list of face indices into vertex texture coordinates
  33. // N double matrix of corner normals #N by 3
  34. // FN #F list of face indices into vertex normals
  35. // Returns true on success, false on errors
  36. template <typename Scalar, typename Index>
  37. IGL_INLINE bool readOBJ(
  38. const std::string obj_file_name,
  39. std::vector<std::vector<Scalar > > & V,
  40. std::vector<std::vector<Scalar > > & TC,
  41. std::vector<std::vector<Scalar > > & N,
  42. std::vector<std::vector<Index > > & F,
  43. std::vector<std::vector<Index > > & FTC,
  44. std::vector<std::vector<Index > > & FN);
  45. #ifndef IGL_NO_EIGEN
  46. //! Read a mesh from an ascii obj file
  47. // Inputs:
  48. // str path to .obj file
  49. // Outputs:
  50. // V eigen matrix #V by 3
  51. // F eigen matrix #F by 3
  52. //
  53. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  54. // crash or give garbage on anything else.
  55. //
  56. // KNOWN BUG: This only knows how to face lines without normal or texture
  57. // indices. It will probably crash or give garbage on anything else.
  58. //
  59. // KNOWN BUG: The order of the attributes is different than the vector
  60. // version above
  61. template <typename DerivedV, typename DerivedF, typename DerivedT>
  62. IGL_INLINE bool readOBJ(
  63. const std::string str,
  64. Eigen::PlainObjectBase<DerivedV>& V,
  65. Eigen::PlainObjectBase<DerivedF>& F,
  66. Eigen::PlainObjectBase<DerivedV>& CN,
  67. Eigen::PlainObjectBase<DerivedF>& FN,
  68. Eigen::PlainObjectBase<DerivedT>& TC,
  69. Eigen::PlainObjectBase<DerivedF>& FTC);
  70. //! Read a poly mesh from an ascii obj file
  71. // Inputs:
  72. // str path to .obj file
  73. // Outputs:
  74. // V eigen matrix #V by 3
  75. // POLYF vector of vector with face indices
  76. //
  77. //
  78. // KNOWN BUG: This only knows how to face lines without normal or texture
  79. // indices. It will probably crash or give garbage on anything else.
  80. //
  81. // KNOWN BUG: The order of the attributes is different than the vector
  82. // version above
  83. template <typename DerivedV, typename DerivedF, typename DerivedT, 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