readOFF.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #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. // Templates:
  25. // Scalar type for positions and vectors (will be read as double and cast
  26. // to Scalar)
  27. // Index type for indices (will be read as int and cast to Index)
  28. // Inputs:
  29. // str path to .obj file
  30. // Outputs:
  31. // V double matrix of vertex positions #V by 3
  32. // F #F list of face indices into vertex positions
  33. // N list of vertex normals #V by 3
  34. // C list of rgb color values per vertex #V by 3
  35. // Returns true on success, false on errors
  36. template <typename Scalar, typename Index>
  37. IGL_INLINE bool readOFF(
  38. const std::string off_file_name,
  39. std::vector<std::vector<Scalar > > & V,
  40. std::vector<std::vector<Index > > & F,
  41. std::vector<std::vector<Scalar > > & N,
  42. std::vector<std::vector<Scalar > > & C);
  43. // Inputs:
  44. // off_file pointer to already opened .off file
  45. // Outputs:
  46. // off_file closed file
  47. template <typename Scalar, typename Index>
  48. IGL_INLINE bool readOFF(
  49. FILE * off_file,
  50. std::vector<std::vector<Scalar > > & V,
  51. std::vector<std::vector<Index > > & F,
  52. std::vector<std::vector<Scalar > > & N,
  53. std::vector<std::vector<Scalar > > & C);
  54. #ifndef IGL_NO_EIGEN
  55. // read mesh from a ascii off file
  56. // Inputs:
  57. // str path to .off file
  58. // Outputs:
  59. // V eigen double matrix #V by 3
  60. // F eigen int matrix #F by 3
  61. template <typename DerivedV, typename DerivedF>
  62. IGL_INLINE bool readOFF(
  63. const std::string str,
  64. Eigen::PlainObjectBase<DerivedV>& V,
  65. Eigen::PlainObjectBase<DerivedF>& F);
  66. template <typename DerivedV, typename DerivedF>
  67. IGL_INLINE bool readOFF(
  68. const std::string str,
  69. Eigen::PlainObjectBase<DerivedV>& V,
  70. Eigen::PlainObjectBase<DerivedF>& F,
  71. Eigen::PlainObjectBase<DerivedV>& N);
  72. #endif
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "readOFF.cpp"
  76. #endif
  77. #endif