1 #if defined(__GNUG__) && !defined(__clang__)
2 #pragma GCC diagnostic push
3 #pragma GCC diagnostic ignored "-Wnull-dereference"
6 #if defined(__GNUG__) && !defined(__clang__)
7 #pragma GCC diagnostic pop
18 #include <fastenvelope/FastEnvelope.h>
19 #include <SimpleBVH/BVH.hpp>
34 , m_coordinate_handle(coordinate)
35 , m_envelope_size(envelope_size)
37 const auto& envelope_mesh = envelope_mesh_coordinate.
mesh();
39 assert(envelope_mesh_coordinate.
holds<
Rational>() || envelope_mesh_coordinate.
holds<
double>());
44 envelope_mesh.create_const_accessor(envelope_mesh_coordinate.
as<
Rational>());
48 std::vector<Eigen::Vector3d>
vertices;
49 std::vector<Eigen::Vector3i>
faces;
55 for (
const auto& f : facest) {
64 faces.emplace_back(count, count + 1, count + 2);
73 std::make_shared<fastEnvelope::FastEnvelope>(
vertices,
faces, envelope_size);
76 logger().warn(
"Envelope for edge mesh is using sampling");
84 Eigen::MatrixXi
edges(edgest.size(), 2);
86 for (
const auto& e : edgest) {
91 edges.row(index) << count, count + 1;
99 m_bvh = std::make_shared<SimpleBVH::BVH>();
102 throw std::runtime_error(
"Envelope works only for tri/edges meshes");
104 }
else if (envelope_mesh_coordinate.
holds<
double>()) {
107 envelope_mesh.create_const_accessor(envelope_mesh_coordinate.
as<
double>());
111 std::vector<Eigen::Vector3d>
vertices;
112 std::vector<Eigen::Vector3i>
faces;
118 for (
const auto& f : facest) {
125 faces.emplace_back(count, count + 1, count + 2);
134 std::make_shared<fastEnvelope::FastEnvelope>(
vertices,
faces, envelope_size);
137 logger().warn(
"Envelope for edge mesh is using sampling");
145 Eigen::MatrixXi
edges(edgest.size(), 2);
147 for (
const auto& e : edgest) {
151 edges.row(index) << count, count + 1;
159 m_bvh = std::make_shared<SimpleBVH::BVH>();
162 throw std::runtime_error(
"Envelope works only for tri/edges meshes");
165 throw std::runtime_error(
"Envelope mesh handle type invlid");
170 const std::vector<Tuple>& top_dimension_tuples_before,
171 const std::vector<Tuple>& top_dimension_tuples_after)
const
173 if (top_dimension_tuples_after.empty())
return true;
185 std::vector<Tuple>
faces;
188 std::array<Eigen::Vector3d, 3> triangle;
190 for (
const Tuple& tuple : top_dimension_tuples_after) {
208 for (
const Tuple& tuple : top_dimension_tuples_after) {
225 for (
const Tuple& tuple : top_dimension_tuples_after) {
236 throw std::runtime_error(
"Invalid mesh type");
242 SimpleBVH::VectorMax3d nearest_point;
247 const double real_envelope_2 = real_envelope * real_envelope;
250 std::vector<SimpleBVH::VectorMax3d> pts;
252 for (
const Tuple& tuple : top_dimension_tuples_after) {
258 const int64_t N = (p0 - p1).norm() / d + 1;
259 pts.reserve(pts.size() + N);
261 for (int64_t n = 0; n <= N; n++) {
262 auto tmp = p0 * (double(n) / N) + p1 * (N -
double(n)) / N;
267 auto current_point = pts[0];
269 int prev_facet =
m_bvh->nearest_facet(current_point, nearest_point, sq_dist);
270 if (sq_dist > real_envelope_2) {
275 for (
const auto& v : pts) {
276 sq_dist = (v - nearest_point).squaredNorm();
277 m_bvh->nearest_facet_with_hint(v, prev_facet, nearest_point, sq_dist);
278 if (sq_dist > real_envelope_2) {
286 for (
const Tuple& tuple : top_dimension_tuples_after) {
288 m_bvh->nearest_facet(p, nearest_point, sq_dist);
297 throw std::runtime_error(
"Invalid mesh type");
309 std::vector<Tuple>
faces;
312 std::array<Eigen::Vector3d, 3> triangle;
314 for (
const Tuple& tuple : top_dimension_tuples_after) {
332 for (
const Tuple& tuple : top_dimension_tuples_after) {
349 for (
const Tuple& tuple : top_dimension_tuples_after) {
360 throw std::runtime_error(
"Invalid mesh type");
366 SimpleBVH::VectorMax3d nearest_point;
371 const double real_envelope_2 = real_envelope * real_envelope;
374 std::vector<SimpleBVH::VectorMax3d> pts;
376 for (
const Tuple& tuple : top_dimension_tuples_after) {
377 SimpleBVH::VectorMax3d p0 =
379 SimpleBVH::VectorMax3d p1 =
383 const int64_t N = (p0 - p1).norm() / d + 1;
384 pts.reserve(pts.size() + N);
386 for (int64_t n = 0; n <= N; n++) {
387 auto tmp = p0 * (double(n) / N) + p1 * (N -
double(n)) / N;
392 auto current_point = pts[0];
394 int prev_facet =
m_bvh->nearest_facet(current_point, nearest_point, sq_dist);
395 if (sq_dist > real_envelope_2) {
400 for (
const auto& v : pts) {
401 sq_dist = (v - nearest_point).squaredNorm();
402 m_bvh->nearest_facet_with_hint(v, prev_facet, nearest_point, sq_dist);
403 if (sq_dist > real_envelope_2) {
411 for (
const Tuple& tuple : top_dimension_tuples_after) {
413 m_bvh->nearest_facet(p, nearest_point, sq_dist);
422 throw std::runtime_error(
"Invalid mesh type");
427 throw std::runtime_error(
"Envelope mesh handle type invlid");
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
PrimitiveType top_simplex_type() const
A CachingAccessor that uses tuples for accessing attributes instead of indices.
int64_t dimension() const
ConstMapResult< D > const_vector_attribute(const ArgType &t) const
auto as() const -> const held_handle_type< held_type_from_primitive< T >()> &
std::shared_ptr< fastEnvelope::FastEnvelope > m_envelope
bool after(const std::vector< Tuple > &top_dimension_tuples_before, const std::vector< Tuple > &top_dimension_tuples_after) const override
const double m_envelope_size
EnvelopeInvariant(const attribute::MeshAttributeHandle &envelope_mesh_coordinate, double envelope_size, const attribute::MeshAttributeHandle &coordinate)
std::shared_ptr< SimpleBVH::BVH > m_bvh
const attribute::MeshAttributeHandle m_coordinate_handle
const Mesh & mesh() const
std::vector< Tuple > vertices(const Mesh &m, const Simplex &simplex)
std::vector< Tuple > edges(const Mesh &m, const Simplex &simplex)
std::vector< Tuple > faces_single_dimension_tuples(const Mesh &mesh, const Simplex &simplex, const PrimitiveType face_type)
SimplexCollection faces(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Returns all faces of a simplex.
constexpr PrimitiveType PV
spdlog::logger & logger()
Retrieves the current logger.
Vector< double, 3 > Vector3d
constexpr PrimitiveType PE