Wildmeshing Toolkit
MshReader.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Core>
4 #include <filesystem>
5 #include <memory>
6 #include <wmtk/Mesh.hpp>
7 #include <wmtk/Types.hpp>
9 
10 #include <mshio/mshio.h>
11 
12 namespace wmtk::io {
13 
14 class MshReader
15 {
16 public:
19  std::shared_ptr<Mesh> read(
20  const std::filesystem::path& filename,
21  const bool ignore_z_if_zero,
22  const std::vector<std::string>& extra_facet_attributes = {});
23  std::shared_ptr<Mesh> read(
24  const std::filesystem::path& filename,
25  const int64_t embedded_dimension,
26  const std::vector<std::vector<std::string>>& extra_attributes);
27  std::shared_ptr<Mesh> read(
28  const std::filesystem::path& filename,
29  const int64_t embedded_dimension = -1);
30 
31 private:
32  const mshio::NodeBlock* get_vertex_block(int DIM) const;
33 
34  const mshio::ElementBlock* get_simplex_element_block(int DIM) const;
35 
36  size_t get_num_vertices(int DIM) const;
37 
38  size_t get_num_simplex_elements(int DIM) const;
39 
40  template <int DIM>
41  void extract_vertices();
42 
43  template <int DIM>
45 
46 
47  template <int DIM>
48  void extract();
49 
50 
51  template <int DIM>
52  void validate();
53 
54  int get_mesh_dimension() const;
55  int get_embedded_dimension() const;
56 
57  std::shared_ptr<Mesh> generate(
58  const std::optional<std::vector<std::vector<std::string>>>& extra_attributes = {});
59 
60  template <int DIM>
61  auto generateT() -> std::shared_ptr<wmtk::utils::mesh_type_from_dimension_t<DIM>>;
62 
63  template <int DIM>
64  auto construct() -> std::shared_ptr<wmtk::utils::mesh_type_from_dimension_t<DIM>>;
65 
66 
67  // std::vector<std::string> get_vertex_attribute_names(int DIM) const;
68 
69  // std::vector<std::string> get_element_attribute_names(int DIM) const;
70 
71  // void extract_vertex_attribute(
72  // std::shared_ptr<wmtk::TetMesh> m,
73  // const std::string& attr_name,
74  // int DIM);
75 
76  void extract_element_attribute(wmtk::Mesh& m, const std::string& attr_name, PrimitiveType pt);
77 
78  // template <int DIM, typename Fn>
79  // bool extract_element_attribute(const std::string& attr_name, int DIM);
80 
81 
82  // template <int DIM, typename Fn>
83  // void extract_element_attribute(const std::string& attr_name, Fn&& set_attr);
84 
85 
86 private:
87  mshio::MshSpec m_spec;
89 
90 
91  Eigen::MatrixXd V;
93 
94  static const int64_t AUTO_EMBEDDED_DIMENSION = -2;
95 };
96 
97 } // namespace wmtk::io
98 namespace wmtk {
100 }
const mshio::ElementBlock * get_simplex_element_block(int DIM) const
Definition: MshReader.cpp:88
auto construct() -> std::shared_ptr< wmtk::utils::mesh_type_from_dimension_t< DIM >>
Definition: MshReader.cpp:196
size_t get_num_simplex_elements(int DIM) const
Definition: MshReader.cpp:108
mshio::MshSpec m_spec
Definition: MshReader.hpp:87
int get_mesh_dimension() const
Definition: MshReader.cpp:28
int get_embedded_dimension() const
Definition: MshReader.cpp:119
static const int64_t AUTO_EMBEDDED_DIMENSION
Definition: MshReader.hpp:94
std::shared_ptr< Mesh > read(const std::filesystem::path &filename, const bool ignore_z_if_zero, const std::vector< std::string > &extra_facet_attributes={})
Definition: MshReader.cpp:38
int64_t m_embedded_dimension
Definition: MshReader.hpp:88
size_t get_num_vertices(int DIM) const
Definition: MshReader.cpp:98
const mshio::NodeBlock * get_vertex_block(int DIM) const
Definition: MshReader.cpp:78
auto generateT() -> std::shared_ptr< wmtk::utils::mesh_type_from_dimension_t< DIM >>
Definition: MshReader.cpp:361
Eigen::MatrixXd V
Definition: MshReader.hpp:91
void extract_simplex_elements()
Definition: MshReader.cpp:166
std::shared_ptr< Mesh > generate(const std::optional< std::vector< std::vector< std::string >>> &extra_attributes={})
Definition: MshReader.cpp:320
void extract_element_attribute(wmtk::Mesh &m, const std::string &attr_name, PrimitiveType pt)
Definition: MshReader.cpp:282
Definition: Accessor.hpp:6
io::MshReader MshReader
Definition: MshReader.hpp:99
MatrixX< int64_t > MatrixXl
Definition: Types.hpp:56