Wildmeshing Toolkit
Loading...
Searching...
No Matches
History.hpp
1#pragma once
2
3#include "Fwd.hpp"
4
5#include <Eigen/Core>
6
7#include <array>
8#include <cstdint>
9#include <filesystem>
10#include <mutex>
11#include <string>
12#include <vector>
13
14namespace wmtk::history {
15
27enum class EditKind : uint8_t {
31 split_edge = 1,
34 split_face = 2,
38 collapse_edge = 3,
41 swap_edge = 4,
43 move_vertices = 5,
45 consolidate = 6,
51 replace_faces = 7,
59 relabel = 8,
65 embed = 9,
66};
67
69constexpr uint64_t kNoVertex = uint64_t(-1);
70
72{
73 uint64_t vid;
74 Eigen::Vector3d pos;
75};
76
78struct Edit
79{
80 EditKind kind;
81 std::vector<uint64_t> v;
82 std::vector<uint64_t> faces;
84 std::vector<VertexMove> moves;
85};
86
99template <int N>
101{
102 static_assert(N == 2 || N == 3, "a history is of triangles or of segments");
104 using Face = std::array<uint64_t, N>;
107 using Feature = std::array<uint64_t, N - 1>;
108
110 std::vector<Eigen::Vector3d> vertices;
111 std::vector<uint8_t> vertex_alive;
112 std::vector<Face> faces;
113 std::vector<uint8_t> face_alive;
124 std::vector<Feature> features;
125
126 std::vector<Edit> edits;
127
129 std::string metadata;
130
138 std::vector<uint64_t> output_vertex_ids;
145 std::vector<uint64_t> input_vertex_ids;
146
149 void save(const std::string& path) const;
150 static History load(const std::string& path);
152 std::vector<uint8_t> to_bytes() const;
153 static History from_bytes(const std::vector<uint8_t>& bytes);
154};
155
162std::vector<uint8_t> read_history(const std::filesystem::path& path);
165void write_history(const std::filesystem::path& path, const std::vector<uint8_t>& bytes);
166
169int face_size(const std::string& path);
170int face_size(const std::vector<uint8_t>& bytes);
171
177template <int N>
178bool append(History<N>& h, const History<N>& next);
179
187template <int N>
188void append_embedded(
189 History<N>& h,
190 const History<N>& next,
191 const std::vector<std::vector<uint64_t>>& sources);
192
204template <int N>
206{
207public:
208 explicit BasicRecorder(History<N> start);
209
210 void append(Edit&& e);
211
214 void rebase(std::vector<Eigen::Vector3d> positions);
215
217 const History<N>& history() const { return m_history; }
218 History<N>& history() { return m_history; }
219
220private:
221 std::mutex m_mutex;
222 History<N> m_history;
223 std::vector<Eigen::Vector3d> m_known;
224 std::vector<uint8_t> m_known_valid;
225};
226
227} // namespace wmtk::history
Collects the edits of operations that may commit concurrently.
Definition History.hpp:206
const History< N > & history() const
Not synchronised: read it once the recording mesh is done.
Definition History.hpp:217
void rebase(std::vector< Eigen::Vector3d > positions)
Definition History.cpp:260
The history types by name, for headers that only hold them (History.hpp defines them).
Definition BinaryIO.hpp:16
std::vector< uint8_t > read_history(const std::filesystem::path &path)
The bytes of a history file, as History::from_bytes takes them – or VolumeHistory::from_bytes,...
Definition History.cpp:426
void write_history(const std::filesystem::path &path, const std::vector< uint8_t > &bytes)
Definition History.cpp:439
EditKind
The kinds of edit a complex goes through.
Definition History.hpp:27
@ move_vertices
Only vertex positions change (smoothing, or a sweep outside any operation).
@ consolidate
Live vertices and faces renumbered by rank, in id order.
void append_embedded(History< N > &h, const History< N > &next, const std::vector< std::vector< uint64_t > > &sources)
h, then next, which starts on a complex lying on h's last state: the same surface or curves,...
Definition History.cpp:296
constexpr uint64_t kNoVertex
No vertex: in a relabel, the slot of one that goes.
Definition History.hpp:69
bool append(History< N > &h, const History< N > &next)
The history of a pipeline: h, then next, which starts where h ends – the same complex,...
Definition History.cpp:268
One committed operation.
Definition History.hpp:79
std::vector< VertexMove > moves
The position, after the operation, of every live vertex it wrote.
Definition History.hpp:84
A complex and the edits it went through, in commit order.
Definition History.hpp:101
std::array< uint64_t, N > Face
A face's corners: a triangle's three, a segment's two.
Definition History.hpp:104
std::vector< uint64_t > output_vertex_ids
Definition History.hpp:138
std::array< uint64_t, N - 1 > Feature
Definition History.hpp:107
std::vector< uint64_t > input_vertex_ids
Definition History.hpp:145
std::string metadata
Free-form text saved with the history; the recording application's parameters, say.
Definition History.hpp:129
std::vector< Eigen::Vector3d > vertices
The snapshot: every vertex and face slot, live or not.
Definition History.hpp:110
void save(const std::string &path) const
Definition History.cpp:323
std::vector< Feature > features
Definition History.hpp:124
std::vector< uint8_t > to_bytes() const
The bytes of a history file, in memory: what a component's memory route returns.
Definition History.cpp:341
Definition History.hpp:72