readOFF.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. #include <cstdio>
  19. namespace igl
  20. {
  21. /// Read a mesh from an ascii OFF file, filling in vertex positions, normals
  22. /// and texture coordinates. Mesh may have faces of any number of degree
  23. ///
  24. /// @tparam Scalar type for positions and vectors (will be read as double and cast
  25. /// to Scalar)
  26. /// @tparam Index type for indices (will be read as int and cast to Index)
  27. /// @param[in] str path to .obj file
  28. /// @param[out] V double matrix of vertex positions #V by 3
  29. /// @param[out] F #F list of face indices into vertex positions
  30. /// @param[out] N list of vertex normals #V by 3
  31. /// @param[out] C list of rgb color values per vertex #V by 3
  32. /// @return true on success, false on errors
  33. template <typename Scalar, typename Index>
  34. IGL_INLINE bool readOFF(
  35. const std::string off_file_name,
  36. std::vector<std::vector<Scalar > > & V,
  37. std::vector<std::vector<Index > > & F,
  38. std::vector<std::vector<Scalar > > & N,
  39. std::vector<std::vector<Scalar > > & C);
  40. /// \overload
  41. template <typename DerivedV, typename DerivedF>
  42. IGL_INLINE bool readOFF(
  43. const std::string str,
  44. Eigen::PlainObjectBase<DerivedV>& V,
  45. Eigen::PlainObjectBase<DerivedF>& F);
  46. /// \overload
  47. template <typename DerivedV, typename DerivedF>
  48. IGL_INLINE bool readOFF(
  49. const std::string str,
  50. Eigen::PlainObjectBase<DerivedV>& V,
  51. Eigen::PlainObjectBase<DerivedF>& F,
  52. Eigen::PlainObjectBase<DerivedV>& N);
  53. /// \overload
  54. /// @param[in,out] off_file pointer to already open .off file (will be closed)
  55. template <typename Scalar, typename Index>
  56. IGL_INLINE bool readOFF(
  57. FILE * off_file,
  58. std::vector<std::vector<Scalar > > & V,
  59. std::vector<std::vector<Index > > & F,
  60. std::vector<std::vector<Scalar > > & N,
  61. std::vector<std::vector<Scalar > > & C);
  62. }
  63. #ifndef IGL_STATIC_LIBRARY
  64. # include "readOFF.cpp"
  65. #endif
  66. #endif