readOBJ.h 4.5 KB

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