File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
components/simplicial_embedding/wmtk/components/simplicial_embedding/tests Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -20,5 +20,8 @@ TEST_CASE("write", "")
2020 // m.write_mesh("simplicial_embedding_out.vtu");
2121
2222 io::VTUWriter writer (m);
23+ writer.add_vertex_attribute (" position2" , [&m](int i) -> VectorXd {
24+ return m.vertex_attrs [i].pos ;
25+ });
2326 writer.write_triangles (" simplicial_embedding_out.vtu" );
2427}
Original file line number Diff line number Diff line change 11#pragma once
22
33#include < filesystem>
4+ #include < functional>
5+ #include < map>
46#include < paraviewo/VTUWriter.hpp>
57#include < wmtk/Types.hpp>
68
@@ -71,12 +73,40 @@ class VTUWriter
7173 for (int i = 0 ; i < VA.size (); ++i) {
7274 writer.add_field (VA_names[i], VA[i]);
7375 }
76+
77+ for (const auto & [name, attr] : m_vertex_attributes) {
78+ writer.add_field (name, attr);
79+ }
80+
7481 bool r = writer.write_mesh (filename.string (), V, F);
7582 return r;
7683 }
7784
85+ void add_vertex_attribute (const std::string& name, const std::function<VectorXd(const int )>& f)
86+ {
87+ const std::vector<Tuple> vertex_tuples = m_mesh.get_vertices ();
88+
89+ if (vertex_tuples.empty ()) {
90+ logger ().warn (" Cannot print mesh without vertices." );
91+ return ;
92+ }
93+
94+ MatrixXd attr;
95+ attr.resize (vertex_tuples.size (), f (0 ).size ());
96+
97+ // init V
98+ for (const Tuple& v : vertex_tuples) {
99+ const auto vid = v.vid (m_mesh);
100+ attr.row (vid) = f (vid);
101+ }
102+
103+ m_vertex_attributes[name] = attr;
104+ }
105+
78106private:
79107 MeshT& m_mesh;
108+
109+ std::map<std::string, MatrixXd> m_vertex_attributes;
80110};
81111
82112template <typename MeshT>
You can’t perform that action at this time.
0 commit comments