readOBJ.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // TC double matrix of texture coordinats #TC by 2
  35. // N double matrix of corner normals #N by 3
  36. // F #F list of face indices into vertex positions
  37. // FTC #F list of face indices into vertex texture coordinates
  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. // Eigen Wrappers. These will return true only if the data is perfectly
  57. // "rectangular": All faces are the same degree, all have the same number of
  58. // textures/normals etc.
  59. template <typename DerivedV, typename DerivedF, typename DerivedT>
  60. IGL_INLINE bool readOBJ(
  61. const std::string str,
  62. Eigen::PlainObjectBase<DerivedV>& V,
  63. Eigen::PlainObjectBase<DerivedT>& TC,
  64. Eigen::PlainObjectBase<DerivedV>& CN,
  65. Eigen::PlainObjectBase<DerivedF>& F,
  66. Eigen::PlainObjectBase<DerivedF>& FTC,
  67. Eigen::PlainObjectBase<DerivedF>& FN);
  68. template <typename DerivedV, typename DerivedF>
  69. IGL_INLINE bool readOBJ(
  70. const std::string str,
  71. Eigen::PlainObjectBase<DerivedV>& V,
  72. Eigen::PlainObjectBase<DerivedF>& F);
  73. #endif
  74. }
  75. #ifndef IGL_STATIC_LIBRARY
  76. # include "readOBJ.cpp"
  77. #endif
  78. #endif