Wildmeshing Toolkit
ParaviewWriter.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MeshWriter.hpp"
4 
5 #include <Eigen/Core>
6 #include <filesystem>
7 
8 namespace paraviewo {
9 class ParaviewWriter;
10 } // namespace paraviewo
11 
12 namespace wmtk {
13 class Mesh;
14 
15 namespace io {
16 class ParaviewWriter : public MeshWriter
17 {
18 private:
20  {
21  public:
24 
25  void init(
26  const std::filesystem::path& filename,
27  const std::string& vertices_name,
28  const Eigen::MatrixXi& elements,
29  const bool enabled);
30 
31  void write(const std::string& name, const int64_t stride, const std::vector<double>& val);
32 
33 
34  Eigen::MatrixXd& vertices() { return m_vertices; }
35 
36  private:
37  std::string m_vertices_name;
38 
39  std::filesystem::path m_filename;
40 
41  bool m_enabled;
42 
43  std::shared_ptr<paraviewo::ParaviewWriter> m_paraview_file;
44 
45  Eigen::MatrixXd m_vertices;
46  Eigen::MatrixXi m_elements;
47  };
48 
49 public:
51  const std::filesystem::path& filename,
52  const std::string& vertices_name,
53  const Mesh& mesh,
54  bool write_points = true,
55  bool write_edges = true,
56  bool write_faces = true,
57  bool write_tetrahedra = true);
58 
59  bool write(const int dim) override { return dim == 0 || m_enabled[dim]; }
60 
61  void write_top_simplex_type(const PrimitiveType) override {}
62  void write_absolute_id(const std::vector<int64_t>& id) override
63  {
64  m_write = m_mm_level == 0;
65  ++m_mm_level;
66  }
67 
68  // paraview doesn't care about mesh capacities
69  void write_capacities(const std::vector<int64_t>& capacities) override {}
70 
71  void write(
72  const std::string& name,
73  const int64_t type,
74  const int64_t stride,
75  const std::vector<char>& val,
76  const char default_val) override;
77 
78  void write(
79  const std::string& name,
80  const int64_t type,
81  const int64_t stride,
82  const std::vector<int64_t>& val,
83  const int64_t default_val) override;
84 
85  void write(
86  const std::string& name,
87  const int64_t type,
88  const int64_t stride,
89  const std::vector<double>& val,
90  const double default_val) override;
91 
92  void write(
93  const std::string& name,
94  const int64_t type,
95  const int64_t stride,
96  const std::vector<Rational>& val,
97  const Rational& default_val) override;
98 
99 
100 private:
101  std::array<ParaviewInternalWriter, 4> m_writers;
102  std::array<bool, 4> m_enabled;
103  std::string m_vertices_name;
104  bool m_write;
105 
106  void write_internal(
107  const std::string& name,
108  const int64_t type,
109  const int64_t stride,
110  const std::vector<double>& val);
111 };
112 } // namespace io
113 
115 
116 } // namespace wmtk
int64_t m_mm_level
Definition: MeshWriter.hpp:51
void write(const std::string &name, const int64_t stride, const std::vector< double > &val)
std::shared_ptr< paraviewo::ParaviewWriter > m_paraview_file
void init(const std::filesystem::path &filename, const std::string &vertices_name, const Eigen::MatrixXi &elements, const bool enabled)
void write_top_simplex_type(const PrimitiveType) override
void write_absolute_id(const std::vector< int64_t > &id) override
ParaviewWriter(const std::filesystem::path &filename, const std::string &vertices_name, const Mesh &mesh, bool write_points=true, bool write_edges=true, bool write_faces=true, bool write_tetrahedra=true)
std::array< ParaviewInternalWriter, 4 > m_writers
bool write(const int dim) override
std::array< bool, 4 > m_enabled
void write_internal(const std::string &name, const int64_t type, const int64_t stride, const std::vector< double > &val)
void write_capacities(const std::vector< int64_t > &capacities) override
Definition: Accessor.hpp:6
io::ParaviewWriter ParaviewWriter