Wildmeshing Toolkit
Loading...
Searching...
No Matches
TriWildMesh.h
1#pragma once
2
3#include <wmtk/MeshData.hpp>
4
5#include <wmtk/TriOptimizerMesh.h>
6
7#include <wmtk/SurfaceTagAttributes.h>
8#include <cstdlib>
9
10#include <wmtk/utils/PartitionMesh.h>
11#include <wmtk/utils/VectorUtils.h>
12#include <polysolve/nonlinear/Problem.hpp>
13#include <wmtk/AttributeCollection.hpp>
14#include <wmtk/Types.hpp>
15#include <wmtk/envelope/CompositeEnvelopes.hpp>
16#include <wmtk/envelope/Envelope.hpp>
17#include <wmtk/optimization/SmoothVertex.hpp>
18#include <wmtk/optimization/solver.hpp>
19#include <wmtk/threading/enumerable_thread_specific.hpp>
20
21// clang-format off
22#include <wmtk/utils/DisableWarnings.hpp>
23#include <fastenvelope/FastEnvelope.h>
24#include <wmtk/utils/EnableWarnings.hpp>
25// clang-format on
26
27#include "Parameters.h"
28
29#include <memory>
30#include <set>
31
32namespace wmtk::components::triwild {
33
35using VertexAttributes = wmtk::TriOptimizerMesh::VertexAttributes;
36using EdgeAttributes = wmtk::TriOptimizerMesh::EdgeAttributes;
37using FaceAttributes = wmtk::TriOptimizerMesh::FaceAttributes;
38
40{
41public:
45
46 std::vector<Vector2d> m_V_envelope;
47 std::vector<Vector2i> m_E_envelope;
48
58
62 std::shared_ptr<Envelope> surface_envelope_for_edge(
63 const std::array<size_t, 2>& vids,
64 const EdgeAttributes& attr) const override
65 {
66 if (m_input_envelopes.empty() || !attr.m_is_surface_fs) return m_envelope;
67 return m_input_envelopes.containment(attr.input_set());
68 }
69
73 std::shared_ptr<Envelope> smoothing_energy_envelope(const size_t vid) const override;
74
75 // The curve network's 0-dimensional features are anchored by the base
76 // (TriOptimizerMesh's feature-point anchors), turned on in the constructor with
77 // m_feature_eps = the envelope eps. init_mesh fills m_feature_points from the
78 // arrangement's constrained edges: a vertex whose valence in that edge set is neither 0
79 // nor 2 is a feature -- valence 1 is an open polyline's endpoint, valence >= 3 a
80 // junction -- plus the input free points. Reading it off the arrangement rather than the
81 // raw input is deliberate: it is the network the optimizer actually starts from, so a
82 // junction the simplification was allowed to merge (which it may, without
83 // preserve_topology) is correctly absent, and no provenance or
84 // position-matching plumbing is needed.
85
86 TriWildMesh(Parameters& _m_params, double envelope_eps, int _num_threads = 0)
87 : wmtk::TriOptimizerMesh(_m_params)
88 , m_tri_params(_m_params)
89 {
90 // Registered unconditionally, as the ids always were: the driver exports and audits
91 // the anchors whether or not preserve_feature_points turns the policy on.
93 m_feature_eps = envelope_eps;
94 m_envelope_eps = envelope_eps;
95 NUM_THREADS = _num_threads;
96
97 optimization::deactivate_opt_logger();
98
99 double& wa = m_params.w_amips;
100 double& we = m_params.w_envelope;
101 we = 1 - wa;
102 logger().info("w_envelope = {}", we);
103 }
104
105 ~TriWildMesh() {}
106
107public:
137 void init_mesh(
138 const MatrixXd& V,
139 const std::vector<Vector2r>& V_rational,
140 const MatrixXi& F,
141 const MatrixXi& E,
142 const std::vector<std::string>& tag_names,
143 const MatrixXd& V_env,
144 const MatrixXi& E_env,
145 const std::vector<int>* E_orientation = nullptr,
146 const std::vector<size_t>& free_point_vids = {},
147 const std::vector<int>* E_env_input = nullptr,
148 const std::vector<InputSet>* E_input_set = nullptr);
149
150 void init_surfaces_and_boundaries();
151
152 void init_envelope(const MatrixXd& V, const MatrixXi& F);
153
173 size_t refine_sizing_around_worst(double max_energy) override;
174
175
176 void write_vtu(const std::string& path, MeshMap* output = nullptr) const;
177
178public:
185 void compute_winding_numbers(const std::vector<MatrixXd>& Vs, const std::vector<MatrixXi>& Es);
186
189
204
205 int flood_fill();
208 bool m_has_parts = false;
209
210protected:
211 void write_smoothing_debug_output(const std::string& path) const override { write_vtu(path); }
212};
213
214
215} // namespace wmtk::components::triwild
One envelope per input, and the containment and the pull of an INPUT SET (bit i = input i; see Surfac...
Definition CompositeEnvelopes.hpp:152
Definition SurfaceTagAttributes.h:24
What triwild and simwild's 2D mesh share.
Definition TriOptimizerMesh.h:42
void enable_feature_point_tracking(const bool preserve)
Turn on feature-point tracking, and the policy when preserve.
Definition TriOptimizerMesh.h:309
OptimizerParameters & m_params
Definition TriOptimizerMesh.h:175
double m_feature_eps
Definition TriOptimizerMesh.h:262
Definition TriWildMesh.h:40
std::shared_ptr< Envelope > smoothing_energy_envelope(const size_t vid) const override
Definition TriWildMesh.cpp:747
void compute_winding_numbers(const std::vector< MatrixXd > &Vs, const std::vector< MatrixXi > &Es)
Tag every face with the inputs it lies inside, by winding number.
Definition TriWildMesh.cpp:496
void filter_with_input_winding_number()
Remove the faces that lie inside no input (needs compute_winding_numbers).
Definition TriWildMesh.cpp:593
std::shared_ptr< Envelope > surface_envelope_for_edge(const std::array< size_t, 2 > &vids, const EdgeAttributes &attr) const override
Definition TriWildMesh.h:62
Parameters & m_tri_params
Definition TriWildMesh.h:44
void init_mesh(const MatrixXd &V, const std::vector< Vector2r > &V_rational, const MatrixXi &F, const MatrixXi &E, const std::vector< std::string > &tag_names, const MatrixXd &V_env, const MatrixXi &E_env, const std::vector< int > *E_orientation=nullptr, const std::vector< size_t > &free_point_vids={}, const std::vector< int > *E_env_input=nullptr, const std::vector< InputSet > *E_input_set=nullptr)
Init mesh from IGL-style matrices.
Definition TriWildMesh.cpp:42
bool m_has_parts
Definition TriWildMesh.h:208
void filter_with_tracked_winding_number()
Remove the faces whose tracked winding number is at most 1/2.
Definition TriWildMesh.cpp:580
wmtk::InputEnvelopes m_input_envelopes
One envelope per input curve file, when there are several: a tracked segment is held to those of its ...
Definition TriWildMesh.h:57
void filter_with_flood_fill()
Remove the flood-fill region that dominates the mesh boundary (needs flood_fill).
Definition TriWildMesh.cpp:607
size_t refine_sizing_around_worst(double max_energy) override
The old global sizing-field update (KNN R-ball around every low-quality triangle)....
Definition TriWildMesh.cpp:428
void compute_tracked_winding_number()
Winding number of every face's centroid w.r.t. the tracked curves, oriented as the input was (m_track...
Definition TriWildMesh.cpp:542
double w_amips
Definition OptimizerParameters.h:172
Definition TriOptimizerMesh.h:95
Definition TriOptimizerMesh.h:45
The fields shared with tetwild and simwild live in wmtk::OptimizerParameters.
Definition Parameters.h:10
bool preserve_feature_points
Definition Parameters.h:22