4#include <wmtk/SurfaceTagAttributes.h>
5#include <wmtk/TetMesh.h>
6#include <wmtk/TetOptimizerMesh.h>
7#include <wmtk/utils/PartitionMesh.h>
8#include <polysolve/nonlinear/Problem.hpp>
9#include <wmtk/envelope/Envelope.hpp>
10#include <wmtk/optimization/SmoothVertex.hpp>
11#include <wmtk/optimization/solver.hpp>
12#include <wmtk/simplex/Simplex.hpp>
13#include <wmtk/threading/enumerable_thread_specific.hpp>
14#include <wmtk/threading/parallel_for.hpp>
16#include "ConnectedComponent.hpp"
17#include "Parameters.h"
20#include <wmtk/utils/DisableWarnings.hpp>
21#include <fastenvelope/FastEnvelope.h>
22#include <VolumeRemesher/embed.h>
23#include <wmtk/utils/EnableWarnings.hpp>
26#include <igl/remove_unreferenced.h>
30#include <wmtk/utils/SurfaceTopology.hpp>
31#include <wmtk/utils/partition_utils.hpp>
32#include "expression_parser/Expression.hpp"
34namespace wmtk::components::simwild {
59 using ExprPtr = expression_parser::ExpressionPtr;
61 size_t m_tags_count = 0;
62 std::map<int64_t, std::string> m_tag_id_to_name;
63 std::map<std::string, int64_t> m_tag_name_to_id;
68 std::vector<Vector3d> m_V_envelope;
69 std::vector<Vector3i> m_F_envelope;
70 double m_envelope_eps = -1;
72 std::vector<std::tuple<ExprPtr, double>> m_sizing_field;
73 std::vector<std::tuple<ExprPtr, double>> m_quality_field;
75 bool m_collapse_check_quality =
true;
86 std::function<double(
const Vector3d&)> m_voronoi_split_fn =
nullptr;
92 m_envelope_eps = envelope_eps;
93 NUM_THREADS = _num_threads;
94 p_tet_attrs = &m_tet_attribute;
95 m_collapse_check_link_condition =
false;
96 m_collapse_check_manifold =
false;
100 optimization::deactivate_opt_logger();
107 logger().info(
"w_envelope = {}", we);
112 TetAttCol m_tet_attribute;
114 double cell_quality(
const size_t tid)
const override {
return m_tet_attribute[tid].m_quality; }
115 void set_cell_quality(
const size_t tid,
const double q)
override
117 m_tet_attribute[tid].m_quality = q;
119 bool allow_surface_swap()
const override {
return m_sim_params.allow_surface_swap; }
120 bool check_surface_topology()
const override {
return m_sim_params.check_surface_topology; }
123 void create_mesh_attributes(
124 const std::vector<VertexAttributes>& _vertex_attribute,
125 const std::vector<TetAttributes>& _tet_attribute)
127 const size_t n_tet = _tet_attribute.size();
128 m_vertex_attribute.resize(_vertex_attribute.size());
129 m_face_attribute.resize(4 * n_tet);
130 m_tet_attribute.resize(n_tet);
132 for (
size_t i = 0; i < _vertex_attribute.size(); i++)
133 m_vertex_attribute[i] = _vertex_attribute[i];
142 const size_t tcap = std::max(n_tet, m_tet_attribute.size());
143 m_tet_attribute.m_attributes = std::vector<TetAttributes>(tcap);
144 for (
size_t i = 0; i < n_tet; i++) m_tet_attribute[i] = _tet_attribute[i];
145 for (
size_t i = 0; i < n_tet; i++)
151 void init_envelope(
const MatrixXd& V,
const MatrixXi& F,
const bool use_exact);
153 CellTag string_set_to_cell_tag(
const std::set<std::string>& str_set);
155 void set_sizing_field(
const nlohmann::json& sizing_field_json);
157 void set_quality_field(
const nlohmann::json& quality_field_json);
159 double target_quality(
const size_t tid)
const;
160 double target_quality(
const Tuple& t)
const;
163 double quality_rel(
const size_t tid)
const override;
165 bool check_mesh_quality(
double& max_rel_quality,
const bool verbose =
false)
const;
171 void write_msh(std::string file,
const bool write_envelope =
true);
185 std::atomic<int> cnt_split = 0, cnt_collapse = 0;
189 double optimization_stop_metric()
const override {
return 1.; }
190 bool optimization_stop_at_float()
const override {
return m_sim_params.stop_at_float; }
191 void write_optimization_debug_output(
const std::string& path)
override { write_vtu(path); }
194 bool collapse_quality_allowed(
size_t v1,
double quality,
double ring_max)
const override;
195 bool collapse_is_order_2_edge(
const std::array<size_t, 2>& e)
override;
196 bool collapse_after_connectivity(
199 const std::vector<std::array<size_t, 2>>& boundary_edges)
override;
200 void collapse_after_vertex(
size_t v1,
size_t v2)
override;
202 bool split_before_cells(
const Tuple& edge,
const std::vector<Tuple>& parents)
override;
203 bool split_after_cells(
size_t v1,
size_t v2,
size_t v_new,
const std::vector<Tuple>& children)
208 bool swap_before_surface(
209 const std::vector<size_t>& tids,
214 bool swap_after_cells(
const std::vector<size_t>& tids,
bool is_surface_flip)
override;
223 std::map<simplex::Edge, TetAttributes>
tets;
230 std::map<size_t, CellTag> ring_tags;
245 const MatrixSi& T_tags,
246 const std::vector<std::string>& tag_names);
250 const MatrixSi& T_tags,
251 const std::vector<std::string>& tag_names);
253 void init_surfaces_and_boundaries();
293 void write_vtu(
const std::string& path);
295 void write_surface(
const std::string& path)
const;
308 double tet_volume(
const size_t tid)
const;
333 std::vector<ConnectedComponent>
find_holes(
const std::vector<CellTag>& tag_in)
const;
353 const std::vector<CellTag>& lcc_tags,
354 const size_t n_lcc = 1);
356 void fill_holes_topo(
357 const std::vector<CellTag>& fill_holes_tags,
358 double threshold = std::numeric_limits<double>::infinity());
360 void seal_connected_components(
361 const std::vector<CellTag>& tag_sets,
362 const std::vector<ConnectedComponent>& components);
364 void tight_seal_topo(
365 const std::vector<std::vector<CellTag>>& tight_seal_tag_sets,
366 double threshold = std::numeric_limits<double>::infinity());
368 void resolve_overlaps(
const std::vector<std::array<ExprPtr, 2>>& intersecting_tags);
370 void replace_tags(
const std::vector<CellTag>& tags_in,
const std::vector<CellTag>& tags_out);
Whether a codimension-1 simplex is tracked surface, and which bbox side it lies on.
Definition SurfaceTagAttributes.h:15
a Tuple refers to a global vid and a global tet id, and a local edge id and local face id
Definition TetMesh.h:49
Tuple tuple_from_tet(size_t tid) const
get a Tuple from global tetra index
Definition TetMesh.cpp:640
What tetwild and simwild's 3D mesh share.
Definition TetOptimizerMesh.h:45
OptimizerParameters & m_params
Definition TetOptimizerMesh.h:121
Definition SimWildMesh.h:57
bool swap_after_cells(const std::vector< size_t > &tids, bool is_surface_flip) override
Propagate application data to the cells made by a successful topological swap.
Definition EdgeSwapping.cpp:45
std::vector< ConnectedComponent > compute_connected_components(const CellTag &tag_in) const
Find all connected components that contain the tag_in tags.
Definition AnnotationsTet.cpp:7
bool split_before_cells(const Tuple &edge, const std::vector< Tuple > &parents) override
Cache application cell data before a split. TetWild needs none; SimWild caches tags.
Definition EdgeSplitting.cpp:7
bool collapse_before_vertex(size_t v1, size_t v2, double edge_length) override
Definition EdgeCollapsing.cpp:8
void init_vertex_order()
Compute the vertex order for every vertex.
Definition SimWildMesh.cpp:642
bool all_rounded() const
Check if all vertices of the mesh are rounded.
Definition SimWildMesh.cpp:441
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 SimWildMesh.cpp:229
bool split_after_cells(size_t v1, size_t v2, size_t v_new, const std::vector< Tuple > &children) override
Restore application cell data on the children made by a split.
Definition EdgeSplitting.cpp:20
Parameters & m_sim_params
Definition SimWildMesh.h:67
void find_order_2_edges()
Find open boundary edges of the embedded surface and initialize a BVH for the open boundary.
Definition VolumemesherInsertion.cpp:407
std::shared_ptr< SampleEnvelope > m_order_2_edge_envelope
Follows m_envelope's use_exact; see where it is built in VolumemesherInsertion.cpp.
Definition SimWildMesh.h:79
double cell_quality(const size_t tid) const override
The quality of cell tid, and how to write it.
Definition SimWildMesh.h:114
void compute_tag_boundary(const CellTag &tag, MatrixXd &V, MatrixXi &F) const
Compute the boundary of a tag.
Definition AnnotationsTet.cpp:202
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 AnnotationsTet.cpp:445
std::tuple< double, double > optimization_quality_stats() override
Definition SimWildMesh.cpp:168
void init_from_image(const MatrixXr &V, const MatrixXi &T, const MatrixSi &T_tags, const std::vector< std::string > &tag_names)
Init from meshes image.
Definition VolumemesherInsertion.cpp:10
std::shared_ptr< SampleEnvelope > smoothing_energy_envelope(const size_t vid) const override
Envelope a vertex is pulled toward while smoothing.
Definition Smooth.cpp:5
void tag_priority(const std::vector< int64_t > &tags)
Gives tags priority over others.
Definition AnnotationsTet.cpp:687
bool is_order_2_edge(const Tuple &e) const
Checks if an edge COULD be an open boundary edge.
Definition VolumemesherInsertion.cpp:448
bool split_adjust_position(size_t v_new, const std::vector< Tuple > &children) override
Definition EdgeSplitting.cpp:50
std::vector< size_t > active_vertices() const override
Definition SimWildMesh.cpp:184
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 AnnotationsTet.cpp:127
bool swap_before_interior(const std::vector< size_t > &tids) override
Application data attached to the old cells. TetWild has none; SimWild caches tags.
Definition EdgeSwapping.cpp:7
double quality_rel(const size_t tid) const override
Definition SimWildMesh.cpp:158
Definition SimWildMesh.h:43
double m_quality
Definition SimWildMesh.h:48
CellTag tags
Definition SimWildMesh.h:53
Definition enumerable_thread_specific.hpp:26
Definition AttributeCollection.hpp:36
double w_amips
Definition OptimizerParameters.h:154
Definition TetOptimizerMesh.h:48
The fields shared with tetwild and triwild live in wmtk::OptimizerParameters.
Definition Parameters.h:10
Definition SimWildMesh.h:220
std::map< simplex::Edge, TetAttributes > tets
Parent cell data, keyed by the edge opposite the split edge.
Definition SimWildMesh.h:223
Definition SimWildMesh.h:228