3#include <wmtk/MeshData.hpp>
5#include <wmtk/TriOptimizerMesh.h>
7#include <wmtk/SurfaceTagAttributes.h>
9#include <unordered_set>
11#include <wmtk/utils/PartitionMesh.h>
12#include <wmtk/utils/VectorUtils.h>
13#include <polysolve/nonlinear/Problem.hpp>
14#include <wmtk/AttributeCollection.hpp>
15#include <wmtk/Types.hpp>
16#include <wmtk/envelope/Envelope.hpp>
17#include <wmtk/optimization/SmoothVertex.hpp>
18#include <wmtk/optimization/solver.hpp>
21#include <wmtk/utils/DisableWarnings.hpp>
22#include <igl/write_triangle_mesh.h>
23#include <wmtk/threading/enumerable_thread_specific.hpp>
24#include <fastenvelope/FastEnvelope.h>
25#include <wmtk/utils/EnableWarnings.hpp>
28#include "ConnectedComponent.hpp"
29#include "Parameters.h"
30#include "expression_parser/Expression.hpp"
33namespace wmtk::components::simwild::tri {
46 using ExprPtr = expression_parser::ExpressionPtr;
52 std::vector<Vector2d> m_V_envelope;
53 std::vector<Vector2i> m_E_envelope;
55 std::vector<std::tuple<ExprPtr, double>> m_sizing_field;
56 std::vector<std::tuple<ExprPtr, double>> m_quality_field;
58 bool m_collapse_check_link_condition =
false;
59 bool m_collapse_check_topology =
false;
60 bool m_collapse_check_manifold =
false;
73 m_envelope_eps = envelope_eps;
74 NUM_THREADS = _num_threads;
76 optimization::deactivate_opt_logger();
81 logger().info(
"w_envelope = {}", we);
99 const MatrixSi& T_tags,
100 const std::vector<std::string>& tag_names);
112 const MatrixSi& T_tags,
113 const std::vector<std::string>& tag_names);
115 void init_surfaces_and_boundaries();
117 void init_envelope(
const MatrixXd& V,
const MatrixXi& F);
119 CellTag string_set_to_cell_tag(
const std::set<std::string>& str_set);
121 void set_sizing_field(
const nlohmann::json& sizing_field_json);
123 void set_quality_field(
const nlohmann::json& quality_field_json);
125 double target_quality(
const size_t tid)
const;
126 double target_quality(
const Tuple& t)
const;
129 double quality_rel(
const size_t tid)
const override;
131 bool check_mesh_quality(
double& max_rel_quality,
const bool verbose =
false)
const;
161 std::vector<size_t> active_vertices()
const override;
178 void write_vtu(
const std::string& path, MeshMap* output =
nullptr)
const;
179 void write_vtu_with_energies(
const std::string& path)
const;
188 std::shared_ptr<polysolve::nonlinear::Problem> get_envelope_energy(
const Tuple& t)
const;
190 std::vector<std::array<double, 6>> get_amips_assembles(
const Tuple& t)
const;
191 std::shared_ptr<polysolve::nonlinear::Problem> get_amips_energy(
const Tuple& t)
const;
199 double triangle_area(
const size_t fid)
const;
224 std::vector<ConnectedComponent>
find_holes(
const std::vector<CellTag>& tag_in)
const;
243 const std::vector<CellTag>& lcc_tags,
244 const size_t n_lcc = 1);
246 void fill_holes_topo(
247 const std::vector<CellTag>& fill_holes_tags,
248 double threshold = std::numeric_limits<double>::infinity());
250 void seal_connected_components(
251 const std::vector<CellTag>& tag_sets,
252 const std::vector<ConnectedComponent>& components);
254 void tight_seal_topo(
255 const std::vector<std::vector<CellTag>>& tight_seal_tag_sets,
256 double threshold = std::numeric_limits<double>::infinity());
291 const std::vector<int64_t>& tags,
293 double trace_rel_tol = 0.01,
294 const std::string& selection =
"explicit",
295 int64_t min_regions = 2,
296 bool sanity =
false);
298 void resolve_overlaps(
const std::vector<std::array<ExprPtr, 2>>& intersecting_tags);
300 void replace_tags(
const std::vector<CellTag>& tags_in,
const std::vector<CellTag>& tags_out);
302 void tag_priority(
const std::vector<int64_t>& tags_order);
308 std::function<double(
const Vector2d&)> m_voronoi_split_fn =
nullptr;
309 size_t m_last_split_vertex = 0;
316 const std::vector<size_t>& fids,
317 const std::function<
bool(
size_t)>& in_set,
318 SimpleBVH::BVH& bvh)
const;
325 std::unordered_set<size_t>& faces,
326 std::vector<char>& filled,
327 const std::function<
void(
size_t,
size_t)>& on_child);
335 const std::vector<size_t>& fids,
336 const std::vector<int>& region,
337 const std::vector<double>& dist_R_at,
338 const std::function<
double(
const Vector2d&)>& dist_R,
343 size_t& n_failed)
const;
352 double optimization_stop_metric()
const override {
return 1.; }
353 bool optimization_stop_at_float()
const override {
return m_sim_params.stop_at_float; }
355 void write_smoothing_debug_output(
const std::string& path)
const override { write_vtu(path); }
357 bool collapse_quality_allowed(
size_t v1,
size_t fid,
double q,
double ring_max)
const override;
358 bool split_adjust_position(
size_t v_new,
const std::vector<Tuple>& children)
override;
359 void split_after_vertex(
size_t v_new)
override { m_last_split_vertex = v_new; }
Definition SurfaceTagAttributes.h:24
What triwild and simwild's 2D mesh share.
Definition TriOptimizerMesh.h:42
OptimizerParameters & m_params
Definition TriOptimizerMesh.h:175
Definition SimWildMeshTri.hpp:44
bool check_interface_edges_tagged(const bool verbose=false) const
Verify that every interface between unlike tags carries a surface edge.
Definition SimWildMeshTri.cpp:857
void update_attributes() override
Update the attributes of the mesh after an iteration of operations.
Definition SimWildMeshTri.cpp:956
size_t refine_sizing_around_worst(double max_metric=0.) override
Escape a stuck max energy by refining the sizing field around the worst elements.
Definition SimWildMeshTri.cpp:537
void init_from_image(const MatrixXd &V, const MatrixXi &T, const MatrixSi &T_tags, const std::vector< std::string > &tag_names)
Init from meshes image.
Definition SimWildMeshTri.cpp:41
void keep_largest_connected_component(const std::vector< CellTag > &lcc_tags, const size_t n_lcc=1)
Keep only the largest connected component for each of the distinct tag_0 values, and engulf all other...
Definition AnnotationsTri.cpp:450
std::vector< ConnectedComponent > compute_connected_components(const CellTag &tag_in) const
Find all connected components that contain the tag_in tags.
Definition AnnotationsTri.cpp:6
void log_total_surface_energy()
Definition SimWildMeshTri.cpp:1063
void tight_seal_geom_sanity(const std::vector< int64_t > &tags, const std::vector< char > &filled) const
Definition TightSealGeom.cpp:474
bool smoothing_position_is_allowed(const size_t, const Vector2d &) const override
Definition SimWildMeshTri.hpp:64
Parameters & m_sim_params
Definition SimWildMeshTri.hpp:50
void compute_tag_boundary(const CellTag &tag, MatrixXd &V, MatrixXi &E) const
Compute the boundary of a tag.
Definition AnnotationsTri.cpp:201
double quality_rel(const size_t tid) const override
Definition SimWildMeshTri.cpp:467
size_t tight_seal_split_tracked(const simplex::Edge &e, std::unordered_set< size_t > &faces, std::vector< char > &filled, const std::function< void(size_t, size_t)> &on_child)
Definition TightSealGeom.cpp:419
bool tight_seal_boundary_bvh(const std::vector< size_t > &fids, const std::function< bool(size_t)> &in_set, SimpleBVH::BVH &bvh) const
Definition TightSealGeom.cpp:340
std::tuple< double, double > optimization_quality_stats() override
Definition SimWildMeshTri.cpp:477
std::vector< ConnectedComponent > find_holes(const std::vector< CellTag > &tag_in) const
Find all regions that do not contain the tags from tag_in.
Definition AnnotationsTri.cpp:126
std::vector< Vector2d > get_surface_assembles(const Tuple &t) const
A vector containing the vertex position and all positions of the surface neighbors.
void tight_seal_geom(const std::vector< int64_t > &tags, double distance, double trace_rel_tol=0.01, const std::string &selection="explicit", int64_t min_regions=2, bool sanity=false)
Geometric tight seal between the regions R_i, the faces tagged with tags[i] and nothing else.
Definition AnnotationsTri.cpp:579
bool tight_seal_dilation_surface_bvh(const std::vector< size_t > &fids, const std::vector< int > ®ion, const std::vector< double > &dist_R_at, const std::function< double(const Vector2d &)> &dist_R, double radius, double tol, SimpleBVH::BVH &bvh, size_t &n_traced, size_t &n_failed) const
Definition TightSealGeom.cpp:363
Definition Simplex.hpp:46
double w_amips
Definition OptimizerParameters.h:172
Definition TriOptimizerMesh.h:95
Definition TriOptimizerMesh.h:45
The fields shared with tetwild and triwild live in wmtk::OptimizerParameters.
Definition Parameters.h:10