39#ifndef VULPES_GEOMETRY_MESHER_HPP_
40#define VULPES_GEOMETRY_MESHER_HPP_
48#include <unordered_map>
71template <
typename FloatType>
76 const FloatType
toll = 1e-4;
111template <
int32_t Dim>
115 int32_t n_inside_seeds) {
117 double total_area = 0.0;
120 double area_and_centroid[Dim + 1];
121 cell.centroid(area_and_centroid);
122 Eigen::Map<Point<double, Dim>> centroid(area_and_centroid + 1);
123 points[id] += centroid;
126 double area = area_and_centroid[0];
127 if (
id < n_inside_seeds) {
128 err += centroid.cwiseAbs2().sum() * area * area;
133 const double total_err =
134 std::sqrt(err) * points.size() / std::pow(total_area, 1.5);
135 return {total_err, total_area};
150template <
typename FloatType,
typename IndexType, IndexType Dim,
typename D>
155 FloatType finite_difference_h) {
157 for (
size_t d = 0; d < Dim; ++d) {
160 x_plus[d] += finite_difference_h;
161 x_minus[d] -= finite_difference_h;
166 gradient[d] = d_x_plus.back() - d_x_minus.back();
169 gradient[d] = d_x_plus[idx] - d_x_minus[idx];
171 gradient[d] /= 2.0 * finite_difference_h;
185template <
int32_t Dim,
typename D>
191 constexpr double same_vertex_distance_tol = 1e-18;
194 std::vector<Point<double, 2>> vertices;
195 std::vector<bool> visited(points.size(),
false);
196 std::vector<int32_t> neighs_buffer(128);
197 std::vector<double> vertices_buffer(128);
200 bbox, points, [&](
const voro::voronoicell_neighbor_2d& cell,
auto id) {
201 cell.neighbors(neighs_buffer);
202 cell.ordered_vertices(points[
id][0], points[
id][1], vertices_buffer);
203 const size_t n_cell_vtxs = vertices_buffer.size() / 2;
208 for (
size_t vid = 0; vid < n_cell_vtxs; ++vid) {
209 bool collision_found =
false;
211 for (
size_t cidn = 0;
212 cidn < neighs_buffer.size() && !collision_found; ++cidn) {
213 const int32_t neigh = neighs_buffer[cidn];
215 if (neigh >= 0 && visited[neigh]) {
216 const size_t n_neigh_vtxs = vertices_idxs.
getRow(neigh).size();
217 for (
size_t vidn = 0; vidn < n_neigh_vtxs; ++vidn) {
219 vertices[vertices_idxs.
getRow(neigh)[vidn]];
220 const Eigen::Map<const Point<double, 2>> vtx2(
221 &vertices_buffer[2 * vid]);
222 const double dist_sqrd = (vtx1 - vtx2).cwiseAbs2().sum();
223 const double magn_sqrd =
224 vtx1.cwiseAbs2().sum() + vtx2.cwiseAbs2().sum();
225 if (dist_sqrd / magn_sqrd < same_vertex_distance_tol) {
226 collision_found =
true;
227 const auto new_vtx_id = vertices_idxs.
getRow(neigh)[vidn];
229 auto& row = vertices_idxs.
getRow(
id);
230 if ((row.size() == 0) ||
231 ((new_vtx_id != row[row.size() - 1]) &&
232 (new_vtx_id != row[0]))) {
233 row.push_back(new_vtx_id);
242 if (!collision_found) {
243 vertices.emplace_back(
244 vertices_buffer[2 * vid], vertices_buffer[2 * vid + 1]);
245 vertices_idxs.
getRow(
id).push_back(vertices.size() - 1);
263template <
int32_t Dim,
typename D>
269 constexpr double same_vertex_distance_tol = 1e-18;
272 std::vector<Point<double, 3>> vertices;
273 std::vector<int32_t> visited(points.size(), -1);
274 std::vector<int32_t> neighs_buffer(128);
275 std::vector<double> vertices_buffer(128);
276 std::vector<std::vector<int32_t>> faces_staggered;
277 std::vector<int32_t> face_sizes(128);
278 std::vector<int32_t> face_vertices(512);
281 voronoi3D(bbox, points, [&](
auto& cell,
auto id) {
282 const auto dist =
computeDistance(points[
id], distanceFunction).back();
285 auto& curr_cell_vtx = vertices_idxs.
getRow(curr_id);
287 points[
id][0], points[
id][1], points[
id][2], vertices_buffer);
288 assert(vertices_buffer.size() % 3 == 0);
289 cell.neighbors(neighs_buffer);
291 const size_t n_cell_vtxs = vertices_buffer.size() / 3;
292 for (
size_t vid = 0; vid < n_cell_vtxs; ++vid) {
293 bool collision_found =
false;
295 const size_t n_neighs = neighs_buffer.size();
296 for (
size_t cidn = 0; cidn < n_neighs && !collision_found; ++cidn) {
297 const int32_t neigh = neighs_buffer[cidn];
299 if (neigh >= 0 && (visited[neigh] != -1)) {
300 auto& neigh_cell_vtx = vertices_idxs.
getRow(visited[neigh]);
301 const size_t n_neigh_vtxs = neigh_cell_vtx.size();
302 for (
size_t vidn = 0; vidn < n_neigh_vtxs; ++vidn) {
304 const Eigen::Map<const Point<double, 3>> vtx2(
305 &vertices_buffer[3 * vid]);
306 const double dist_sqrd = (vtx1 - vtx2).cwiseAbs2().sum();
307 const double magn_sqrd =
308 vtx1.cwiseAbs2().sum() + vtx2.cwiseAbs2().sum();
309 if (dist_sqrd / magn_sqrd < same_vertex_distance_tol) {
310 collision_found =
true;
311 curr_cell_vtx.push_back(neigh_cell_vtx[vidn]);
318 if (!collision_found) {
319 vertices.emplace_back(
320 vertices_buffer[3 * vid], vertices_buffer[3 * vid + 1],
321 vertices_buffer[3 * vid + 2]);
322 curr_cell_vtx.push_back(vertices.size() - 1);
325 visited[id] = curr_id++;
328 cell.face_vertices(face_vertices, face_sizes);
329 faces_staggered.emplace_back();
330 auto& curr_cell_face_vtx = faces_staggered.back();
333 for (
size_t j = 0; j < face_sizes.size(); ++j) {
334 for (int32_t k = 0; k < face_sizes[j] + 1; ++k) {
335 assert(count < face_vertices.size());
337 assert(face_vertices[count] == face_sizes[j]);
338 curr_cell_face_vtx.push_back(face_vertices[count]);
340 curr_cell_face_vtx.push_back(curr_cell_vtx[face_vertices[count]]);
345 curr_cell_face_vtx.end() - face_sizes[j], curr_cell_face_vtx.end());
347 assert(count == face_vertices.size());
363template <
typename FloatType,
typename IndexType, IndexType Dim>
366 const std::vector<IndexType>& near_boundary_idxs,
368 if (fixed_pts.empty()) {
372 for (
const auto& fix_pt : fixed_pts) {
374 std::array<std::pair<IndexType, FloatType>, 2 * Dim> closest_seeds;
375 for (
size_t d = 0; d < closest_seeds.size(); ++d) {
376 closest_seeds[d] = {-1, std::numeric_limits<FloatType>::max()};
380 for (
const IndexType idx : near_boundary_idxs) {
381 const FloatType dist = (seed_pts[idx] - fix_pt).norm();
382 auto max_it = std::max_element(
383 closest_seeds.begin(), closest_seeds.end(),
384 [](
const auto& lhs,
const auto& rhs) {
385 return lhs.second < rhs.second;
387 if (dist < max_it->second) {
388 max_it->second = dist;
395 closest_seeds.begin(), closest_seeds.end(),
396 [](
const auto& lhs,
const auto& rhs) {
397 return lhs.second < rhs.second;
400 if (closest_seeds.back().first == -1) {
401 std::cout <<
"WARNING: could not find enough points near the fixed point "
405 for (
size_t i = 1; i < closest_seeds.size(); ++i) {
407 seed_pts[closest_seeds[i].first] - fix_pt;
408 seed_pts[closest_seeds[i].first] -=
409 normal * (1.0 - closest_seeds[0].second / closest_seeds[i].second);
414 (fix_pt - seed_pts[closest_seeds[i].first]).norm() -
415 (fix_pt - seed_pts[closest_seeds[0].first]).norm()) <
416 2 * std::numeric_limits<FloatType>::epsilon());
435template <
typename FloatType,
typename IndexType, IndexType Dim,
typename D>
441 std::vector<IndexType> near_boundary_idxs;
443 const size_t n_seed_pts = seed_pts.size();
444 size_t near_boundary = 0;
445 size_t reflected_with_success = 0;
446 for (
size_t i = 0; i < n_seed_pts; ++i) {
449 assert(d_i.back() < 0.0);
450 if (-d_i.back() < alpha) {
452 near_boundary_idxs.push_back(i);
453 bool reflection_inserted =
false;
455 for (
size_t j = 0; j < d_i.size() - 1; ++j) {
457 const FloatType d_seed_j = d_i[j];
458 const FloatType d_seed_j_abs = std::abs(d_seed_j);
459 if (d_seed_j_abs < alpha) {
463 seed_pt_i, distanceFunction, (IndexType)j,
466 seed_pts[i] - 2.0 * d_seed_j * gradient;
469 if (pt_d.back() > 0 &&
471 near_boundary_idxs.push_back(seed_pts.size());
472 seed_pts.push_back(rflc_pt);
473 reflection_inserted =
true;
477 reflected_with_success += reflection_inserted;
481 if (reflected_with_success < near_boundary) {
482 std::cout <<
"WARNING: could not insert some reflections, succeeded: "
483 << reflected_with_success <<
" / " << near_boundary << std::endl;
486 return near_boundary_idxs;
500template <
typename FloatType,
typename MeshType,
typename D>
507 constexpr auto Dim = MeshType::self_dim;
508 size_t possible_clipping = 0;
509 size_t successfull_clipping = 0;
510 for (
auto& vtx : mesh.getVertexes()) {
511 const auto distance_from_bnd =
514 if (std::abs(distance_from_bnd) < params.
clipping_relax * alpha) {
521 const auto new_distance_from_bnd =
523 if (std::abs(new_distance_from_bnd) < std::abs(distance_from_bnd)) {
525 successfull_clipping++;
529 std::cout <<
"possible_clipping: " << possible_clipping
530 <<
" successfull_clipping: " << successfull_clipping << std::endl;
541template <
typename FloatType,
typename IndexType>
545 const std::array<IndexType, 2>& edge) {
547 return std::numeric_limits<FloatType>::max();
549 const auto vtx_ids = mesh.getCellToVtxMap().getRow(cell_id);
550 const auto& pts = mesh.getVertexes();
552 FloatType meanvy = 0.0;
553 FloatType meanvx = 0.0;
554 for (
const auto& vid : vtx_ids) {
555 meanvx += pts[vid][0];
556 meanvy += pts[vid][1];
558 meanvx /= vtx_ids.size();
559 meanvy /= vtx_ids.size();
563 std::atan2(pts[edge[1]][1] - meanvy, pts[edge[1]][0] - meanvx) -
564 std::atan2(pts[edge[0]][1] - meanvy, pts[edge[0]][0] - meanvx);
567 constexpr auto min_angle = 1e-8;
569 angle = std::fmod(angle + pi2, pi2);
571 return std::abs(angle) * vtx_ids.size() / pi2;
585template <
typename FloatType,
typename IndexType, IndexType Dim,
typename D>
589 FloatType edge_collapse_tol) {
590 std::vector<IndexType> small_edges;
591 const IndexType n_edges = mesh.getFacetToCellMap().size();
592 for (IndexType i = 0; i < n_edges; ++i) {
593 const auto edge = mesh.getFacetToVtxMap().getRow(i);
594 const auto& cells = mesh.getFacetToCellMap()[i];
596 const auto& map = mesh.getCellToVtxMap();
597 if ((cells[0] == -1 || map.getRow(cells[0]).size() > 3) &&
598 (cells[1] == -1 || map.getRow(cells[1]).size() > 3)) {
600 const FloatType angle_normalized_size_0 =
602 const FloatType angle_normalized_size_1 =
605 if ((angle_normalized_size_0 < edge_collapse_tol) ||
606 (angle_normalized_size_1 < edge_collapse_tol)) {
607 small_edges.push_back(i);
616 std::unordered_map<IndexType, uint64_t> vertex_to_edges;
617 for (
size_t i = 0; i < small_edges.size(); ++i) {
618 const auto edge_id = small_edges[i];
619 const auto edge_vtx = mesh.getFacetToVtxMap().getRow(edge_id);
623 vertex_to_edges[edge_vtx[0]] += (1ULL << 32) + uint64_t(edge_id);
624 vertex_to_edges[edge_vtx[1]] += (1ULL << 32) + uint64_t(edge_id);
627 std::unordered_map<IndexType, IndexType> vtxs_to_remove_in_edge;
628 for (
const auto& [vertex_id, edge_count_and_id] : vertex_to_edges) {
631 if ((edge_count_and_id >> 32) == 1) {
632 vtxs_to_remove_in_edge[edge_count_and_id & 0xFFFFFFFFULL]++;
636 std::vector<std::array<IndexType, 2>> vtxs_to_remove;
637 auto new_cell_to_vtx = mesh.getCellToVtxMap();
638 for (
const auto& [edge_id, vtx_count] : vtxs_to_remove_in_edge) {
640 if (vtx_count == 2) {
644 const IndexType v1_id = mesh.getFacetToVtxMap()(edge_id, 0);
645 const IndexType v2_id = mesh.getFacetToVtxMap()(edge_id, 1);
646 const auto& pt1 = mesh.getVertexes()[v1_id];
647 const auto& pt2 = mesh.getVertexes()[v2_id];
652 if (std::abs(d1) < std::abs(d2)) {
653 vtxs_to_remove.push_back({v2_id, v1_id});
655 vtxs_to_remove.push_back({v1_id, v2_id});
658 for (
const auto& cell : mesh.getFacetToCellMap()[edge_id]) {
660 for (IndexType& vtx_id : new_cell_to_vtx.getRow(cell)) {
661 if (vtx_id == vtxs_to_remove.back()[0]) {
672 constexpr IndexType mask = IndexType(1)
673 << IndexType(
sizeof(IndexType) * 8 - 1);
676 vtxs_to_remove.begin(), vtxs_to_remove.end(),
677 [](
const auto& lhs,
const auto& rhs) { return lhs[0] < rhs[0]; });
679 vtxs_to_remove.push_back({-1, -1});
680 std::vector<Point<FloatType, 2>> new_vxts;
681 std::vector<IndexType> vtx_old_new_table;
683 const IndexType n_vtxs = mesh.getVertexes().size();
684 for (IndexType i = 0; i < n_vtxs; ++i) {
685 if (vtxs_to_remove[j][0] == i) {
689 vtx_old_new_table.push_back(vtxs_to_remove[j][1] | mask);
693 vtx_old_new_table.push_back(new_vxts.size());
694 new_vxts.push_back(mesh.getVertexes()[i]);
697 new_vxts.size() == mesh.getVertexes().size() - vtxs_to_remove.size() + 1);
700 std::vector<IndexType> crs_indexes = {0};
701 std::vector<IndexType> crs_data;
702 for (IndexType i = 0; i < new_cell_to_vtx.size(); ++i) {
703 const auto row = new_cell_to_vtx.getRow(i);
704 for (
const auto elem : row) {
706 const auto new_elem = vtx_old_new_table[elem];
708 if (mask & new_elem) {
709 crs_data.push_back(vtx_old_new_table[new_elem & (~mask)]);
711 crs_data.push_back(new_elem);
715 crs_indexes.push_back(crs_data.size());
744 typename = std::enable_if_t<(Dim == 2) || (Dim == 3)>>
745using Mesh = std::conditional_t<
766template <
typename FloatType,
typename IndexType, IndexType Dim,
typename D>
767std::pair<Mesh<FloatType, IndexType, Dim>, std::vector<Point<FloatType, Dim>>>
772 const VulPolyParams<FloatType>& params = {},
774 const auto bbox = distanceFunction.
bbox();
776 std::mt19937 gen(seed);
777 std::uniform_real_distribution<FloatType> dis(0.0, 1.0);
780 const auto gen_random_pt = [&](
size_t iter) {
781 std::array<FloatType, Dim> pt;
782 switch (engine_type) {
784 for (
size_t d = 0; d < Dim; ++d) {
794 throw std::logic_error(
"Mesher: unknown random engine");
800 std::vector<Point<FloatType, Dim>> seed_pts(n_elems);
803 while (found < n_elems) {
805 const auto raw_random_pt = gen_random_pt(count++);
806 Eigen::Map<const Point<FloatType, Dim>> random_pt(raw_random_pt.data());
809 bbox[0].array() + random_pt.array() * (bbox[1] - bbox[0]).array();
812 if (distance.back() < 0) {
813 seed_pts[found++] = pt;
817 return {
mesh(seed_pts, distanceFunction, fixed_pts, params), seed_pts};
835template <
typename FloatType,
typename IndexType, IndexType Dim,
typename D>
840 const VulPolyParams<FloatType>& params = {}) {
841 const auto bbox = distanceFunction.
bbox();
844 const std::array<Point<FloatType, Dim>, 2> extended_bbox = {
845 bbox[0].array() - 0.5 * (bbox[1] - bbox[0]).array(),
846 bbox[1].array() + 0.5 * (bbox[1] - bbox[0]).array()};
847 FloatType area = (bbox[1] - bbox[0]).prod();
849 FloatType err = std::numeric_limits<FloatType>::infinity();
850 for (
size_t it = 0; it < params.max_iter; ++it) {
851 const size_t n_elems = center_pts.size();
853 const FloatType alpha =
854 params.area_relax * std::pow(area / n_elems, 1.0 / Dim);
855 const auto near_boundary_idxs =
858 fixed_pts, near_boundary_idxs, center_pts);
863 if (err < params.toll || it == (params.max_iter - 1)) {
868 extended_bbox, center_pts, n_elems);
871 std::vector<Point<FloatType, Dim>> new_center_pts;
872 for (
const auto& pt : center_pts) {
874 new_center_pts.push_back(pt);
877 center_pts = new_center_pts;
879 std::cout <<
"VulPoly: " << err <<
" " << it << std::endl;
883 if constexpr (Dim == 2) {
885 extended_bbox, center_pts, distanceFunction);
887 tmp_mesh, distanceFunction, params.collapse_edge_toll);
888 const auto alpha = std::pow(area / center_pts.size(), 1.0 / Dim);
890 if (params.clip_to_bnd) {
892 tmp_mesh, alpha, distanceFunction, params);
895 }
else if constexpr (Dim == 3) {
897 extended_bbox, center_pts, distanceFunction);
898 const auto alpha = std::pow(area / tmp_mesh.numCells(), 1.0 / Dim);
899 if (params.clip_to_bnd) {
901 tmp_mesh, alpha, distanceFunction, params);
905 static_assert(Dim * 0,
"Not Implemented");
918template <
typename FloatType,
typename IndexType>
923 const auto distanceRectangle =
925 const std::vector<Point<FloatType, 2>> fixed_pts = {};
927 constexpr FloatType sqrt3_2 = std::sqrt(3) / 2.0;
928 const FloatType dx = (corner_b[0] - corner_a[0]) / n_divisions[0];
929 const FloatType dy = (corner_b[1] - corner_a[1]) / n_divisions[1];
930 const IndexType ny = IndexType(std::ceil(n_divisions[1] / sqrt3_2)) + 2;
931 std::vector<Point<FloatType, 2>> seeds;
932 for (IndexType i = 0; i < n_divisions[0] + 1; ++i) {
933 for (IndexType j = 0; j < ny; ++j) {
934 const FloatType x = corner_a[0] + i * dx + ((j % 2) * dx) / 2.0;
935 const FloatType y = corner_a[1] + j * sqrt3_2 * dy;
943 return vulpoly::mesh(seeds, distanceRectangle, fixed_pts, options);
955template <
typename FloatType,
typename IndexType>
960 const auto distanceFn =
962 const std::vector<Point<FloatType, 3>> fixed_pts = {};
964 const FloatType dt = 0.01;
967 (corner_b[0] - corner_a[0]) / (n_divisions[0] - 1. + 2 * dt);
969 (corner_b[1] - corner_a[1]) / (n_divisions[1] - 1. + 2 * dt);
971 (corner_b[2] - corner_a[2]) / (n_divisions[2] - 1. + 2 * dt);
973 std::vector<Point<FloatType, 3>> seeds;
974 for (IndexType i = 0; i < n_divisions[0] + 2; ++i) {
975 for (IndexType j = 0; j < n_divisions[1] + 2; ++j) {
976 for (IndexType k = 0; k < n_divisions[2] + 2; ++k) {
978 const FloatType x = corner_a[0] + i * dx;
979 const FloatType y = corner_a[1] + j * dy;
980 const FloatType z = corner_a[2] + k * dz;
987 const FloatType x = corner_a[0] + (2 * i + 1) * dx / 2.0;
988 const FloatType y = corner_a[1] + (2 * j + 1) * dy / 2.0;
989 const FloatType z = corner_a[2] + (2 * k + 1) * dz / 2.0;
A class that behaves like a vector of vectors, providing automatic row range checking.
Definition crs_map.hpp:758
SmallVector< DataType, N > & getRow(std::size_t row_idx)
Access a row of the matrix as a mutable reference.
Definition crs_map.hpp:857
Definition crs_map.hpp:72
Template class representing a generic signed distance expression.
Definition distance.hpp:65
std::array< Point< FloatType, Dim >, 2 > bbox() const
Get the bounding box (bbox) of the shape.
Definition distance.hpp:108
A class for a 2D mesh, inheriting from MeshBase.
Definition mesh_2d.hpp:94
Represents a 3D mesh.
Definition mesh_3d.hpp:82
Signed distance function for a rectangle in 2D space.
Definition distance.hpp:125
Signed distance function for a hexahedron (cuboid) in 3D space.
Definition distance.hpp:468
Helpers implementing VulPoly's Voronoi construction and cleanup.
Definition abs_agg_model.cpp:42
std::vector< IndexType > vulPolyReflect(const DistanceExpression< FloatType, Dim, D > &distanceFunction, FloatType alpha, const vulpoly::VulPolyParams< FloatType > ¶ms, std::vector< Point< FloatType, Dim > > &seed_pts)
Add reflected seeds near domain boundaries.
Definition mesher.hpp:436
Point< FloatType, Dim > computeGradient(const Point< FloatType, Dim > x, const DistanceExpression< double, Dim, D > &distanceFunction, IndexType idx, FloatType finite_difference_h)
Estimate a signed-distance gradient by centered finite differences.
Definition mesher.hpp:151
void vulPolyAdjustFixedPoints(const std::vector< Point< FloatType, Dim > > &fixed_pts, const std::vector< IndexType > &near_boundary_idxs, std::vector< Point< FloatType, Dim > > &seed_pts)
Adjust nearby seeds to keep fixed points represented in the mesh.
Definition mesher.hpp:364
void vulPolyClipToBoundary(MeshType &mesh, FloatType alpha, const DistanceExpression< FloatType, MeshType::self_dim, D > &distanceFunction, const vulpoly::VulPolyParams< FloatType > ¶ms)
Improve positions of mesh vertices close to the domain boundary.
Definition mesher.hpp:501
std::pair< double, double > updateVoronoiCentroid(const std::array< Point< double, Dim >, 2 > &bbox, std::vector< Point< double, Dim > > &points, int32_t n_inside_seeds)
Move each Voronoi seed to its cell centroid and estimate relaxation error.
Definition mesher.hpp:112
Mesh3D< double, int32_t > computeVoronoiMesh3D(const std::array< Point< double, 3 >, 2 > &bbox, const std::vector< Point< double, 3 > > &points, const DistanceExpression< double, Dim, D > &distanceFunction)
Convert in-domain 3D Voronoi cells into a Vulpes mesh.
Definition mesher.hpp:264
FloatType vulPolyComputeEdgeAngle(const Mesh2D< FloatType, IndexType > &mesh, IndexType cell_id, const std::array< IndexType, 2 > &edge)
Estimate an edge's normalized angular size in an adjacent cell.
Definition mesher.hpp:542
Mesh2D< double, int32_t > computeVoronoiMesh2D(const std::array< Point< double, 2 >, 2 > &bbox, const std::vector< Point< double, 2 > > &points, const DistanceExpression< double, Dim, D > &distanceFunction)
Convert in-domain 2D Voronoi cells into a Vulpes mesh.
Definition mesher.hpp:186
void vulPolyCollapseEdges(Mesh2D< FloatType, IndexType > &mesh, const DistanceExpression< FloatType, Dim, D > &distanceFunction, FloatType edge_collapse_tol)
Collapse isolated undersized edges in a 2D mesh.
Definition mesher.hpp:586
VulPoly meshing options and algorithm parameters.
Definition mesher.hpp:66
RandomEngine
Available random or low-discrepancy seed generation strategies.
Definition mesher.hpp:732
@ AdditiveRecurrence
Generate points with the additive recurrence sequence.
Definition mesher.hpp:736
@ Pseudo
Draw independent uniform samples from the unit box.
Definition mesher.hpp:734
auto buildHexagonTessellation(const Point< FloatType, 2 > &corner_a, const Point< FloatType, 2 > &corner_b, const Point< IndexType, 2 > &n_divisions)
Build a 2D hexagonal seed tessellation and mesh its rectangle.
Definition mesher.hpp:919
std::conditional_t< Dim==2, Mesh2D< FloatType, IndexType >, Mesh3D< FloatType, IndexType > > Mesh
Select the concrete mesh type for a supported spatial dimension.
Definition mesher.hpp:745
std::pair< Mesh< FloatType, IndexType, Dim >, std::vector< Point< FloatType, Dim > > > mesh(const DistanceExpression< FloatType, Dim, D > &distanceFunction, size_t n_elems, const std::vector< Point< FloatType, Dim > > &fixed_pts={}, const VulPolyParams< FloatType > ¶ms={}, size_t seed=0)
Generate a VulPoly mesh from a requested number of seeds.
Definition mesher.hpp:768
auto buildOctahedronTessellation(const Point< FloatType, 3 > &corner_a, const Point< FloatType, 3 > &corner_b, const Point< IndexType, 3 > &n_divisions)
Build a 3D hexahedral-domain mesh from an octahedral seed pattern.
Definition mesher.hpp:956
Definition abs_agg_model.cpp:40
Eigen::Matrix< DataType, Dim, 1, Eigen::ColMajor > Point
Definition traits.hpp:34
void voronoi(const std::array< Point< double, Dim >, 2 > &bbox, std::vector< Point< double, Dim > > &points, const std::function< void(VoronoiCell< Dim > &cell, int32_t id)> &cell_callback)
Computes a Voronoi tessellation in either 2D or 3D space.
Definition voronoi.hpp:123
void voronoi2D(const std::array< Point< double, 2 >, 2 > &bbox, const std::vector< Point< double, 2 > > &points, const std::function< void(voro::voronoicell_neighbor_2d &cell, int32_t id)> &cell_callback)
Computes a 2D Voronoi tessellation for a given set of points within a bounding box.
Definition voronoi.cpp:44
void voronoi3D(const std::array< Point< double, 3 >, 2 > &bbox, const std::vector< Point< double, 3 > > &points, const std::function< void(voro::voronoicell_neighbor &cell, int32_t id)> &cell_callback)
Computes a 3D Voronoi tessellation for a given set of points within a bounding box.
Definition voronoi.cpp:72
auto computeDistance(const Point< FloatType, Dim > &point, const DistanceExpression< FloatType, Dim, D > &distance_function)
Computes the signed distance between a point and a shape defined by a distance function.
Definition distance.hpp:936
std::vector< std::array< double, M > > additiveRecurrence(std::size_t n0, std::size_t n1)
Generates a sequence of points using an additive recurrence formula.
Definition additive_recurrence.hpp:102
constexpr T pi()
Returns the value of pi.
Definition vmath.hpp:222
Definition cell_manager.hpp:38
Parameters controlling VulPoly relaxation and mesh cleanup.
Definition mesher.hpp:72
const FloatType collapse_edge_toll
Relative threshold below which a 2D edge may be collapsed.
Definition mesher.hpp:86
const FloatType finite_difference_h
Step size used in finite-difference boundary-gradient estimates.
Definition mesher.hpp:78
const FloatType clipping_relax
Maximum fraction of the characteristic width for boundary clipping.
Definition mesher.hpp:84
const FloatType area_relax
Multiplier for the characteristic cell width used during relaxation.
Definition mesher.hpp:74
const size_t max_iter
Maximum number of centroidal relaxation iterations.
Definition mesher.hpp:82
const FloatType toll
Convergence tolerance for the normalized centroid displacement.
Definition mesher.hpp:76
const bool clip_to_bnd
Whether to project nearby output vertices toward the domain boundary.
Definition mesher.hpp:88
const FloatType reflection_relax
Minimum reflected-point clearance as a fraction of boundary distance.
Definition mesher.hpp:80