readMSH.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <int EigenMatrixOptions>
  37. IGL_INLINE bool readMSH(
  38. const std::string &msh,
  39. Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &X,
  40. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tri,
  41. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tet,
  42. Eigen::VectorXi &TriTag,
  43. Eigen::VectorXi &TetTag,
  44. std::vector<std::string> &XFields,
  45. std::vector<Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions>> &XF,
  46. std::vector<std::string> &EFields,
  47. std::vector<Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions>> &TriF,
  48. std::vector<Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions>> &TetF);
  49. /// \overload
  50. template <int EigenMatrixOptions>
  51. IGL_INLINE bool readMSH(
  52. const std::string &msh,
  53. Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &X,
  54. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tri,
  55. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tet,
  56. Eigen::VectorXi &TriTag,
  57. Eigen::VectorXi &TetTag);
  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::VectorXi &TriTag);
  65. /// \overload
  66. template <int EigenMatrixOptions>
  67. IGL_INLINE bool readMSH(
  68. const std::string &msh,
  69. Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &X,
  70. Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic,EigenMatrixOptions> &Tri);
  71. }
  72. #ifndef IGL_STATIC_LIBRARY
  73. # include "readMSH.cpp"
  74. #endif
  75. #endif