read_triangle_mesh.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_READ_TRIANGLE_MESH_H
  9. #define IGL_READ_TRIANGLE_MESH_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <string>
  13. #include <cstdio>
  14. #include <vector>
  15. // History:
  16. // renamed read -> read_triangle_mesh Daniele 24 June 2014
  17. // return type changed from void to bool Alec 18 Sept 2011
  18. namespace igl
  19. {
  20. /// Read mesh from an ascii file with automatic detection of file format
  21. /// among: mesh, msh obj, off, ply, stl, wrl.
  22. ///
  23. /// @tparam Scalar type for positions and vectors (will be read as double and
  24. /// cast to Scalar)
  25. /// @tparam Index type for indices (will be read as int and cast to Index)
  26. /// @param[in] str path to file
  27. /// @param[out] V eigen double matrix #V by 3
  28. /// @param[out] F eigen int matrix #F by 3
  29. /// @return true iff success
  30. template <typename DerivedV, typename DerivedF>
  31. IGL_INLINE bool read_triangle_mesh(
  32. const std::string str,
  33. Eigen::PlainObjectBase<DerivedV>& V,
  34. Eigen::PlainObjectBase<DerivedF>& F);
  35. /// \overload
  36. /// \brief outputs to vectors, only .off and .obj supported.
  37. template <typename Scalar, typename Index>
  38. IGL_INLINE bool read_triangle_mesh(
  39. const std::string str,
  40. std::vector<std::vector<Scalar> > & V,
  41. std::vector<std::vector<Index> > & F);
  42. /// \overload
  43. /// @param[out] dir directory path (see pathinfo.h)
  44. /// @param[out] base base name (see pathinfo.h)
  45. /// @param[out] ext extension (see pathinfo.h)
  46. /// @param[out] name filename (see pathinfo.h)
  47. template <typename DerivedV, typename DerivedF>
  48. IGL_INLINE bool read_triangle_mesh(
  49. const std::string str,
  50. Eigen::PlainObjectBase<DerivedV>& V,
  51. Eigen::PlainObjectBase<DerivedF>& F,
  52. std::string & dir,
  53. std::string & base,
  54. std::string & ext,
  55. std::string & name);
  56. /// \overload
  57. /// @param[in] ext file extension
  58. /// @param[in,out] fp pointer to already opened .ext file (will be closed)
  59. template <typename DerivedV, typename DerivedF>
  60. IGL_INLINE bool read_triangle_mesh(
  61. const std::string & ext,
  62. FILE * fp,
  63. Eigen::PlainObjectBase<DerivedV>& V,
  64. Eigen::PlainObjectBase<DerivedF>& F);
  65. }
  66. #ifndef IGL_STATIC_LIBRARY
  67. # include "read_triangle_mesh.cpp"
  68. #endif
  69. #endif