OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{Model.cpp} Namespace Reference

Classes

struct  ExclusionPrismFootprintTriangle

Functions

static double cross_2d (const Vec2d &a, const Vec2d &b)
template<class DistanceFn>
static std::vector< Vec3d > clip_polygon_by_signed_distance (const std::vector< Vec3d > &input, DistanceFn distance)
static std::vector< ExclusionPrismFootprintTriangle > triangulated_prism_footprints (const Polygon &polygon)
static bool triangle_bbox_intersects_prism_footprint (const Vec3d &p0, const Vec3d &p1, const Vec3d &p2, const ExclusionPrismFootprintTriangle &footprint)
static std::vector< Vec3d > clip_model_triangle_to_prism (const Vec3d &p0, const Vec3d &p1, const Vec3d &p2, const double z_min, const double z_max, const ExclusionPrismFootprintTriangle &footprint)
static double polygon_3d_area2 (const std::vector< Vec3d > &polygon)
static void append_clipped_polygon (indexed_triangle_set &out, const std::vector< Vec3d > &polygon)
static bool mesh_contains_point_linear (const indexed_triangle_set &its, const Vec3d &point)

Class Documentation

◆ Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle

struct Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle
Collaboration diagram for Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle:
Class Members
Vec2d max = Vec2d::Zero()
Vec2d min = Vec2d::Zero()
array< Vec2d, 3 > vertices

Function Documentation

◆ append_clipped_polygon()

void Slic3r::anonymous_namespace{Model.cpp}::append_clipped_polygon ( indexed_triangle_set & out,
const std::vector< Vec3d > & polygon )
static
3706{
3707 if (polygon.size() < 3)
3708 return;
3709
3710 // Do not reserve exact capacity here. This helper may be called for many
3711 // clipped fragments, so let std::vector grow amortized through emplace_back.
3712 const int base = int(out.vertices.size());
3713 for (const Vec3d &point : polygon)
3714 out.vertices.emplace_back(point.cast<float>());
3715
3716 for (size_t i = 1; i + 1 < polygon.size(); ++i) {
3717 stl_triangle_vertex_indices tri;
3718 tri << base, base + int(i), base + int(i + 1);
3719 out.indices.emplace_back(tri);
3720 }
3721}
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68

References append_clipped_polygon().

Referenced by append_clipped_polygon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clip_model_triangle_to_prism()

std::vector< Vec3d > Slic3r::anonymous_namespace{Model.cpp}::clip_model_triangle_to_prism ( const Vec3d & p0,
const Vec3d & p1,
const Vec3d & p2,
const double z_min,
const double z_max,
const ExclusionPrismFootprintTriangle & footprint )
static
3677{
3678 std::vector<Vec3d> clipped = { p0, p1, p2 };
3679 clipped = clip_polygon_by_signed_distance(clipped, [z_min](const Vec3d &p) { return p.z() - z_min; });
3680 clipped = clip_polygon_by_signed_distance(clipped, [z_max](const Vec3d &p) { return z_max - p.z(); });
3681
3682 for (size_t i = 0; i < footprint.vertices.size() && clipped.size() >= 3; ++i) {
3683 const Vec2d &a = footprint.vertices[i];
3684 const Vec2d &b = footprint.vertices[(i + 1) % footprint.vertices.size()];
3685 const Vec2d edge = b - a;
3686 clipped = clip_polygon_by_signed_distance(clipped, [a, edge](const Vec3d &p) {
3687 return cross_2d(edge, Vec2d(p.x() - a.x(), p.y() - a.y()));
3688 });
3689 }
3690
3691 return clipped;
3692}
static std::vector< Vec3d > clip_polygon_by_signed_distance(const std::vector< Vec3d > &input, DistanceFn distance)
Definition Model.cpp:3574
static double cross_2d(const Vec2d &a, const Vec2d &b)
Definition Model.cpp:3568
std::array< Vec2d, 3 > vertices
Definition Model.cpp:3563
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References clip_model_triangle_to_prism(), clip_polygon_by_signed_distance(), cross_2d(), and Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle::vertices.

Referenced by clip_model_triangle_to_prism().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clip_polygon_by_signed_distance()

template<class DistanceFn>
std::vector< Vec3d > Slic3r::anonymous_namespace{Model.cpp}::clip_polygon_by_signed_distance ( const std::vector< Vec3d > & input,
DistanceFn distance )
static
3575{
3576 constexpr double clip_epsilon = 1e-8;
3577 constexpr double duplicate_epsilon_sq = 1e-16;
3578
3579 std::vector<Vec3d> output;
3580 if (input.empty())
3581 return output;
3582
3583 auto append_point = [&output](const Vec3d &point) {
3584 if (output.empty() || (output.back() - point).squaredNorm() > duplicate_epsilon_sq)
3585 output.emplace_back(point);
3586 };
3587
3588 Vec3d prev = input.back();
3589 double prev_distance = distance(prev);
3590 bool prev_inside = prev_distance >= -clip_epsilon;
3591 for (const Vec3d &curr : input) {
3592 const double curr_distance = distance(curr);
3593 const bool curr_inside = curr_distance >= -clip_epsilon;
3594
3595 if (curr_inside != prev_inside) {
3596 const double denom = prev_distance - curr_distance;
3597 if (std::abs(denom) > clip_epsilon) {
3598 const double t = prev_distance / denom;
3599 append_point(prev + t * (curr - prev));
3600 }
3601 }
3602 if (curr_inside)
3603 append_point(curr);
3604
3605 prev = curr;
3606 prev_distance = curr_distance;
3607 prev_inside = curr_inside;
3608 }
3609
3610 if (output.size() > 1 && (output.front() - output.back()).squaredNorm() <= duplicate_epsilon_sq)
3611 output.pop_back();
3612
3613 return output;
3614}
void append_point(Points &points, const Point &point)
Definition ExclusionVolumeTravelAvoidance.cpp:247

References clip_polygon_by_signed_distance().

Referenced by clip_model_triangle_to_prism(), and clip_polygon_by_signed_distance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cross_2d()

double Slic3r::anonymous_namespace{Model.cpp}::cross_2d ( const Vec2d & a,
const Vec2d & b )
static
3569{
3570 return a.x() * b.y() - a.y() * b.x();
3571}

References cross_2d().

Referenced by clip_model_triangle_to_prism(), cross_2d(), and triangulated_prism_footprints().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mesh_contains_point_linear()

bool Slic3r::anonymous_namespace{Model.cpp}::mesh_contains_point_linear ( const indexed_triangle_set & its,
const Vec3d & point )
static
3724{
3725 constexpr double ray_epsilon = 1e-6;
3726 const Vec3d ray_direction = Vec3d::UnitX();
3727 double nearest_hit_distance = std::numeric_limits<double>::infinity();
3728 size_t nearest_face = size_t(-1);
3729
3730 for (size_t face_id = 0; face_id < its.indices.size(); ++face_id) {
3731 const stl_triangle_vertex_indices &face = its.indices[face_id];
3732 double distance;
3733 double u;
3734 double v;
3736 point, ray_direction,
3737 its.vertices[face[0]], its.vertices[face[1]], its.vertices[face[2]],
3738 distance, u, v, ray_epsilon) &&
3739 distance > 0.0 && distance < nearest_hit_distance) {
3740 nearest_hit_distance = distance;
3741 nearest_face = face_id;
3742 }
3743 }
3744
3745 // This matches AABBMesh::hit_result::is_inside(): for a consistently
3746 // oriented closed mesh, the nearest face points along a ray leaving it.
3747 return nearest_face != size_t(-1) &&
3748 its_unnormalized_normal(its, nearest_face).cast<double>().dot(ray_direction) > 0.0;
3749}
std::enable_if_t< std::is_same< typename V::Scalar, double >::value &&std::is_same< typename W::Scalar, double >::value, bool > intersect_triangle(const V &orig, const V &dir, const W &vert0, const W &vert1, const W &vert2, double &t, double &u, double &v, double eps)
Definition AABBTreeIndirect.hpp:321
stl_normal its_unnormalized_normal(const indexed_triangle_set &its, size_t face_id)
Definition TriangleMesh.hpp:320
T dot(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:154

References Slic3r::dot(), Slic3r::AABBTreeIndirect::detail::intersect_triangle(), Slic3r::its_unnormalized_normal(), and mesh_contains_point_linear().

Referenced by mesh_contains_point_linear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ polygon_3d_area2()

double Slic3r::anonymous_namespace{Model.cpp}::polygon_3d_area2 ( const std::vector< Vec3d > & polygon)
static
3695{
3696 if (polygon.size() < 3)
3697 return 0.0;
3698
3699 Vec3d normal = Vec3d::Zero();
3700 for (size_t i = 1; i + 1 < polygon.size(); ++i)
3701 normal += (polygon[i] - polygon.front()).cross(polygon[i + 1] - polygon.front());
3702 return normal.norm();
3703}
Point normal(Point pt, double scale)
Definition TreeSupport.cpp:112

References Slic3r::normal(), and polygon_3d_area2().

Referenced by polygon_3d_area2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triangle_bbox_intersects_prism_footprint()

bool Slic3r::anonymous_namespace{Model.cpp}::triangle_bbox_intersects_prism_footprint ( const Vec3d & p0,
const Vec3d & p1,
const Vec3d & p2,
const ExclusionPrismFootprintTriangle & footprint )
static
3657{
3658 constexpr double bbox_epsilon = 1e-8;
3659 const double tri_min_x = std::min({ p0.x(), p1.x(), p2.x() });
3660 const double tri_max_x = std::max({ p0.x(), p1.x(), p2.x() });
3661 const double tri_min_y = std::min({ p0.y(), p1.y(), p2.y() });
3662 const double tri_max_y = std::max({ p0.y(), p1.y(), p2.y() });
3663
3664 return tri_max_x >= footprint.min.x() - bbox_epsilon &&
3665 tri_min_x <= footprint.max.x() + bbox_epsilon &&
3666 tri_max_y >= footprint.min.y() - bbox_epsilon &&
3667 tri_min_y <= footprint.max.y() + bbox_epsilon;
3668}

References Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle::max, Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle::min, and triangle_bbox_intersects_prism_footprint().

Referenced by triangle_bbox_intersects_prism_footprint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triangulated_prism_footprints()

std::vector< ExclusionPrismFootprintTriangle > Slic3r::anonymous_namespace{Model.cpp}::triangulated_prism_footprints ( const Polygon & polygon)
static
3617{
3618 std::vector<ExclusionPrismFootprintTriangle> out;
3619 if (polygon.points.size() < 3)
3620 return out;
3621
3622 ExPolygon expolygon;
3623 expolygon.contour = polygon;
3624 expolygon.contour.make_counter_clockwise();
3625
3626 std::vector<Vec2d> triangles = triangulate_expolygon_2d(expolygon, NORMALS_UP);
3627 if (triangles.empty()) {
3628 triangles.reserve((polygon.points.size() - 2) * 3);
3629 const Vec2d first(unscale<double>(polygon.points.front().x()), unscale<double>(polygon.points.front().y()));
3630 for (size_t i = 1; i + 1 < polygon.points.size(); ++i) {
3631 triangles.emplace_back(first);
3632 triangles.emplace_back(unscale<double>(polygon.points[i].x()), unscale<double>(polygon.points[i].y()));
3633 triangles.emplace_back(unscale<double>(polygon.points[i + 1].x()), unscale<double>(polygon.points[i + 1].y()));
3634 }
3635 }
3636
3637 out.reserve(triangles.size() / 3);
3638 for (size_t i = 0; i + 2 < triangles.size(); i += 3) {
3639 ExclusionPrismFootprintTriangle tri;
3640 tri.vertices = { triangles[i], triangles[i + 1], triangles[i + 2] };
3641
3642 const double area = cross_2d(tri.vertices[1] - tri.vertices[0], tri.vertices[2] - tri.vertices[0]);
3643 if (std::abs(area) <= EPSILON)
3644 continue;
3645 if (area < 0.0)
3646 std::swap(tri.vertices[1], tri.vertices[2]);
3647
3648 tri.min = tri.vertices[0].cwiseMin(tri.vertices[1]).cwiseMin(tri.vertices[2]);
3649 tri.max = tri.vertices[0].cwiseMax(tri.vertices[1]).cwiseMax(tri.vertices[2]);
3650 out.emplace_back(std::move(tri));
3651 }
3652
3653 return out;
3654}
#define EPSILON
Definition ColorUtils.cpp:64
Definition ExPolygon.hpp:23
Polygon contour
Definition ExPolygon.hpp:42
Points points
Definition MultiPoint.hpp:22
bool make_counter_clockwise()
Definition Polygon.cpp:94
const bool constexpr NORMALS_UP
Definition Tesselate.hpp:14
double area(const ExPolygon &poly)
Definition ExPolygon.hpp:511
std::vector< Vec2d > triangulate_expolygon_2d(const ExPolygon &poly, bool flip)
Definition Tesselate.cpp:216
T unscale(Q v)
Definition libslic3r.h:138

References Slic3r::area(), Slic3r::ExPolygon::contour, cross_2d(), EPSILON, Slic3r::Polygon::make_counter_clockwise(), Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle::max, Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle::min, Slic3r::NORMALS_UP, Slic3r::MultiPoint::points, Slic3r::triangulate_expolygon_2d(), triangulated_prism_footprints(), Slic3r::unscale(), and Slic3r::anonymous_namespace{Model.cpp}::ExclusionPrismFootprintTriangle::vertices.

Referenced by triangulated_prism_footprints().

Here is the call graph for this function:
Here is the caller graph for this function: