OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::TriangleSelector::Capsule2D Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/TriangleSelector.hpp>

Inheritance diagram for Slic3r::TriangleSelector::Capsule2D:
Collaboration diagram for Slic3r::TriangleSelector::Capsule2D:

Public Member Functions

 Capsule2D ()=delete
 Capsule2D (const Vec3f &first_center_, const Vec3f &second_center_, const Vec3f &source_, float radius_world, const Transform3d &trafo_, const ClippingPlane &clipping_plane_)
 ~Capsule2D () override=default
bool is_mesh_point_inside (const Vec3f &point) const override
bool is_edge_inside_cursor (const Triangle &tr, const std::vector< 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 > cursor_factory (const Vec3f &first_center, const Vec3f &second_center, const Vec3f &camera_pos, const float cursor_radius, const CursorType cursor_type, 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)

Protected Attributes

Vec3f first_center
Vec3f second_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

Detailed Description

Constructor & Destructor Documentation

◆ Capsule2D() [1/2]

Slic3r::TriangleSelector::Capsule2D::Capsule2D ( )
delete

◆ Capsule2D() [2/2]

Slic3r::TriangleSelector::Capsule2D::Capsule2D ( const Vec3f & first_center_,
const Vec3f & second_center_,
const Vec3f & source_,
float radius_world,
const Transform3d & trafo_,
const ClippingPlane & clipping_plane_ )
inlineexplicit
257 : TriangleSelector::DoublePointCursor(first_center_, second_center_, source_, radius_world, trafo_, clipping_plane_)
258 {}

References Slic3r::TriangleSelector::DoublePointCursor::DoublePointCursor(), and Slic3r::TriangleSelector::Cursor::TriangleSelector.

Here is the call graph for this function:

◆ ~Capsule2D()

Slic3r::TriangleSelector::Capsule2D::~Capsule2D ( )
overridedefault

Member Function Documentation

◆ cursor_factory()

std::unique_ptr< Cursor > Slic3r::TriangleSelector::DoublePointCursor::cursor_factory ( const Vec3f & first_center,
const Vec3f & second_center,
const Vec3f & camera_pos,
const float cursor_radius,
const CursorType cursor_type,
const Transform3d & trafo_matrix,
const ClippingPlane & clipping_plane )
inlinestaticinherited
172 {
173 assert(cursor_type == TriangleSelector::CursorType::CIRCLE || cursor_type == TriangleSelector::CursorType::SPHERE);
174 if (cursor_type == TriangleSelector::CursorType::SPHERE)
175 return std::make_unique<TriangleSelector::Capsule3D>(first_center, second_center, camera_pos, cursor_radius, trafo_matrix, clipping_plane);
176 else
177 return std::make_unique<TriangleSelector::Capsule2D>(first_center, second_center, camera_pos, cursor_radius, trafo_matrix, clipping_plane);
178 }
ClippingPlane clipping_plane
Definition TriangleSelector.hpp:130
Vec3f second_center
Definition TriangleSelector.hpp:184
Vec3f first_center
Definition TriangleSelector.hpp:183
@ SPHERE
Definition TriangleSelector.hpp:83
@ CIRCLE
Definition TriangleSelector.hpp:82

References Slic3r::TriangleSelector::CIRCLE, Slic3r::TriangleSelector::Cursor::clipping_plane, first_center, second_center, and Slic3r::TriangleSelector::SPHERE.

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

Here is the caller graph for this function:

◆ is_edge_inside_cursor()

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

Implements Slic3r::TriangleSelector::Cursor.

2286{
2287 std::array<Vec3f, 3> pts;
2288 for (int i = 0; i < 3; ++i) {
2289 pts[i] = vertices[tr.verts_idxs[i]].v;
2290 if (!this->uniform_scaling)
2291 pts[i] = this->trafo * pts[i];
2292 }
2293
2294 const Vec3f centers_diff = this->second_center - this->first_center;
2295 // Vector in the direction of line |AD| of the rectangle that intersects the circle with the center in first_center.
2296 const Vec3f rectangle_da_dir = centers_diff.cross(this->dir);
2297 // Vector pointing from first_center to the point 'A' of the rectangle.
2298 const Vec3f first_center_rectangle_a_diff = rectangle_da_dir.normalized() * this->radius;
2299 const Vec3f rectangle_a = this->first_center - first_center_rectangle_a_diff;
2300 const Vec3f rectangle_d = this->first_center + first_center_rectangle_a_diff;
2301
2302 auto edge_inside_rectangle = [&self = std::as_const(*this), &centers_diff](const Vec3f &edge_a, const Vec3f &edge_b, const Vec3f &plane_origin, const Vec3f &plane_normal) -> bool {
2303 Vec3f intersection(-1.f, -1.f, -1.f);
2304 if (line_plane_intersection(edge_a, edge_b, plane_origin, plane_normal, intersection)) {
2305 // Now check if the intersection point is inside the rectangle. That means it is between 'first_center' and 'second_center', resp. between 'A' and 'B'.
2306 if (self.first_center.dot(centers_diff) <= intersection.dot(centers_diff) && intersection.dot(centers_diff) <= self.second_center.dot(centers_diff))
2307 return true;
2308 }
2309 return false;
2310 };
2311
2312 for (int side = 0; side < 3; ++side) {
2313 const Vec3f &edge_a = pts[side];
2314 const Vec3f &edge_b = pts[side < 2 ? side + 1 : 0];
2315 const Vec3f edge_dir = edge_b - edge_a;
2316 const Vec3f edge_dir_n = edge_dir.normalized();
2317
2318 float t1 = (this->first_center - edge_a).dot(edge_dir_n);
2319 float t2 = (this->second_center - edge_a).dot(edge_dir_n);
2320 Vec3f vector1 = edge_a + t1 * edge_dir_n - this->first_center;
2321 Vec3f vector2 = edge_a + t2 * edge_dir_n - this->second_center;
2322
2323 // Vectors vector1 and vector2 are 3D vector from centers to the intersections. What we want to
2324 // measure is length of its projection onto plane perpendicular to dir.
2325 if (float dist = vector1.squaredNorm() - std::pow(vector1.dot(this->dir), 2.f); dist < this->radius_sqr && t1 >= 0.f && t1 <= edge_dir.norm())
2326 return true;
2327
2328 if (float dist = vector2.squaredNorm() - std::pow(vector2.dot(this->dir), 2.f); dist < this->radius_sqr && t2 >= 0.f && t2 <= edge_dir.norm())
2329 return true;
2330
2331 // Check if the edge is passing through the rectangle between first_center and second_center.
2332 if (edge_inside_rectangle(edge_a, edge_b, rectangle_a, (rectangle_d - rectangle_a)) || edge_inside_rectangle(edge_a, edge_b, rectangle_d, (rectangle_a - rectangle_d)))
2333 return true;
2334 }
2335
2336 return false;
2337}
Transform3f trafo
Definition TriangleSelector.hpp:121
bool uniform_scaling
Definition TriangleSelector.hpp:124
float radius
Definition TriangleSelector.hpp:126
float radius_sqr
Definition TriangleSelector.hpp:127
Vec3f dir
Definition TriangleSelector.hpp:128
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:298
Vec3d plane_normal(const SurfaceFeature &plane)
Definition Measure.hpp:207
Slic3r::Polygons intersection(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:769
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65
bool line_plane_intersection(const Vec3f &line_a, const Vec3f &line_b, const Vec3f &plane_origin, const Vec3f &plane_normal, Vec3f &out_intersection)
Definition TriangleSelector.cpp:2248
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::TriangleSelector::Cursor::dir, Slic3r::Geometry::dist(), Slic3r::dot(), Slic3r::TriangleSelector::DoublePointCursor::first_center, Slic3r::intersection(), Slic3r::line_plane_intersection(), Slic3r::TriangleSelector::Cursor::radius, Slic3r::TriangleSelector::Cursor::radius_sqr, Slic3r::TriangleSelector::DoublePointCursor::second_center, 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::TriangleSelector::Capsule2D::is_facet_visible ( int facet_idx,
const std::vector< Vec3f > & face_normals ) const
inlineoverridevirtual

Implements Slic3r::TriangleSelector::Cursor.

264 {
265 return TriangleSelector::Cursor::is_facet_visible(*this, facet_idx, face_normals);
266 }
virtual bool is_facet_visible(int facet_idx, const std::vector< Vec3f > &face_normals) const =0

References Slic3r::TriangleSelector::Cursor::is_facet_visible().

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::TriangleSelector::Capsule2D::is_mesh_point_inside ( const Vec3f & point) const
overridevirtual

Implements Slic3r::TriangleSelector::Cursor.

2182{
2183 const Vec3f transformed_point = uniform_scaling ? point : Vec3f(trafo * point);
2184 const Vec3f first_center_diff = this->first_center - transformed_point;
2185 const Vec3f first_center_diff_projected = first_center_diff - first_center_diff.dot(this->dir) * this->dir;
2186 if (first_center_diff_projected.squaredNorm() < this->radius_sqr)
2188
2189 const Vec3f second_center_diff = this->second_center - transformed_point;
2190 const Vec3f second_center_diff_projected = second_center_diff - second_center_diff.dot(this->dir) * this->dir;
2191 if (second_center_diff_projected.squaredNorm() < this->radius_sqr)
2193
2194 const Vec3f centers_diff = this->second_center - this->first_center;
2195 const Vec3f centers_diff_projected = centers_diff - centers_diff.dot(this->dir) * this->dir;
2196
2197 // First, check if the point is laying between first_center and second_center.
2198 if (first_center_diff_projected.dot(centers_diff_projected) <= 0.f && second_center_diff_projected.dot(centers_diff_projected) >= 0.f) {
2199 // Vector in the direction of line |AD| of the rectangle that intersects the circle with the center in first_center.
2200 const Vec3f rectangle_da_dir = centers_diff.cross(this->dir);
2201 // Vector pointing from first_center to the point 'A' of the rectangle.
2202 const Vec3f first_center_rectangle_a_diff = rectangle_da_dir.normalized() * this->radius;
2203 const Vec3f rectangle_a = this->first_center - first_center_rectangle_a_diff;
2204 const Vec3f rectangle_d = this->first_center + first_center_rectangle_a_diff;
2205 // Now check if the point is laying inside the rectangle between circles with centers in first_center and second_center.
2206 if ((rectangle_a - transformed_point).dot(rectangle_da_dir) <= 0.f && (rectangle_d - transformed_point).dot(rectangle_da_dir) >= 0.f)
2208 }
2209
2210 return false;
2211}
static bool is_mesh_point_not_clipped(const Vec3f &point, const TriangleSelector::ClippingPlane &clipping_plane)
Definition TriangleSelector.cpp:2135

References Slic3r::TriangleSelector::Cursor::clipping_plane, Slic3r::TriangleSelector::Cursor::dir, Slic3r::dot(), Slic3r::TriangleSelector::DoublePointCursor::first_center, Slic3r::is_mesh_point_not_clipped(), Slic3r::TriangleSelector::Cursor::radius, Slic3r::TriangleSelector::DoublePointCursor::second_center, Slic3r::TriangleSelector::Cursor::trafo, and Slic3r::TriangleSelector::Cursor::uniform_scaling.

Here is the call graph for this function:

◆ 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::DoublePointCursor::is_pointer_in_triangle ( const Vec3f & p1,
const Vec3f & p2,
const Vec3f & p3 ) const
overridevirtualinherited

Implements Slic3r::TriangleSelector::Cursor.

2243{
2246}
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 Slic3r::TriangleSelector::Cursor::dir, first_center, Slic3r::is_circle_pointer_inside_triangle(), second_center, Slic3r::TriangleSelector::Cursor::trafo, and Slic3r::TriangleSelector::Cursor::uniform_scaling.

Here is the call 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

◆ clipping_plane

◆ dir

◆ first_center

◆ radius

◆ radius_sqr

◆ second_center

◆ source

◆ 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 files: