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(
32  const std::string& name,
33  const int64_t stride,
34  const std::vector<double>& val,
35  const bool is_cell_field);
36 
37 
38  Eigen::MatrixXd& vertices() { return m_vertices; }
39 
40  private:
41  std::string m_vertices_name;
42 
43  std::filesystem::path m_filename;
44 
45  bool m_enabled;
46 
47  std::shared_ptr<paraviewo::ParaviewWriter> m_paraview_file;
48 
49  Eigen::MatrixXd m_vertices;
50  Eigen::MatrixXi m_elements;
51  };
52 
53 public:
55  const std::filesystem::path& filename,
56  const std::string& vertices_name,
57  const Mesh& mesh,
58  bool write_points = true,
59  bool write_edges = true,
60  bool write_faces = true,
61  bool write_tetrahedra = true);
62 
63  bool write(const int dim) override { return dim == 0 || m_enabled[dim]; }
64 
65  void write_top_simplex_type(const PrimitiveType) override {}
66  void write_absolute_id(const std::vector<int64_t>& id) override
67  {
68  m_write = m_mm_level == 0;
69  ++m_mm_level;
70  }
71 
72  // paraview doesn't care about mesh capacities
73  void write_capacities(const std::vector<int64_t>& capacities) override {}
74 
75  void write(
76  const std::string& name,
77  const int64_t type,
78  const int64_t stride,
79  const std::vector<char>& val,
80  const char default_val) override;
81 
82  void write(
83  const std::string& name,
84  const int64_t type,
85  const int64_t stride,
86  const std::vector<int64_t>& val,
87  const int64_t default_val) override;
88 
89  void write(
90  const std::string& name,
91  const int64_t type,
92  const int64_t stride,
93  const std::vector<double>& val,
94  const double default_val) override;
95 
96  void write(
97  const std::string& name,
98  const int64_t type,
99  const int64_t stride,
100  const std::vector<Rational>& val,
101  const Rational& default_val) override;
102 
103 
104 private:
105  std::array<ParaviewInternalWriter, 4> m_writers;
106  std::array<bool, 4> m_enabled;
107  std::string m_vertices_name;
108  bool m_write;
109 
110  void write_internal(
111  const std::string& name,
112  const int64_t type,
113  const int64_t stride,
114  const std::vector<double>& val);
115 };
116 } // namespace io
117 
119 
120 } // namespace wmtk
int64_t m_mm_level
Definition: MeshWriter.hpp:51
std::shared_ptr< paraviewo::ParaviewWriter > m_paraview_file
void write(const std::string &name, const int64_t stride, const std::vector< double > &val, const bool is_cell_field)
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