OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::TriangleCursor Class Reference
Inheritance diagram for Slic3r::TriangleCursor:
Collaboration diagram for Slic3r::TriangleCursor:

Public Member Functions

 TriangleCursor ()=delete
 TriangleCursor (const Vec3f &center_, const Vec3f &source_, float radius_world, const Transform3d &trafo_, const TriangleSelector::ClippingPlane &clipping_plane_, const std::array< const Vec3f, 3 > &vertices)
 ~TriangleCursor () override=default
bool is_mesh_point_inside (const Vec3f &point) const override
bool is_edge_inside_cursor (const TriangleSelector::Triangle &tr, const std::vector< TriangleSelector::Vertex > &vertices) const override
bool is_facet_visible (int facet_idx, const std::vector< Vec3f > &face_normals) const override
bool is_pointer_in_triangle (const Vec3f &p1, const Vec3f &p2, const Vec3f &p3) const override
bool is_pointer_in_triangle (const Triangle &tr, const std::vector< Vertex > &vertices) const
virtual int vertices_inside (const Triangle &tr, const std::vector< Vertex > &vertices) const

Static Public Member Functions

static std::unique_ptr< Cursor > build_cursor (const TriangleSelector &source_selector, const TriangleSelector::Triangle &tri)
static bool check_normal (const Vec3f &facet_norm, const Vec3f &camera_dir)
static std::unique_ptr< Cursor > cursor_factory (const Vec3f &center, const Vec3f &camera_pos, const float cursor_radius, const CursorType cursor_type, const Transform3d &trafo_matrix, const ClippingPlane &clipping_plane)
static std::unique_ptr< Cursor > cursor_factory (float z_world, const Vec3f &camera_pos, const float height, const Transform3d &trafo_matrix, const ClippingPlane &clipping_plane)
static bool is_facet_visible (const Cursor &cursor, int facet_idx, const std::vector< Vec3f > &face_normals)

Static Public Attributes

static constexpr float tolerance = 0.01f

Protected Attributes

Vec3f center
Transform3f trafo
Vec3f source
bool uniform_scaling
Transform3f trafo_normal
float radius
float radius_sqr
Vec3f dir = Vec3f(0.f, 0.f, 0.f)
ClippingPlane clipping_plane
friend TriangleSelector

Static Private Member Functions

static float point_to_line_dist (const Vec3f &p, const Vec3f &a, const Vec3f &b)

Private Attributes

const Barycentric barycentric_

Static Private Attributes

static const double facet_angle_limit = cos(Geometry::deg2rad(5.0))

Detailed Description

Constructor & Destructor Documentation

◆ TriangleCursor() [1/2]

Slic3r::TriangleCursor::TriangleCursor ( )
delete

◆ TriangleCursor() [2/2]

Slic3r::TriangleCursor::TriangleCursor ( const Vec3f & center_,
const Vec3f & source_,
float radius_world,
const Transform3d & trafo_,
const TriangleSelector::ClippingPlane & clipping_plane_,
const std::array< const Vec3f, 3 > & vertices )
inlineexplicit
2379 : TriangleSelector::SinglePointCursor(center_, source_, radius_world, trafo_, clipping_plane_)
2380 , barycentric_(vertices[0], vertices[1], vertices[2])
2381 {}
const Barycentric barycentric_
Definition TriangleSelector.cpp:2485

References Slic3r::TriangleSelector::SinglePointCursor::SinglePointCursor(), and barycentric_.

Here is the call graph for this function:

◆ ~TriangleCursor()

Slic3r::TriangleCursor::~TriangleCursor ( )
overridedefault

Member Function Documentation

◆ build_cursor()

std::unique_ptr< Cursor > Slic3r::TriangleCursor::build_cursor ( const TriangleSelector & source_selector,
const TriangleSelector::Triangle & tri )
inlinestatic
2385 {
2386 const Vec3f& pv0 = source_selector.m_vertices[tri.verts_idxs[0]].v;
2387 const Vec3f& pv1 = source_selector.m_vertices[tri.verts_idxs[1]].v;
2388 const Vec3f& pv2 = source_selector.m_vertices[tri.verts_idxs[2]].v;
2389
2390 // Calculate the centroid of the triangle
2391 const Vec3f center = (pv0 + pv1 + pv2) / 3.f;
2392
2393 // Calculate the norm of the plane
2394 const Vec3f& norm = source_selector.m_face_normals[tri.source_triangle];
2395
2396 // Calculate the min distance from the centroid to every edges
2397 const float radius = std::max(std::min(std::min(point_to_line_dist(center, pv0, pv1), point_to_line_dist(center, pv0, pv2)),
2398 point_to_line_dist(center, pv1, pv2)), 0.1f);
2399
2400 return std::make_unique<TriangleCursor>(center, center + norm, radius, Transform3d::Identity(), TriangleSelector::ClippingPlane(),
2401 std::array<const Vec3f, 3>{pv0, pv1, pv2});
2402 }
static float point_to_line_dist(const Vec3f &p, const Vec3f &a, const Vec3f &b)
Definition TriangleSelector.cpp:2488
float radius
Definition TriangleSelector.hpp:126
Vec3f center
Definition TriangleSelector.hpp:160
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65

References Slic3r::TriangleSelector::SinglePointCursor::center, Slic3r::TriangleSelector::m_face_normals, Slic3r::TriangleSelector::m_vertices, point_to_line_dist(), Slic3r::TriangleSelector::Cursor::radius, Slic3r::TriangleSelector::Triangle::source_triangle, and Slic3r::TriangleSelector::Triangle::verts_idxs.

Referenced by Slic3r::TriangleSelector::remap_painting().

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

◆ check_normal()

bool Slic3r::TriangleCursor::check_normal ( const Vec3f & facet_norm,
const Vec3f & camera_dir )
inlinestatic
2477 {
2478 const float a = -(facet_norm.dot(camera_dir));
2479 return std::clamp(a, 0.f, 1.f) >= facet_angle_limit;
2480 }
static const double facet_angle_limit
Definition TriangleSelector.cpp:2486

References facet_angle_limit.

Referenced by is_facet_visible(), and Slic3r::TriangleSelector::remap_painting().

Here is the caller graph for this function:

◆ cursor_factory() [1/2]

std::unique_ptr< Cursor > Slic3r::TriangleSelector::SinglePointCursor::cursor_factory ( const Vec3f & center,
const Vec3f & camera_pos,
const float cursor_radius,
const CursorType cursor_type,
const Transform3d & trafo_matrix,
const ClippingPlane & clipping_plane )
inlinestaticinherited
144 {
145 assert(cursor_type == TriangleSelector::CursorType::CIRCLE || cursor_type == TriangleSelector::CursorType::SPHERE);
146 if (cursor_type == TriangleSelector::CursorType::SPHERE)
147 return std::make_unique<TriangleSelector::Sphere>(center, camera_pos, cursor_radius, trafo_matrix, clipping_plane);
148 else
149 return std::make_unique<TriangleSelector::Circle>(center, camera_pos, cursor_radius, trafo_matrix, clipping_plane);
150 }
ClippingPlane clipping_plane
Definition TriangleSelector.hpp:130
@ SPHERE
Definition TriangleSelector.hpp:83
@ CIRCLE
Definition TriangleSelector.hpp:82

References center, Slic3r::TriangleSelector::CIRCLE, Slic3r::TriangleSelector::Cursor::clipping_plane, and Slic3r::TriangleSelector::SPHERE.

Referenced by Slic3r::GUI::GLGizmoPainterBase::gizmo_event().

Here is the caller graph for this function:

◆ cursor_factory() [2/2]

std::unique_ptr< Cursor > Slic3r::TriangleSelector::SinglePointCursor::cursor_factory ( float z_world,
const Vec3f & camera_pos,
const float height,
const Transform3d & trafo_matrix,
const ClippingPlane & clipping_plane )
inlinestaticinherited
153 {
154 return std::make_unique<TriangleSelector::HeightRange>(z_world, camera_pos, height, trafo_matrix, clipping_plane);
155 }

References Slic3r::TriangleSelector::Cursor::clipping_plane.

◆ is_edge_inside_cursor()

bool Slic3r::TriangleCursor::is_edge_inside_cursor ( const TriangleSelector::Triangle & tr,
const std::vector< TriangleSelector::Vertex > & vertices ) const
inlineoverridevirtual

Implements Slic3r::TriangleSelector::Cursor.

2410 {
2411 std::array<Vec3f, 3> pts_proj; // Projected point onto the plane
2412 std::array<float, 3> pts_dist; // Distance to the plane, positive means above, negative means below the plane
2413 for (int i = 0; i < 3; ++i) {
2414 Vec3f p = vertices[tr.verts_idxs[i]].v;
2415 if (!this->uniform_scaling)
2416 p = this->trafo * p;
2417
2418 const Vec3f diff = p - center;
2419 pts_dist[i] = diff.dot(dir);
2420 pts_proj[i] = p - pts_dist[i] * dir;
2421 }
2422
2423 for (int side = 0; side < 3; ++side) {
2424 const int idx_a = side;
2425 const int idx_b = side < 2 ? side + 1 : 0;
2426
2427 // If both ends at the same side and farther than tolerance, skip
2428 const float dist_a = pts_dist[idx_a];
2429 const float dist_b = pts_dist[idx_b];
2430 if ((dist_a > tolerance && dist_b > tolerance) || (dist_a < -tolerance && dist_b < -tolerance)) {
2431 continue;
2432 }
2433
2434 // Find the projected line segment which has distance to the plane within the tolerance
2435 Vec3f pt_a = pts_proj[idx_a];
2436 Vec3f pt_b = pts_proj[idx_b];
2437 if (std::abs(dist_a) > tolerance) {
2438 pt_a = (tolerance - dist_b) / (dist_a - dist_b) * (pts_proj[idx_a] - pts_proj[idx_b]) + pts_proj[idx_b];
2439 }
2440 if (std::abs(dist_b) > tolerance) {
2441 pt_b = (tolerance - dist_a) / (dist_b - dist_a) * (pts_proj[idx_b] - pts_proj[idx_a]) + pts_proj[idx_a];
2442 }
2443
2444 // If any projected end is inside the triangle, then is in
2445 if (barycentric_.is_point_inside_triangle(pt_a) ||
2446 barycentric_.is_point_inside_triangle(pt_b)) {
2447 return true;
2448 }
2449
2450 // Otherwise see if the segment (pt_a, pt_b) intersects the triangle
2451 {
2452 const Vec3f uvw_a = barycentric_.calc(pt_a);
2453 const Vec3f uvw_b = barycentric_.calc(pt_b);
2454 const Vec3f uvw_0 {1.f,0.f,0.f};
2455 const Vec3f uvw_1 {0.f,1.f,0.f};
2456 const Vec3f uvw_2 {0.f,0.f,1.f};
2457 constexpr std::pair<int, int> proj{0, 1};
2458
2459 if (segments_intersect_proj(uvw_a, uvw_b, uvw_0, uvw_1, proj)||
2460 segments_intersect_proj(uvw_a, uvw_b, uvw_0, uvw_2, proj)||
2461 segments_intersect_proj(uvw_a, uvw_b, uvw_1, uvw_2, proj)) {
2462 return true;
2463 }
2464 }
2465 }
2466 return false;
2467 }
static constexpr float tolerance
Definition TriangleSelector.cpp:2482
Transform3f trafo
Definition TriangleSelector.hpp:121
bool uniform_scaling
Definition TriangleSelector.hpp:124
Vec3f dir
Definition TriangleSelector.hpp:128
static bool segments_intersect_proj(const Vec3f &p1, const Vec3f &p2, const Vec3f &p3, const Vec3f &p4, const std::pair< int, int > &proj)
Definition TriangleSelector.cpp:2350
Slic3r::Polygons diff(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:731

References barycentric_, Slic3r::TriangleSelector::SinglePointCursor::center, Slic3r::diff(), Slic3r::TriangleSelector::Cursor::dir, Slic3r::segments_intersect_proj(), tolerance, Slic3r::TriangleSelector::Cursor::trafo, Slic3r::TriangleSelector::Cursor::uniform_scaling, and Slic3r::TriangleSelector::Triangle::verts_idxs.

Here is the call graph for this function:

◆ is_facet_visible() [1/2]

bool Slic3r::TriangleCursor::is_facet_visible ( int facet_idx,
const std::vector< Vec3f > & face_normals ) const
inlineoverridevirtual

Implements Slic3r::TriangleSelector::Cursor.

2470 {
2471 const Vec3f& n = face_normals[facet_idx];
2472
2473 return check_normal(n, this->dir);
2474 }
static bool check_normal(const Vec3f &facet_norm, const Vec3f &camera_dir)
Definition TriangleSelector.cpp:2476

References check_normal(), and Slic3r::TriangleSelector::Cursor::dir.

Here is the call graph for this function:

◆ is_facet_visible() [2/2]

bool Slic3r::TriangleSelector::Cursor::is_facet_visible ( const Cursor & cursor,
int facet_idx,
const std::vector< Vec3f > & face_normals )
staticinherited
1101{
1102 assert(facet_idx < int(face_normals.size()));
1103 Vec3f n = face_normals[facet_idx];
1104 if (!cursor.uniform_scaling)
1105 n = cursor.trafo_normal * n;
1106 return n.dot(cursor.dir) < 0.f;
1107}

References Cursor(), dir, trafo_normal, and uniform_scaling.

Here is the call graph for this function:

◆ is_mesh_point_inside()

bool Slic3r::TriangleCursor::is_mesh_point_inside ( const Vec3f & point) const
inlineoverridevirtual

Implements Slic3r::TriangleSelector::Cursor.

2405 {
2406 return barycentric_.is_point_inside_triangle(point);
2407 }

References barycentric_.

◆ is_pointer_in_triangle() [1/2]

bool Slic3r::TriangleSelector::Cursor::is_pointer_in_triangle ( const Triangle & tr,
const std::vector< Vertex > & vertices ) const
inherited
1092 {
1093 const Vec3f& p1 = vertices[tr.verts_idxs[0]].v;
1094 const Vec3f& p2 = vertices[tr.verts_idxs[1]].v;
1095 const Vec3f& p3 = vertices[tr.verts_idxs[2]].v;
1096 return this->is_pointer_in_triangle(p1, p2, p3);
1097}
bool is_pointer_in_triangle(const Triangle &tr, const std::vector< Vertex > &vertices) const
Definition TriangleSelector.cpp:1092

References is_pointer_in_triangle(), and Slic3r::TriangleSelector::Triangle::verts_idxs.

Referenced by is_pointer_in_triangle().

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

◆ is_pointer_in_triangle() [2/2]

bool Slic3r::TriangleSelector::SinglePointCursor::is_pointer_in_triangle ( const Vec3f & p1,
const Vec3f & p2,
const Vec3f & p3 ) const
overridevirtualinherited

Implements Slic3r::TriangleSelector::Cursor.

2237{
2239}
static bool is_circle_pointer_inside_triangle(const Vec3f &p1_, const Vec3f &p2_, const Vec3f &p3_, const Vec3f &center, const Vec3f &dir, const bool uniform_scaling, const Transform3f &trafo)
Definition TriangleSelector.cpp:2214

References center, Slic3r::TriangleSelector::Cursor::dir, Slic3r::is_circle_pointer_inside_triangle(), Slic3r::TriangleSelector::Cursor::trafo, and Slic3r::TriangleSelector::Cursor::uniform_scaling.

Here is the call graph for this function:

◆ point_to_line_dist()

float Slic3r::TriangleCursor::point_to_line_dist ( const Vec3f & p,
const Vec3f & a,
const Vec3f & b )
inlinestaticprivate
2489 {
2490 const Eigen::ParametrizedLine<float, 3> line = Eigen::ParametrizedLine<float, 3>::Through(a, b);
2491 return line.distance(p);
2492 }

Referenced by build_cursor().

Here is the caller graph for this function:

◆ vertices_inside()

int Slic3r::TriangleSelector::Cursor::vertices_inside ( const Triangle & tr,
const std::vector< Vertex > & vertices ) const
virtualinherited
1111{
1112 int inside = 0;
1113 for (size_t i = 0; i < 3; ++i)
1114 if (this->is_mesh_point_inside(vertices[tr.verts_idxs[i]].v))
1115 ++inside;
1116
1117 return inside;
1118}
virtual bool is_mesh_point_inside(const Vec3f &point) const =0
bool inside(const Polygons &polygons, const Point &p)
Definition TreeNode.cpp:160

References is_mesh_point_inside(), and Slic3r::TriangleSelector::Triangle::verts_idxs.

Here is the call graph for this function:

Member Data Documentation

◆ barycentric_

const Barycentric Slic3r::TriangleCursor::barycentric_
private

◆ center

◆ clipping_plane

◆ dir

◆ facet_angle_limit

const double Slic3r::TriangleCursor::facet_angle_limit = cos(Geometry::deg2rad(5.0))
staticprivate

Referenced by check_normal().

◆ radius

◆ radius_sqr

◆ source

◆ tolerance

float Slic3r::TriangleCursor::tolerance = 0.01f
staticconstexpr

◆ trafo

◆ trafo_normal

Transform3f Slic3r::TriangleSelector::Cursor::trafo_normal
protectedinherited

Referenced by Cursor(), and is_facet_visible().

◆ TriangleSelector

friend Slic3r::TriangleSelector::Cursor::TriangleSelector
protectedinherited

◆ uniform_scaling


The documentation for this class was generated from the following file: