Wildmeshing Toolkit
Loading...
Searching...
No Matches
TrackedRecorder.hpp
1#pragma once
2
3#include "History.hpp"
4#include "Replay.hpp"
5
6#include <Eigen/Core>
7
8#include <array>
9#include <cstdint>
10#include <functional>
11#include <mutex>
12#include <optional>
13#include <vector>
14
15namespace wmtk::history {
16
40template <int N>
42{
43public:
45 using Cell = std::array<size_t, N>;
47 using MeshFeature = std::array<size_t, N - 1>;
48 using Positions = std::function<Eigen::Vector3d(size_t)>;
50 using Orient = std::function<Cell(const Cell&)>;
51
57 const std::vector<Cell>& faces,
58 Positions position,
59 Orient orient,
60 const std::vector<MeshFeature>& features = {});
61
64 std::vector<MeshFeature> features() const;
67 std::vector<uint64_t> mesh_vertex_ids() const;
68
70 struct Change
71 {
75 std::vector<size_t> v;
78 std::vector<Cell> before, after;
81 std::vector<size_t> written;
82 };
85 std::array<size_t, 2> commit(Change&& c);
86
88 void renumber(const std::vector<size_t>& old_to_new);
89
93 size_t resync(const std::vector<Cell>& faces);
94
96 struct Stats
97 {
98 size_t split = 0, collapse = 0, swap = 0, move = 0;
101 size_t weld = 0;
103 size_t replaced = 0;
105 size_t unknown = 0;
106 };
107 Stats stats() const;
108
110 const History<N>& history() const { return m_history; }
111 History<N>& history() { return m_history; }
113 const BasicReplay<N>& complex() const { return m_replay; }
114
117 std::optional<uint64_t> face_id(const Cell& t) const;
119 std::optional<uint64_t> vertex_id(size_t v) const;
122 std::vector<uint64_t> vertex_ids(const std::vector<size_t>& vs) const;
123
124private:
125 static constexpr uint64_t kNone = uint64_t(-1);
126
127 std::optional<uint64_t> live(size_t v) const;
128 std::optional<uint64_t> lookup(const Cell& t) const;
129 uint64_t fresh_vertex(size_t v);
130 std::optional<Edit> as_split(
131 const Change& c,
132 const std::vector<Cell>& before,
133 const std::vector<Cell>& removed,
134 const std::vector<Cell>& added,
135 std::vector<uint64_t>& fresh);
136 std::optional<Edit>
137 as_collapse(Change& c, const std::vector<Cell>& before, const std::vector<Cell>& after);
138 std::optional<Edit> as_swap(const std::vector<Cell>& removed, const std::vector<Cell>& added);
140 void record(Edit&& e, const std::vector<size_t>& written, const std::vector<uint64_t>& fresh);
143 const std::vector<Cell>& removed,
144 const std::vector<Cell>& added,
145 std::vector<uint64_t>& fresh);
146
147 mutable std::mutex m_mutex;
148 Positions m_position;
149 Orient m_orient;
152 std::vector<uint64_t> m_complex_of;
153 std::vector<size_t> m_mesh_of;
154 History<N> m_history;
155 BasicReplay<N> m_replay;
157 std::vector<Eigen::Vector3d> m_known;
158 uint64_t m_next_face = 0;
159 Stats m_stats;
160};
161
162} // namespace wmtk::history
A complex driven by the edits of a History: a surface (N = 3) or a curve network (N = 2).
Definition Replay.hpp:23
Records a tracked complex: some of the faces of a mesh, or some of its edges, which the mesh gives no...
Definition TrackedRecorder.hpp:42
Edit replacement(const std::vector< Cell > &removed, const std::vector< Cell > &added, std::vector< uint64_t > &fresh)
The replace_faces edit taking away removed and adding added (mesh ids, sorted).
Definition TrackedRecorder.cpp:323
std::function< Cell(const Cell &)> Orient
A tracked face's corners, in the order that orients it.
Definition TrackedRecorder.hpp:50
const History< N > & history() const
Not synchronised: read once the mesh is done.
Definition TrackedRecorder.hpp:110
std::optional< uint64_t > face_id(const Cell &t) const
Definition TrackedRecorder.cpp:437
size_t resync(const std::vector< Cell > &faces)
Definition TrackedRecorder.cpp:409
std::vector< MeshFeature > features() const
Definition TrackedRecorder.cpp:136
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 TrackedRecorder.cpp:392
std::vector< uint64_t > m_complex_of
Definition TrackedRecorder.hpp:152
std::array< size_t, N > Cell
A face by mesh vertex ids.
Definition TrackedRecorder.hpp:45
std::vector< uint64_t > mesh_vertex_ids() const
Definition TrackedRecorder.cpp:126
const BasicReplay< N > & complex() const
The complex as it is now.
Definition TrackedRecorder.hpp:113
std::vector< uint64_t > vertex_ids(const std::vector< size_t > &vs) const
Definition TrackedRecorder.cpp:449
std::vector< Eigen::Vector3d > m_known
The last position recorded for each vertex of the complex.
Definition TrackedRecorder.hpp:157
std::array< size_t, 2 > commit(Change &&c)
Definition TrackedRecorder.cpp:357
void record(Edit &&e, const std::vector< size_t > &written, const std::vector< uint64_t > &fresh)
Records e – applies it, then the moves of written and of fresh vertices.
Definition TrackedRecorder.cpp:192
std::optional< uint64_t > vertex_id(size_t v) const
The vertex of the complex a mesh vertex is, if it is on it. Not synchronised.
Definition TrackedRecorder.cpp:443
std::array< size_t, N - 1 > MeshFeature
A feature by mesh vertex ids.
Definition TrackedRecorder.hpp:47
The history types by name, for headers that only hold them (History.hpp defines them).
Definition BinaryIO.hpp:16
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).
One committed operation.
Definition History.hpp:79
A complex and the edits it went through, in commit order.
Definition History.hpp:101
What an operation did to the tracked complex, as the mesh saw it at its commit point.
Definition TrackedRecorder.hpp:71
EditKind kind
split_edge, collapse_edge, swap_edge (for every kind of swap) or move_vertices.
Definition TrackedRecorder.hpp:73
std::vector< size_t > v
split_edge: {v0, v1, new}; collapse_edge: {removed, kept}; otherwise empty.
Definition TrackedRecorder.hpp:75
std::vector< Cell > before
Definition TrackedRecorder.hpp:78
std::vector< size_t > written
Definition TrackedRecorder.hpp:81
How the commits were recorded.
Definition TrackedRecorder.hpp:97
size_t replaced
Changes no edit fitted, recorded as they are.
Definition TrackedRecorder.hpp:103
size_t weld
Definition TrackedRecorder.hpp:101
size_t unknown
Faces the mesh reported gone that the recorder did not know: it had lost track.
Definition TrackedRecorder.hpp:105