readOFF.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_READOFF_H
  9. #define IGL_READOFF_H
  10. #include "igl_inline.h"
  11. // History:
  12. // return type changed from void to bool Alec 18 Sept 2011
  13. #ifndef IGL_NO_EIGEN
  14. # include <Eigen/Core>
  15. #endif
  16. #include <string>
  17. #include <vector>
  18. namespace igl
  19. {
  20. // Read a mesh from an ascii obj file, filling in vertex positions, normals
  21. // and texture coordinates. Mesh may have faces of any number of degree
  22. //
  23. // Templates:
  24. // Scalar type for positions and vectors (will be read as double and cast
  25. // to Scalar)
  26. // Index type for indices (will be read as int and cast to Index)
  27. // Inputs:
  28. // str path to .obj file
  29. // Outputs:
  30. // V double matrix of vertex positions #V by 3
  31. // F #F list of face indices into vertex positions
  32. // TC double matrix of texture coordinats #TC by 2
  33. // FTC #F list of face indices into vertex texture coordinates
  34. // N double matrix of corner normals #N by 3
  35. // FN #F list of face indices into vertex normals
  36. // Returns true on success, false on errors
  37. template <typename Scalar, typename Index>
  38. IGL_INLINE bool readOFF(
  39. const std::string off_file_name,
  40. std::vector<std::vector<Scalar > > & V,
  41. std::vector<std::vector<Index > > & F,
  42. std::vector<std::vector<Scalar > > & N);
  43. #ifndef IGL_NO_EIGEN
  44. // read mesh from a ascii off file
  45. // Inputs:
  46. // str path to .off file
  47. // Outputs:
  48. // V eigen double matrix #V by 3
  49. // F eigen int matrix #F by 3
  50. template <typename DerivedV, typename DerivedF>
  51. IGL_INLINE bool readOFF(
  52. const std::string str,
  53. Eigen::PlainObjectBase<DerivedV>& V,
  54. Eigen::PlainObjectBase<DerivedF>& F);
  55. template <typename DerivedV, typename DerivedF>
  56. IGL_INLINE bool readOFF(
  57. const std::string str,
  58. Eigen::PlainObjectBase<DerivedV>& V,
  59. Eigen::PlainObjectBase<DerivedF>& F,
  60. Eigen::PlainObjectBase<DerivedV>& N);
  61. #endif
  62. }
  63. #ifndef IGL_STATIC_LIBRARY
  64. # include "readOFF.cpp"
  65. #endif
  66. #endif