Wildmeshing Toolkit
Loading...
Searching...
No Matches
tracking.hpp
1#pragma once
2
3#include "CurveMap.hpp"
4#include "SurfaceMap.hpp"
5#include "VolumeMap.hpp"
6#include "volume_io.hpp"
7
8#include <wmtk/history/History.hpp>
9
10#include <Eigen/Core>
11#include <nlohmann/json.hpp>
12#include <wmtk/MeshData.hpp>
13
14#include <array>
15#include <cstdint>
16#include <limits>
17#include <map>
18#include <memory>
19#include <optional>
20#include <string>
21#include <vector>
22
23namespace wmtk::components::tracking {
24
26constexpr uint64_t kNoId = std::numeric_limits<uint64_t>::max();
27
39{
41 uint64_t face = kNoId;
42 Eigen::Vector3d bary = Eigen::Vector3d::Constant(1. / 3);
45 std::array<uint64_t, 3> vertices = {{kNoId, kNoId, kNoId}};
46};
47
58{
60 uint64_t face = kNoId;
62 std::array<uint64_t, 3> vertices = {{kNoId, kNoId, kNoId}};
63 Eigen::Vector3d bary = Eigen::Vector3d::Constant(1. / 3);
64};
65
76{
77public:
78 explicit Tracking(const history::SurfaceHistory& h, const SurfaceMapOptions& options = {});
80 static Tracking load(const std::string& path, const SurfaceMapOptions& options = {});
81
83 bool output_by_vertices() const { return !m_output.ids.empty(); }
86 bool input_by_vertices() const { return !m_input.ids.empty(); }
87
90 std::vector<OutputPoint> to_output(
91 const std::vector<InputPoint>& points,
92 MapWarnings* warnings = nullptr) const;
96 std::vector<InputPoint> to_input(
97 const std::vector<OutputPoint>& points,
98 MapWarnings* warnings = nullptr) const;
99
102 std::vector<std::array<uint64_t, 3>> output_triangles() const;
103
107 std::vector<std::array<uint64_t, 3>> input_triangles() const;
108
110 const std::vector<std::array<uint64_t, 3>>& input_faces() const { return m_map.input_faces(); }
111 const SurfaceMap& map() const { return m_map; }
112
113private:
116 struct Naming
117 {
118 std::vector<uint64_t> ids;
119 std::map<uint64_t, uint64_t> history_vertex;
120 };
124 const Naming& naming,
125 const std::vector<std::array<uint64_t, 3>>& faces,
126 const std::map<std::array<uint64_t, 3>, uint64_t>& face_of,
127 const std::array<uint64_t, 3>& vertices,
128 const Eigen::Vector3d& bary);
130 static std::map<std::array<uint64_t, 3>, uint64_t> faces_by_corners(
131 const std::vector<std::array<uint64_t, 3>>& faces,
132 const std::vector<uint8_t>& alive);
134 static std::vector<std::array<uint64_t, 3>> triangles(
135 const Naming& naming,
136 const std::vector<std::array<uint64_t, 3>>& faces,
137 const std::vector<uint8_t>& alive);
138
139 SurfaceMap m_map;
142 Naming m_output, m_input;
145 std::map<std::array<uint64_t, 3>, uint64_t> m_output_face_of, m_input_face_of;
146};
147
152{
153 uint64_t segment = kNoId;
154 Eigen::Vector2d bary = Eigen::Vector2d::Constant(0.5);
155};
156
166{
168 uint64_t segment = kNoId;
170 std::array<uint64_t, 2> vertices = {{kNoId, kNoId}};
171 Eigen::Vector2d bary = Eigen::Vector2d::Constant(0.5);
172};
173
178{
179 uint64_t input_vertex = kNoId;
180 uint64_t output_vertex = kNoId;
181};
182
193{
194public:
195 explicit CurveTracking(const history::CurveHistory& h, const CurveMapOptions& options = {});
197 static CurveTracking load(const std::string& path, const CurveMapOptions& options = {});
198
201 bool output_by_vertices() const { return !m_output_ids.empty(); }
202
205 std::vector<OutputCurvePoint> to_output(
206 const std::vector<InputCurvePoint>& points,
207 CurveMapWarnings* warnings = nullptr) const;
210 std::vector<InputCurvePoint> to_input(
211 const std::vector<OutputCurvePoint>& points,
212 CurveMapWarnings* warnings = nullptr) const;
213
216 std::vector<std::array<uint64_t, 2>> output_segments() const;
218 const std::vector<std::array<uint64_t, 2>>& input_segments() const
219 {
220 return m_map.input_segments();
221 }
223 std::vector<FeaturePoint> feature_points() const;
224 const CurveMap& map() const { return m_map; }
225
226private:
227 CurveMap m_map;
229 std::vector<uint64_t> m_output_ids;
231 std::map<uint64_t, uint64_t> m_history_vertex;
232};
233
235nlohmann::json warnings_report(const MapWarnings& w);
236nlohmann::json warnings_report(const CurveMapWarnings& w);
239nlohmann::json stats_report(const VolumeMapStats& s);
240
244{
245 uint64_t tet = kNoId;
246 Eigen::Vector4d bary = Eigen::Vector4d::Constant(0.25);
247};
248
270{
271public:
276 const history::SurfaceHistory& surface,
278 const MeshData& input_mesh,
279 const MeshData& output_mesh,
280 const VolumeMapOptions& options = {});
283 const history::SurfaceHistory& surface,
285 const VolumeMapOptions& options = {});
287 static VolumeTracking load(
288 const std::string& surface_history,
289 const std::string& volume_history,
290 const std::string& input_mesh,
291 const std::string& output_mesh,
292 const VolumeMapOptions& options = {});
293
295 bool has_meshes() const { return m_in.has_value(); }
297 std::vector<TetPoint> to_output(const std::vector<TetPoint>& points) const;
299 std::vector<TetPoint> to_input(const std::vector<TetPoint>& points) const;
305 std::vector<VolumePoint> map_positions(
306 const std::vector<Eigen::Vector3d>& positions,
307 bool forward,
308 const std::vector<uint32_t>& regions = {}) const;
309
310 const VolumeMap& map() const { return *m_map; }
312 const TetMeshData& input_mesh() const;
313 const TetMeshData& output_mesh() const;
314
315private:
316 std::vector<TetPoint> map_points(const std::vector<TetPoint>& points, bool forward) const;
317
318 // Shared, all of it, by a copy: the map and the meshes are not changed by mapping.
319 std::shared_ptr<const VolumeMap> m_map;
320 std::optional<TetLocator> m_in, m_out;
321};
322
325void tracking(nlohmann::json json_params);
339ComponentResult tracking(nlohmann::json json_params, const MeshMap& meshes);
340
341} // namespace wmtk::components::tracking
The map between the first and the last state of a CurveHistory.
Definition CurveMap.hpp:75
The map between a curve application's input curves and its output's, read from the tracking file the ...
Definition tracking.hpp:193
std::vector< InputCurvePoint > to_input(const std::vector< OutputCurvePoint > &points, CurveMapWarnings *warnings=nullptr) const
Definition tracking.cpp:223
std::map< uint64_t, uint64_t > m_history_vertex
Output vertex -> vertex of the last state.
Definition tracking.hpp:231
std::vector< uint64_t > m_output_ids
The output's id of each vertex of the history's last state; empty for a curve output.
Definition tracking.hpp:229
std::vector< std::array< uint64_t, 2 > > output_segments() const
Definition tracking.cpp:181
std::vector< OutputCurvePoint > to_output(const std::vector< InputCurvePoint > &points, CurveMapWarnings *warnings=nullptr) const
Definition tracking.cpp:196
static CurveTracking load(const std::string &path, const CurveMapOptions &options={})
The tracking file an application wrote.
Definition tracking.cpp:176
bool output_by_vertices() const
Definition tracking.hpp:201
std::vector< FeaturePoint > feature_points() const
The input's feature points and where each ended (see FeaturePoint).
Definition tracking.cpp:266
const std::vector< std::array< uint64_t, 2 > > & input_segments() const
The segments of the input files, in order, as the history holds them.
Definition tracking.hpp:218
The map between the first and the last state of a SurfaceHistory.
Definition SurfaceMap.hpp:106
The map between an application's input and its output, read from the tracking file the application wr...
Definition tracking.hpp:76
const std::vector< std::array< uint64_t, 3 > > & input_faces() const
The triangles of the input files, in order, as the history holds them.
Definition tracking.hpp:110
std::vector< std::array< uint64_t, 3 > > output_triangles() const
Definition tracking.cpp:90
std::map< std::array< uint64_t, 3 >, uint64_t > m_output_face_of
Definition tracking.hpp:145
static std::vector< std::array< uint64_t, 3 > > triangles(const Naming &naming, const std::vector< std::array< uint64_t, 3 > > &faces, const std::vector< uint8_t > &alive)
The live faces of a side, by the naming's vertex ids if it has them.
Definition tracking.cpp:46
static std::map< std::array< uint64_t, 3 >, uint64_t > faces_by_corners(const std::vector< std::array< uint64_t, 3 > > &faces, const std::vector< uint8_t > &alive)
The live faces by their sorted corners.
Definition tracking.cpp:32
bool output_by_vertices() const
Whether output points are named by vertex triplets (a tet output) rather than triangles.
Definition tracking.hpp:83
std::vector< OutputPoint > to_output(const std::vector< InputPoint > &points, MapWarnings *warnings=nullptr) const
Definition tracking.cpp:100
std::vector< InputPoint > to_input(const std::vector< OutputPoint > &points, MapWarnings *warnings=nullptr) const
Definition tracking.cpp:132
Naming m_output
Definition tracking.hpp:142
std::vector< std::array< uint64_t, 3 > > input_triangles() const
Definition tracking.cpp:95
static SurfacePoint by_vertices(const Naming &naming, const std::vector< std::array< uint64_t, 3 > > &faces, const std::map< std::array< uint64_t, 3 >, uint64_t > &face_of, const std::array< uint64_t, 3 > &vertices, const Eigen::Vector3d &bary)
Definition tracking.cpp:63
bool input_by_vertices() const
Definition tracking.hpp:86
static Tracking load(const std::string &path, const SurfaceMapOptions &options={})
The tracking file an application wrote.
Definition tracking.cpp:27
The map of a tet mesh's volume between the mesh its volume history starts from and the one it ends at...
Definition tracking.hpp:270
static VolumeTracking load(const std::string &surface_history, const std::string &volume_history, const std::string &input_mesh, const std::string &output_mesh, const VolumeMapOptions &options={})
The files an application wrote: the two histories and the two meshes.
Definition tracking.cpp:336
std::vector< TetPoint > to_input(const std::vector< TetPoint > &points) const
Points of the output mesh to the input mesh, the inverse map. Throws without the meshes.
Definition tracking.cpp:387
std::vector< TetPoint > to_output(const std::vector< TetPoint > &points) const
Points of the input mesh to the output mesh. Throws without the meshes.
Definition tracking.cpp:382
std::vector< VolumePoint > map_positions(const std::vector< Eigen::Vector3d > &positions, bool forward, const std::vector< uint32_t > &regions={}) const
Definition tracking.cpp:363
const TetMeshData & input_mesh() const
The meshes; they throw without them.
Definition tracking.cpp:351
bool has_meshes() const
Whether it has the meshes, which TetPoints are of.
Definition tracking.hpp:295
Definition MeshData.hpp:48
How a CurveMap is built.
Definition CurveMap.hpp:49
Where a curve map stops being a bijection. Counted, never fatal: the map still answers.
Definition CurveMap.hpp:26
Definition tracking.hpp:178
A point on an application's input.
Definition tracking.hpp:39
uint64_t face
Histories from input files: the input triangle.
Definition tracking.hpp:41
std::array< uint64_t, 3 > vertices
Definition tracking.hpp:45
Where a map stops being a bijection. Counted, never fatal: the map still answers.
Definition SurfaceMap.hpp:24
A point on an application's output curves.
Definition tracking.hpp:166
std::array< uint64_t, 2 > vertices
Triangle mesh outputs: the output's vertices at the ends of the tracked edge holding it.
Definition tracking.hpp:170
uint64_t segment
Curve outputs: the output segment.
Definition tracking.hpp:168
A point on an application's output surface.
Definition tracking.hpp:58
std::array< uint64_t, 3 > vertices
Tet outputs: the output's vertices at the corners of the tracked face holding the point.
Definition tracking.hpp:62
uint64_t face
Surface outputs: the output triangle.
Definition tracking.hpp:60
How a SurfaceMap is built.
Definition SurfaceMap.hpp:90
Definition SurfaceMap.hpp:17
Definition tracking.hpp:244
How a VolumeMap keeps what it builds.
Definition VolumeMap.hpp:68
What building and using a volume map found.
Definition VolumeMap.hpp:33
A complex and the edits it went through, in commit order.
Definition History.hpp:101
The tets around every operation that changed a tet mesh's tracked surface, which, with the surface hi...
Definition VolumeHistory.hpp:89