readMESH.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_READMESH_H
  9. #define IGL_READMESH_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <string>
  13. #include <vector>
  14. #include <cstdio>
  15. namespace igl
  16. {
  17. // load a tetrahedral volume mesh from a .mesh file
  18. //
  19. // Templates:
  20. // Scalar type for positions and vectors (will be read as double and cast
  21. // to Scalar)
  22. // Index type for indices (will be read as int and cast to Index)
  23. // Input:
  24. // mesh_file_name path of .mesh file
  25. // Outputs:
  26. // V double matrix of vertex positions #V by 3
  27. // T #T list of tet indices into vertex positions
  28. // F #F list of face indices into vertex positions
  29. //
  30. // Known bugs: Holes and regions are not supported
  31. template <typename Scalar, typename Index>
  32. IGL_INLINE bool readMESH(
  33. const std::string mesh_file_name,
  34. std::vector<std::vector<Scalar > > & V,
  35. std::vector<std::vector<Index > > & T,
  36. std::vector<std::vector<Index > > & F);
  37. // Inputs:
  38. // mesh_file pointer to already opened .mesh file
  39. // Outputs:
  40. // mesh_file closed file
  41. template <typename Scalar, typename Index>
  42. IGL_INLINE bool readMESH(
  43. FILE * mesh_file,
  44. std::vector<std::vector<Scalar > > & V,
  45. std::vector<std::vector<Index > > & T,
  46. std::vector<std::vector<Index > > & F);
  47. // Input:
  48. // mesh_file_name path of .mesh file
  49. // Outputs:
  50. // V eigen double matrix #V by 3
  51. // T eigen int matrix #T by 4
  52. // F eigen int matrix #F by 3
  53. template <typename DerivedV, typename DerivedF, typename DerivedT>
  54. IGL_INLINE bool readMESH(
  55. const std::string mesh_file_name,
  56. Eigen::PlainObjectBase<DerivedV>& V,
  57. Eigen::PlainObjectBase<DerivedT>& T,
  58. Eigen::PlainObjectBase<DerivedF>& F);
  59. // Inputs:
  60. // mesh_file pointer to already opened .mesh file
  61. // Outputs:
  62. // mesh_file closed file
  63. template <typename DerivedV, typename DerivedF, typename DerivedT>
  64. IGL_INLINE bool readMESH(
  65. FILE * mesh_file,
  66. Eigen::PlainObjectBase<DerivedV>& V,
  67. Eigen::PlainObjectBase<DerivedT>& T,
  68. Eigen::PlainObjectBase<DerivedF>& F);
  69. }
  70. #ifndef IGL_STATIC_LIBRARY
  71. # include "readMESH.cpp"
  72. #endif
  73. #endif