Wildmeshing Toolkit
Loading...
Searching...
No Matches
VolumeHistory.hpp
1#pragma once
2
3#include "History.hpp"
4
5#include <Eigen/Core>
6
7#include <array>
8#include <cstdint>
9#include <map>
10#include <memory>
11#include <mutex>
12#include <optional>
13#include <string>
14#include <vector>
15
16namespace wmtk::history {
17
19enum class VolumeOp : uint8_t {
20 collapse = 0,
21 swap_32 = 1,
22 swap_44 = 2,
23 swap_56 = 3,
24 swap_23 = 4,
25 smooth = 5,
26};
27
39{
40 VolumeOp op = VolumeOp::collapse;
42 uint64_t first_edit = 0;
43 uint64_t n_edits = 0;
47 std::vector<uint64_t> vertices;
48 std::vector<Eigen::Vector3d> positions;
49 std::vector<uint64_t> surface_before, surface_after;
51 std::vector<std::pair<uint32_t, Eigen::Vector3d>> moved;
54 std::vector<std::array<uint32_t, 4>> tets;
55 std::vector<uint32_t> regions;
57 std::vector<uint32_t> removed;
58 std::vector<std::array<uint32_t, 4>> added;
59 std::vector<uint32_t> added_regions;
61 std::vector<uint32_t> op_vertices;
62
64 std::vector<std::array<uint32_t, 4>> tets_after(
65 std::vector<uint32_t>* regions_after = nullptr) const;
67 std::vector<Eigen::Vector3d> positions_after() const;
68};
69
73{
74 uint64_t edits = 0;
75 uint64_t hash = 0;
76 bool operator==(const SurfaceKey& o) const { return edits == o.edits && hash == o.hash; }
77 bool operator!=(const SurfaceKey& o) const { return !(*this == o); }
78};
82
89{
91 std::vector<std::vector<int64_t>> regions;
95 std::map<int64_t, std::string> tag_names;
97 std::vector<VolumeEdit> edits;
103 std::optional<SurfaceKey> surface;
104
108 void save(const std::string& path) const;
109 static VolumeHistory load(const std::string& path);
110 std::vector<uint8_t> to_bytes() const;
111 static VolumeHistory from_bytes(const std::vector<uint8_t>& bytes);
112};
113
118 const std::vector<uint8_t>& bytes,
119 const std::string& name = "the history given");
120
124{
125 std::vector<std::array<size_t, 4>> tets;
126 std::vector<std::vector<int64_t>> tags;
127 std::vector<size_t> vertices;
128 std::vector<Eigen::Vector3d> positions;
129 std::vector<uint64_t> surface;
130};
131
142{
143public:
146
147 using Capture = VolumeCapture;
148 void commit(
149 VolumeOp op,
150 std::array<size_t, 2> surface_edits,
151 const std::vector<size_t>& op_vertices,
152 const Capture& before,
153 const Capture& after);
154
156 void renumber(const std::vector<size_t>& old_to_new);
157
159 VolumeHistory history() const;
163 std::vector<uint8_t> to_bytes(
164 uint64_t surface_edit_offset,
165 const SurfaceKey& surface,
166 const std::map<int64_t, std::string>& tag_names) const;
168 size_t size() const;
169 size_t bytes() const;
170
171private:
173 uint32_t region_of(const std::vector<int64_t>& tags);
174
175 mutable std::mutex m_mutex;
176 std::vector<std::vector<int64_t>> m_regions;
178 std::vector<uint64_t> m_id_of;
179 uint64_t m_next_id = 0;
181 std::vector<uint8_t> m_bytes;
182 size_t m_count = 0;
183 struct Encoder;
184 std::unique_ptr<Encoder> m_encoder;
185};
186
187} // namespace wmtk::history
Records a VolumeHistory alongside a TrackedSurfaceRecorder. An operation captures the tets around it ...
Definition VolumeHistory.hpp:142
void renumber(const std::vector< size_t > &old_to_new)
The mesh renumbered its vertices: old_to_new[v], size_t(-1) for a vertex gone.
Definition VolumeHistory.cpp:647
std::vector< uint8_t > m_bytes
The edits, encoded in the order they came (see VolumeHistory.cpp).
Definition VolumeHistory.hpp:181
VolumeHistory history() const
What was recorded, decoded, sorted by surface edit.
Definition VolumeHistory.cpp:661
std::vector< uint8_t > to_bytes(uint64_t surface_edit_offset, const SurfaceKey &surface, const std::map< int64_t, std::string > &tag_names) const
Definition VolumeHistory.cpp:675
size_t size() const
The edits recorded, and the bytes they take.
Definition VolumeHistory.cpp:688
uint32_t region_of(const std::vector< int64_t > &tags)
The region of a set of tags, sorted, each once; a new one if it is new. Under the lock.
Definition VolumeHistory.cpp:559
std::vector< uint64_t > m_id_of
Mesh vertex -> the recorder's id of it.
Definition VolumeHistory.hpp:178
The history types by name, for headers that only hold them (History.hpp defines them).
Definition BinaryIO.hpp:16
bool is_volume_history(const std::vector< uint8_t > &bytes, const std::string &name)
Definition VolumeHistory.cpp:422
SurfaceKey surface_key(const SurfaceHistory &h)
Definition VolumeHistory.cpp:440
VolumeOp
The tet operations a volume history records.
Definition VolumeHistory.hpp:19
A complex and the edits it went through, in commit order.
Definition History.hpp:101
Definition VolumeHistory.hpp:73
Definition VolumeHistory.hpp:124
One operation that changed the tracked surface of a tet mesh, as the tets around it saw it: the tets ...
Definition VolumeHistory.hpp:39
std::vector< uint32_t > op_vertices
collapse: {removed, kept}; smooth: {the vertex}; swaps: none.
Definition VolumeHistory.hpp:61
std::vector< std::array< uint32_t, 4 > > tets
Definition VolumeHistory.hpp:54
std::vector< uint32_t > removed
After it: those tets but removed (indices into tets), and added.
Definition VolumeHistory.hpp:57
std::vector< std::pair< uint32_t, Eigen::Vector3d > > moved
The vertices the operation moved, and where to.
Definition VolumeHistory.hpp:51
std::vector< Eigen::Vector3d > positions_after() const
The positions after the operation.
Definition VolumeHistory.cpp:492
uint64_t first_edit
The surface history's edits the operation made: [first_edit, first_edit + n_edits).
Definition VolumeHistory.hpp:42
std::vector< std::array< uint32_t, 4 > > tets_after(std::vector< uint32_t > *regions_after=nullptr) const
The tets after the operation, with their regions.
Definition VolumeHistory.cpp:473
std::vector< uint64_t > vertices
Definition VolumeHistory.hpp:47
The tets around every operation that changed a tet mesh's tracked surface, which, with the surface hi...
Definition VolumeHistory.hpp:89
std::vector< std::vector< int64_t > > regions
The regions, each the set of tags of its tets, sorted.
Definition VolumeHistory.hpp:91
uint64_t surface_edit_offset
Definition VolumeHistory.hpp:100
std::vector< VolumeEdit > edits
In the order of the surface edits they made.
Definition VolumeHistory.hpp:97
std::optional< SurfaceKey > surface
Definition VolumeHistory.hpp:103
void save(const std::string &path) const
Definition VolumeHistory.cpp:538
std::map< int64_t, std::string > tag_names
Definition VolumeHistory.hpp:95
Definition VolumeHistory.cpp:549