Wildmeshing Toolkit
Loading...
Searching...
No Matches
CurveMap.hpp
1#pragma once
2
3#include "SurfaceMap.hpp"
4
5#include <wmtk/history/History.hpp>
6
7#include <Eigen/Core>
8
9#include <array>
10#include <cstdint>
11#include <utility>
12#include <vector>
13
14namespace wmtk::components::tracking {
15
19{
20 uint64_t segment;
21 Eigen::Vector2d bary;
22};
23
26{
30 size_t topology = 0;
33 size_t merged_segments = 0;
36 size_t overlapping = 0;
39 size_t unlocated = 0;
42 size_t replaced = 0;
43
44 size_t total() const { return topology + merged_segments + overlapping + unlocated + replaced; }
45};
46
49{
54 Smoothing smoothing = Smoothing::flatten;
55};
56
75{
76public:
77 explicit CurveMap(const history::CurveHistory& h, const CurveMapOptions& options = {});
78
81 std::vector<CurvePoint> to_input(
82 std::vector<CurvePoint> points,
83 CurveMapWarnings* warnings = nullptr) const;
85 std::vector<CurvePoint> to_output(
86 std::vector<CurvePoint> points,
87 CurveMapWarnings* warnings = nullptr) const;
88
90 const CurveMapWarnings& build_warnings() const { return m_build_warnings; }
92 const std::vector<size_t>& warned_edits() const { return m_warned_edits; }
93
95 const std::vector<Eigen::Vector3d>& input_vertices() const { return m_in_vertices; }
96 const std::vector<std::array<uint64_t, 2>>& input_segments() const { return m_in_segments; }
97 const std::vector<uint8_t>& input_segment_alive() const { return m_in_alive; }
98 const std::vector<Eigen::Vector3d>& output_vertices() const { return m_out_vertices; }
99 const std::vector<std::array<uint64_t, 2>>& output_segments() const { return m_out_segments; }
100 const std::vector<uint8_t>& output_segment_alive() const { return m_out_alive; }
101
105 const std::vector<std::array<uint64_t, 2>>& feature_points() const { return m_features; }
107 const std::vector<uint64_t>& output_feature_points() const { return m_out_features; }
108
110 const std::array<size_t, 16>& steps_by_kind() const { return m_steps_by_kind; }
111
112private:
114 struct Chain
115 {
116 std::vector<uint64_t> segments;
117 std::vector<uint8_t> forward;
120 std::vector<double> start, length;
121 double total = 0;
122 };
128 static void measure(Chain& c);
131 struct Image
132 {
133 uint64_t segment;
134 bool flipped;
135 };
137 using Place = std::pair<uint32_t, uint32_t>;
138 struct Step
139 {
144 std::vector<std::pair<Chain, Chain>> chains;
145 std::vector<std::pair<uint64_t, Place>> before_at, after_at;
148 std::vector<std::pair<uint64_t, Image>> forward, backward;
150 std::vector<Image> old_to_new, new_to_old;
154 std::vector<std::array<Eigen::Vector3d, 2>> before, after;
155 std::vector<std::vector<uint64_t>> to_after, to_before;
156 };
157
158 void build_local(history::CurveReplay& r, const history::Edit& e, Step& step, bool flatten);
159 void build_renumbering(history::CurveReplay& r, const history::Edit& e, Step& step);
160 void build_embed(history::CurveReplay& r, const history::Edit& e, Step& step);
161 void build_replace(history::CurveReplay& r, const history::Edit& e, Step& step);
162
164 static bool forward(const Step& s, CurvePoint& p);
165 static bool backward(const Step& s, CurvePoint& p);
168 void map(std::vector<CurvePoint>& points, bool to_output, CurveMapWarnings& warnings) const;
170 static CurvePoint
171 along(const Chain& from, size_t i, const Eigen::Vector2d& bary, const Chain& to);
172
173 std::vector<Step> m_steps;
174 CurveMapWarnings m_build_warnings;
175 std::vector<size_t> m_warned_edits;
176 std::vector<Eigen::Vector3d> m_in_vertices, m_out_vertices;
177 std::vector<std::array<uint64_t, 2>> m_in_segments, m_out_segments;
178 std::vector<uint8_t> m_in_alive, m_out_alive;
179 std::vector<std::array<uint64_t, 2>> m_features;
180 std::vector<uint64_t> m_out_features;
181 std::array<size_t, 16> m_steps_by_kind = {};
182};
183
184} // namespace wmtk::components::tracking
The map between the first and the last state of a CurveHistory.
Definition CurveMap.hpp:75
const std::array< size_t, 16 > & steps_by_kind() const
How many operations needed a local map, by kind (index: history::EditKind).
Definition CurveMap.hpp:110
std::vector< CurvePoint > to_input(std::vector< CurvePoint > points, CurveMapWarnings *warnings=nullptr) const
Definition CurveMap.cpp:813
const std::vector< std::array< uint64_t, 2 > > & feature_points() const
Definition CurveMap.hpp:105
const CurveMapWarnings & build_warnings() const
What building the map found.
Definition CurveMap.hpp:90
const std::vector< uint64_t > & output_feature_points() const
The feature points of the last state.
Definition CurveMap.hpp:107
const std::vector< size_t > & warned_edits() const
The edits (indices into the history) whose local map raised a build warning.
Definition CurveMap.hpp:92
std::vector< CurvePoint > to_output(std::vector< CurvePoint > points, CurveMapWarnings *warnings=nullptr) const
Points on the first state, mapped onto the last; see to_input.
Definition CurveMap.cpp:803
static void measure(Chain &c)
Definition CurveMap.cpp:614
static bool forward(const Step &s, CurvePoint &p)
One point through one step, or back; false if it has no image.
Definition CurveMap.cpp:658
std::pair< uint32_t, uint32_t > Place
Where a segment is on a step's chains: the pair, and its place on the chain.
Definition CurveMap.hpp:137
static CurvePoint along(const Chain &from, size_t i, const Eigen::Vector2d &bary, const Chain &to)
The point at the same fraction of arc length along to as bary on segment i of from.
Definition CurveMap.cpp:645
const std::vector< Eigen::Vector3d > & input_vertices() const
The curves at the start and at the end, every slot, as the history holds them.
Definition CurveMap.hpp:95
void map(std::vector< CurvePoint > &points, bool to_output, CurveMapWarnings &warnings) const
Definition CurveMap.cpp:749
A complex driven by the edits of a History: a surface (N = 3) or a curve network (N = 2).
Definition Replay.hpp:23
EditKind
The kinds of edit a complex goes through.
Definition History.hpp:27
A polyline: segments end to end, each run from its first corner to its second or back.
Definition CurveMap.hpp:115
std::vector< double > start
Definition CurveMap.hpp:120
std::vector< std::pair< Chain, Chain > > chains
Definition CurveMap.hpp:144
std::vector< std::array< Eigen::Vector3d, 2 > > before
Definition CurveMap.hpp:154
std::vector< Image > old_to_new
consolidate, relabel: every segment's new id, and back; any other has none.
Definition CurveMap.hpp:150
std::vector< std::pair< uint64_t, Image > > forward
Definition CurveMap.hpp:148
How a CurveMap is built.
Definition CurveMap.hpp:49
Smoothing smoothing
Definition CurveMap.hpp:54
Where a curve map stops being a bijection. Counted, never fatal: the map still answers.
Definition CurveMap.hpp:26
size_t unlocated
Definition CurveMap.hpp:39
size_t overlapping
Definition CurveMap.hpp:36
size_t merged_segments
Definition CurveMap.hpp:33
size_t replaced
Definition CurveMap.hpp:42
size_t topology
Definition CurveMap.hpp:30
Definition CurveMap.hpp:19
One committed operation.
Definition History.hpp:79
A complex and the edits it went through, in commit order.
Definition History.hpp:101