Wildmeshing Toolkit
Loading...
Searching...
No Matches
output_conversion.hpp
1#pragma once
2#include <wmtk/TetMesh.h>
3#include <type_traits>
4#include <wmtk/io/tagged_mesh_data.hpp>
5
6namespace wmtk::components::topological_offset {
7template <typename Mesh>
8void collect_memory_output(
9 Mesh& mesh,
10 io::ComponentIO& context,
11 io::OutputKeys keys = io::default_output_keys())
12{
13 // In 2D, `_surf` is the envelope curve itself, which is returned as `envelope` below.
14 if constexpr (!std::is_base_of_v<TetMesh, Mesh>) keys["mesh_surf.vtu"] = "";
15 MeshMap raw;
16 mesh.write_vtu("mesh", &raw);
17 // The stencil file (3D, DEBUG_stencil, a mesh with an offset potential and a front): one point
18 // per stencil point of every offset face, indexed by those points, not by the mesh's vertex
19 // slots, so compact_slot_outputs() cannot remap it ("Export references an inactive vertex":
20 // every run of the 2026-10-29 sonic sweep aborted there). A debug-frame diagnostic, not a
21 // result.
22 raw.erase("mesh_stencil.vtu");
23 if constexpr (std::is_base_of_v<TetMesh, Mesh>) io::compact_slot_outputs(mesh, raw);
24 context.result.first = io::named_outputs(std::move(raw), keys);
25 auto& data = context.result.first.at("mesh");
26 if constexpr (std::is_base_of_v<TetMesh, Mesh>) {
27 io::collect_tags(
28 mesh,
29 context.result.first,
30 CellType::Tetrahedron,
31 mesh.get_tets(),
32 [&](const auto& t) -> const auto& { return mesh.m_tet_attribute[t.tid(mesh)].tag; });
33 io::collect_face_tags(mesh, context.result.first, mesh.m_face_tag_names);
34 } else {
35 io::collect_tags(
36 mesh,
37 context.result.first,
38 CellType::Triangle,
39 mesh.get_faces(),
40 [&](const auto& t) -> const auto& { return mesh.m_face_attribute[t.fid(mesh)].tags; });
41 }
42 if (mesh.m_offset_params.save_offset_correspondence) {
43 const auto ids = data.vertex_attributes.at("vid").integers();
44 DataMatrix<int64_t> correspondence(data.V.rows(), 1);
45 for (Eigen::Index i = 0; i < ids.rows(); ++i)
46 correspondence(i, 0) = mesh.m_vertex_extra[ids(i, 0)].m_corr_input_vid;
47 data.vertex_attributes["corr_input_vid"].values = std::move(correspondence);
48 data.vertex_attributes["vid"].values = ids;
49 }
50 if (mesh.m_has_envelope) {
51 context.result.first["envelope"] = io::geometry_data(
52 mesh.m_V_envelope,
53 mesh.m_F_envelope,
54 std::is_base_of_v<TetMesh, Mesh> ? CellType::Triangle : CellType::Edge);
55 }
56 data.validate();
57}
58} // namespace wmtk::components::topological_offset