3#include <wmtk/utils/PartitionMesh.h>
4#include <wmtk/utils/VectorUtils.h>
5#include <polysolve/nonlinear/Problem.hpp>
6#include <wmtk/AttributeCollection.hpp>
7#include <wmtk/Types.hpp>
8#include <wmtk/envelope/Envelope.hpp>
9#include <wmtk/optimization/solver.hpp>
12#include <wmtk/utils/DisableWarnings.hpp>
13#include <fastenvelope/FastEnvelope.h>
14#include <tbb/concurrent_priority_queue.h>
15#include <tbb/concurrent_vector.h>
16#include <tbb/enumerable_thread_specific.h>
17#include <tbb/parallel_for.h>
18#include <tbb/parallel_sort.h>
19#include <wmtk/utils/EnableWarnings.hpp>
22#include "Parameters.h"
24namespace wmtk::components::triwild {
32 bool m_is_rounded =
false;
34 bool m_is_on_surface =
false;
35 std::vector<int> on_bbox_faces;
37 double m_sizing_scalar = 1;
39 size_t partition_id = 0;
50 bool m_is_surface_fs =
false;
63 m_is_surface_fs =
false;
69 m_is_surface_fs = m_is_surface_fs || attr.m_is_surface_fs;
78 double m_winding_number = 0;
79 std::set<int64_t> tags;
86 int m_debug_print_counter = 0;
87 size_t m_tags_count = 0;
88 std::map<int64_t, std::string> m_tag_id_to_name;
89 std::map<std::string, int64_t> m_tag_name_to_id;
91 const double MAX_ENERGY = 1e50;
94 std::vector<Vector2d> m_V_envelope;
95 std::vector<Vector2i> m_E_envelope;
96 std::shared_ptr<SampleEnvelope> m_envelope;
97 double m_envelope_eps = -1;
106 tbb::enumerable_thread_specific<std::unique_ptr<polysolve::nonlinear::Solver>> m_solver;
109 double m_s_amips = -1;
110 double m_s_envelope = -1;
113 : m_params(_m_params)
114 , m_envelope_eps(envelope_eps)
116 NUM_THREADS = _num_threads;
117 p_vertex_attrs = &m_vertex_attribute;
118 p_edge_attrs = &m_edge_attribute;
119 p_face_attrs = &m_face_attribute;
121 optimization::deactivate_opt_logger();
128 m_s_envelope = 1. / (m_params.eps * m_params.eps);
131 double& wa = m_params.w_amips;
132 double& we = m_params.w_envelope;
134 logger().info(
"w_envelope = {}", we);
140 void partition_mesh();
143 void partition_mesh_morton();
145 size_t get_partition_id(
const Tuple& loc)
const
147 return m_vertex_attribute[loc.vid(*
this)].partition_id;
150 double get_length2(
const Tuple& l)
const;
160 void init_mesh(
const MatrixXd& V,
const MatrixXi& F,
const MatrixXi& E);
162 void init_surfaces_and_boundaries();
164 void init_envelope(
const MatrixXd& V,
const MatrixXi& F);
166 bool adjust_sizing_field_serial(
double max_energy);
168 void write_msh_groups(std::string file,
const bool write_envelope =
true);
170 void write_vtu(
const std::string& path)
const;
172 std::vector<std::array<size_t, 2>> get_edges_by_condition(
173 std::function<
bool(
const EdgeAttributes&)> cond)
const;
176 void split_all_edges();
180 void collapse_all_edges(
bool is_limit_length =
true);
184 size_t swap_all_edges();
194 void smooth_all_vertices(
const size_t n_iters = 1);
204 std::shared_ptr<polysolve::nonlinear::Problem> get_envelope_energy(
const Tuple& t)
const;
206 std::vector<std::array<double, 6>> get_amips_assembles(
const Tuple& t)
const;
207 std::shared_ptr<polysolve::nonlinear::Problem> get_amips_energy(
const Tuple& t)
const;
214 bool is_inverted(
const std::array<size_t, 3>& vs)
const;
215 bool is_inverted(
const Tuple& loc)
const;
216 bool is_inverted(
const size_t fid)
const;
217 double get_quality(
const std::array<size_t, 3>& vs)
const;
218 double get_quality(
const Tuple& loc)
const;
219 double get_quality(
const size_t fid)
const;
220 bool round(
const Tuple& loc);
222 bool is_edge_on_surface(
const Tuple& loc)
const;
223 bool is_edge_on_surface(
const std::array<size_t, 2>& vids)
const;
224 bool is_edge_on_bbox(
const Tuple& loc)
const;
225 bool is_edge_on_bbox(
const std::array<size_t, 2>& vids)
const;
230 std::tuple<double, double> local_operations(
231 const std::array<int, 4>& ops,
232 bool collapse_limit_length =
true);
233 std::tuple<double, double> get_max_avg_energy();
235 void compute_winding_numbers(
const std::vector<std::string>& input_paths);
240 return m_vertex_attribute.at(vid).m_is_on_surface ||
241 !m_vertex_attribute.at(vid).on_bbox_faces.empty();
250 bool on_surface = m_edge_attribute.at(eid).m_is_surface_fs;
251 bool on_bbox = m_edge_attribute.at(eid).m_is_bbox_fs >= 0;
252 return on_surface || on_bbox;
263 std::vector<size_t> v1_param_type;
264 std::vector<size_t> v2_param_type;
269 std::map<simplex::Edge, EdgeAttributes> changed_edges;
275 std::map<size_t, FaceAttributes>
faces;
277 tbb::enumerable_thread_specific<SplitInfoCache> split_cache;
285 bool is_limit_length;
287 std::vector<std::pair<EdgeAttributes, std::array<size_t, 2>>> changed_edges;
289 std::vector<std::array<size_t, 2>> surface_edges;
290 std::vector<size_t> changed_fids;
291 std::vector<double> changed_energies;
293 tbb::enumerable_thread_specific<CollapseInfoCache> collapse_cache;
299 std::map<simplex::Edge, EdgeAttributes> changed_edges;
300 std::set<int64_t> face_tags;
302 tbb::enumerable_thread_specific<SwapInfoCache> swap_cache;
Tuple tuple_from_edge(size_t vid1, size_t vid2, size_t fid) const
Definition TriMesh.cpp:1479
Definition TriWildMesh.h:46
int m_is_bbox_fs
Definition TriWildMesh.h:59
Definition TriWildMesh.h:75
Definition TriWildMesh.h:84
bool edge_is_on_surface(const std::array< size_t, 2 > &vids) const override
Is an edge part of the substructure.
Definition TriWildMesh.h:243
bool split_edge_after(const Tuple &loc) override
User specified modifications and desideratas after an edge split.
Definition EdgeSplitting.cpp:113
void init_mesh(const MatrixXd &V, const MatrixXi &F, const MatrixXi &E)
Init mesh from IGL-style matrices.
Definition TriWildMesh.cpp:203
bool swap_edge_after(const Tuple &t) override
User specified modifications and desideras after an edge swap.
Definition EdgeSwapping.cpp:145
bool swap_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge swap including 1.can't swap on boundary edge....
Definition EdgeSwapping.cpp:109
bool vertex_is_on_surface(const size_t vid) const override
Is a vertex part of the substructure.
Definition TriWildMesh.h:238
void mesh_improvement(int max_its=80)
Definition TriWildMesh.cpp:42
bool collapse_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge collapse including the link check as collapse...
Definition EdgeCollapsing.cpp:75
bool is_inverted_f(const Tuple &loc) const
Inversion check using only floating point numbers.
Definition TriWildMesh.cpp:832
bool split_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge split.
Definition EdgeSplitting.cpp:73
TriWildMesh(Parameters &_m_params, double envelope_eps, int _num_threads=0)
Definition TriWildMesh.h:112
bool smooth_after(const Tuple &t) override
User specified modifications and desideras after an edge smooth.
Definition Smooth.cpp:35
bool smooth_before(const Tuple &t) override
User specified preparations and desideratas for an edge smooth.
Definition Smooth.cpp:16
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition EdgeCollapsing.cpp:252
double swap_weight(const Tuple &t) const
The quality improvement of a swap.
Definition EdgeSwapping.cpp:79
std::vector< Vector2d > get_surface_assembles(const Tuple &t) const
A vector containing the vertex position and all positions of the surface neighbors.
Definition Smooth.cpp:177
Definition TriWildMesh.h:28
Definition Parameters.h:5
Definition TriWildMesh.h:280
Definition TriWildMesh.h:259
std::map< size_t, FaceAttributes > faces
Definition TriWildMesh.h:275
Definition TriWildMesh.h:297