readMSH.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // high level interface for MshLoader.h/.cpp
  2. // Copyright (C) 2020 Vladimir Fonov <[email protected]>
  3. //
  4. // This Source Code Form is subject to the terms of the Mozilla
  5. // Public License v. 2.0. If a copy of the MPL was not distribute
  6. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #ifndef IGL_READ_MSH_H
  8. #define IGL_READ_MSH_H
  9. #include "igl_inline.h"
  10. #include <Eigen/Core>
  11. #include <string>
  12. #include <vector>
  13. namespace igl
  14. {
  15. /// read triangle surface mesh and tetrahedral volume mesh from .msh file
  16. ///
  17. /// @tparam EigenMatrixOptions matrix options of output matrices (e.g.,
  18. /// Eigen::ColMajor, Eigen::RowMajor)
  19. /// @param[in] msh - file name
  20. /// @param[out] X eigen double matrix of vertex positions #X by 3
  21. /// @param[out] Tri #Tri eigen integer matrix of triangular faces indices into vertex positions
  22. /// @param[out] Tet #Tet eigen integer matrix of tetrahedral indices into vertex positions
  23. /// @param[out] TriTag #Tri eigen integer vector of tags associated with surface faces
  24. /// @param[out] TetTag #Tet eigen integer vector of tags associated with volume elements
  25. /// @param[out] XFields #XFields list of strings with field names associated with nodes
  26. /// @param[out] XF #XFields list of eigen double matrices, fields associated with nodes
  27. /// @param[out] EFields #EFields list of strings with field names associated with elements
  28. /// @param[out] TriF #EFields list of eigen double matrices, fields associated with surface elements
  29. /// @param[out] TetF #EFields list of eigen double matrices, fields associated with volume elements
  30. /// @return true on success
  31. /// \bug only version 2.2 of .msh file is supported (gmsh 3.X)
  32. /// \bug only triangle surface elements and tetrahedral volumetric elements are supported
  33. /// \bug only 3D information is supported
  34. /// \bug only the 1st tag per element is returned (physical)
  35. /// \bug same element fields are expected to be associated with surface elements and volumetric elements
  36. template <
  37. typename DerivedX,
  38. typename DerivedTri,
  39. typename DerivedTet,
  40. typename DerivedTriTag,
  41. typename DerivedTetTag,
  42. typename MatrixXF,
  43. typename MatrixTriF,
  44. typename MatrixTetF
  45. >
  46. IGL_INLINE bool readMSH(
  47. const std::string &msh,
  48. Eigen::PlainObjectBase<DerivedX> &X,
  49. Eigen::PlainObjectBase<DerivedTri> &Tri,
  50. Eigen::PlainObjectBase<DerivedTet> &Tet,
  51. Eigen::PlainObjectBase<DerivedTriTag> &TriTag,
  52. Eigen::PlainObjectBase<DerivedTetTag> &TetTag,
  53. std::vector<std::string> &XFields,
  54. std::vector<MatrixXF> &XF,
  55. std::vector<std::string> &EFields,
  56. std::vector<MatrixTriF> &TriF,
  57. std::vector<MatrixTetF> &TetF);
  58. /// \overload
  59. template <int EigenMatrixOptions>
  60. IGL_INLINE bool readMSH(
  61. const std::string &msh,
  62. Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &X,
  63. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tri,
  64. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tet,
  65. Eigen::VectorXi &TriTag,
  66. Eigen::VectorXi &TetTag);
  67. /// \overload
  68. template <int EigenMatrixOptions>
  69. IGL_INLINE bool readMSH(
  70. const std::string &msh,
  71. Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &X,
  72. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tri,
  73. Eigen::VectorXi &TriTag);
  74. /// \overload
  75. template <int EigenMatrixOptions>
  76. IGL_INLINE bool readMSH(
  77. const std::string &msh,
  78. Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &X,
  79. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tri);
  80. }
  81. #ifndef IGL_STATIC_LIBRARY
  82. # include "readMSH.cpp"
  83. #endif
  84. #endif