readOBJ.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <
  84. typename DerivedV,
  85. typename DerivedF,
  86. typename DerivedT,
  87. typename Index>
  88. IGL_INLINE bool readOBJPoly(
  89. const std::string str,
  90. Eigen::PlainObjectBase<DerivedV>& V,
  91. std::vector<std::vector<Index> >& F,
  92. Eigen::PlainObjectBase<DerivedV>& CN,
  93. Eigen::PlainObjectBase<DerivedF>& FN,
  94. Eigen::PlainObjectBase<DerivedT>& TC,
  95. Eigen::PlainObjectBase<DerivedF>& FTC);
  96. //! Read a mesh from an ascii obj file
  97. // Inputs:
  98. // str path to .obj file
  99. // Outputs:
  100. // V eigen matrix #V by 3
  101. // F eigen matrix #F by 3
  102. //
  103. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  104. // crash or give garbage on anything else.
  105. //
  106. // KNOWN BUG: This only knows how to face lines without normal or texture
  107. // indices. It will probably crash or give garbage on anything else.
  108. template <typename DerivedV, typename DerivedF>
  109. IGL_INLINE bool readOBJ(
  110. const std::string str,
  111. Eigen::PlainObjectBase<DerivedV>& V,
  112. Eigen::PlainObjectBase<DerivedF>& F);
  113. #endif
  114. }
  115. #ifdef IGL_HEADER_ONLY
  116. # include "readOBJ.cpp"
  117. #endif
  118. #endif