readOBJ.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. template <typename DerivedV, typename DerivedF, typename DerivedT>
  59. IGL_INLINE bool readOBJ(
  60. const std::string str,
  61. Eigen::PlainObjectBase<DerivedV>& V,
  62. Eigen::PlainObjectBase<DerivedF>& F,
  63. Eigen::PlainObjectBase<DerivedV>& CN,
  64. Eigen::PlainObjectBase<DerivedF>& FN,
  65. Eigen::PlainObjectBase<DerivedT>& TC,
  66. Eigen::PlainObjectBase<DerivedF>& FTC);
  67. //! Read a mesh from an ascii obj file
  68. // Inputs:
  69. // str path to .obj file
  70. // Outputs:
  71. // V eigen matrix #V by 3
  72. // F eigen matrix #F by 3
  73. //
  74. // KNOWN BUG: This only knows how to read *triangle* meshes. It will probably
  75. // crash or give garbage on anything else.
  76. //
  77. // KNOWN BUG: This only knows how to face lines without normal or texture
  78. // indices. It will probably crash or give garbage on anything else.
  79. template <typename DerivedV, typename DerivedF>
  80. IGL_INLINE bool readOBJ(
  81. const std::string str,
  82. Eigen::PlainObjectBase<DerivedV>& V,
  83. Eigen::PlainObjectBase<DerivedF>& F);
  84. #endif
  85. }
  86. #ifdef IGL_HEADER_ONLY
  87. # include "readOBJ.cpp"
  88. #endif
  89. #endif