OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::sla::DrainHole Struct Reference

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

Public Member Functions

 DrainHole ()
 DrainHole (Vec3f p, Vec3f n, float r, float h, bool fl=false)
bool operator== (const DrainHole &sp) const
bool operator!= (const DrainHole &sp) const
bool is_inside (const Vec3f &pt) const
bool get_intersections (const Vec3f &s, const Vec3f &dir, std::array< std::pair< float, Vec3d >, 2 > &out) const
indexed_triangle_set to_mesh () const
template<class Archive>
void serialize (Archive &ar)

Public Attributes

Vec3f pos
Vec3f normal
float radius
float height
bool failed = false

Static Public Attributes

static constexpr size_t steps = 32

Detailed Description

Constructor & Destructor Documentation

◆ DrainHole() [1/2]

Slic3r::sla::DrainHole::DrainHole ( )
inline
48 : pos(Vec3f::Zero()), normal(Vec3f::UnitZ()), radius(5.f), height(10.f)
49 {}
float height
Definition Hollowing.hpp:44
Vec3f normal
Definition Hollowing.hpp:42
float radius
Definition Hollowing.hpp:43
Vec3f pos
Definition Hollowing.hpp:41

References height, normal, pos, and radius.

Referenced by operator!=(), and operator==().

Here is the caller graph for this function:

◆ DrainHole() [2/2]

Slic3r::sla::DrainHole::DrainHole ( Vec3f p,
Vec3f n,
float r,
float h,
bool fl = false )
inline
52 : pos(p), normal(n), radius(r), height(h), failed(fl)
53 {}
bool failed
Definition Hollowing.hpp:45

References failed, height, normal, pos, and radius.

Member Function Documentation

◆ get_intersections()

bool Slic3r::sla::DrainHole::get_intersections ( const Vec3f & s,
const Vec3f & dir,
std::array< std::pair< float, Vec3d >, 2 > & out ) const
209{
210 assert(is_approx(normal.norm(), 1.f));
211 const Eigen::ParametrizedLine<float, 3> ray(s, dir.normalized());
212
213 for (size_t i=0; i<2; ++i)
214 out[i] = std::make_pair(sla::IndexedMesh::hit_result::infty(), Vec3d::Zero());
215
216 const float sqr_radius = pow(radius, 2.f);
217
218 // first check a bounding sphere of the hole:
220 float sqr_dist_limit = pow(height/2.f, 2.f) + sqr_radius ;
221 if (ray.squaredDistance(center) > sqr_dist_limit)
222 return false;
223
224 // The line intersects the bounding sphere, look for intersections with
225 // bases of the cylinder.
226
227 size_t found = 0; // counts how many intersections were found
228 Eigen::Hyperplane<float, 3> base;
229 if (! is_approx(ray.direction().dot(normal), 0.f)) {
230 for (size_t i=1; i<=1; --i) {
231 Vec3f cylinder_center = pos+i*height*normal;
232 if (i == 0) {
233 // The hole base can be identical to mesh surface if it is flat
234 // let's better move the base outward a bit
235 cylinder_center -= EPSILON*normal;
236 }
237 base = Eigen::Hyperplane<float, 3>(normal, cylinder_center);
238 Vec3f intersection = ray.intersectionPoint(base);
239 // Only accept the point if it is inside the cylinder base.
240 if ((cylinder_center-intersection).squaredNorm() < sqr_radius) {
241 out[found].first = ray.intersectionParameter(base);
242 out[found].second = (i==0 ? 1. : -1.) * normal.cast<double>();
243 ++found;
244 }
245 }
246 }
247 else
248 {
249 // In case the line was perpendicular to the cylinder axis, previous
250 // block was skipped, but base will later be assumed to be valid.
251 base = Eigen::Hyperplane<float, 3>(normal, pos-EPSILON*normal);
252 }
253
254 // In case there is still an intersection to be found, check the wall
255 if (found != 2 && ! is_approx(std::abs(ray.direction().dot(normal)), 1.f)) {
256 // Project the ray onto the base plane
257 Vec3f proj_origin = base.projection(ray.origin());
258 Vec3f proj_dir = base.projection(ray.origin()+ray.direction())-proj_origin;
259 // save how the parameter scales and normalize the projected direction
260 float par_scale = proj_dir.norm();
261 proj_dir = proj_dir/par_scale;
262 Eigen::ParametrizedLine<float, 3> projected_ray(proj_origin, proj_dir);
263 // Calculate point on the secant that's closest to the center
264 // and its distance to the circle along the projected line
265 Vec3f closest = projected_ray.projection(pos);
266 float dist = sqrt((sqr_radius - (closest-pos).squaredNorm()));
267 // Unproject both intersections on the original line and check
268 // they are on the cylinder and not past it:
269 for (int i=-1; i<=1 && found !=2; i+=2) {
270 Vec3f isect = closest + i*dist * projected_ray.direction();
271 Vec3f to_isect = isect-proj_origin;
272 float par = to_isect.norm() / par_scale;
273 if (to_isect.normalized().dot(proj_dir.normalized()) < 0.f)
274 par *= -1.f;
275 Vec3d hit_normal = (pos-isect).normalized().cast<double>();
276 isect = ray.pointAt(par);
277 // check that the intersection is between the base planes:
278 float vert_dist = base.signedDistance(isect);
279 if (vert_dist > 0.f && vert_dist < height) {
280 out[found].first = par;
281 out[found].second = hit_normal;
282 ++found;
283 }
284 }
285 }
286
287 // If only one intersection was found, it is some corner case,
288 // no intersection will be returned:
289 if (found != 2)
290 return false;
291
292 // Sort the intersections:
293 if (out[0].first > out[1].first)
294 std::swap(out[0], out[1]);
295
296 return true;
297}
#define EPSILON
Definition ColorUtils.cpp:64
static constexpr double infty()
Definition IndexedMesh.hpp:93
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:298
Foot closest(const Contour &c, const Vec2d &p, double stop=-1.0, const std::vector< Vec2d > *source_normals=nullptr, double normal_cosine=0.0)
Definition SeamContour.cpp:36
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition SpatIndex.hpp:18
void center(ExPolygonsWithIds &e)
Definition Emboss.cpp:1382
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
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:320

References Slic3r::center(), Slic3r::Geometry::dist(), EPSILON, height, Slic3r::sla::IndexedMesh::hit_result::infty(), Slic3r::intersection(), Slic3r::is_approx(), normal, pos, and radius.

Here is the call graph for this function:

◆ is_inside()

bool Slic3r::sla::DrainHole::is_inside ( const Vec3f & pt) const
189{
190 Eigen::Hyperplane<float, 3> plane(normal, pos);
191 float dist = plane.signedDistance(pt);
192 if (dist < float(EPSILON) || dist > height)
193 return false;
194
195 Eigen::ParametrizedLine<float, 3> axis(pos, normal);
196 if ( axis.squaredDistance(pt) < pow(radius, 2.f))
197 return true;
198
199 return false;
200}

References Slic3r::Geometry::dist(), EPSILON, height, normal, pos, and radius.

Here is the call graph for this function:

◆ operator!=()

bool Slic3r::sla::DrainHole::operator!= ( const DrainHole & sp) const
inline
57{ return !(sp == (*this)); }

References DrainHole().

Here is the call graph for this function:

◆ operator==()

bool Slic3r::sla::DrainHole::operator== ( const DrainHole & sp) const
182{
183 return (pos == sp.pos) && (normal == sp.normal) &&
184 is_approx(radius, sp.radius) &&
185 is_approx(height, sp.height);
186}

References DrainHole(), height, Slic3r::is_approx(), normal, pos, and radius.

Here is the call graph for this function:

◆ serialize()

template<class Archive>
void Slic3r::sla::DrainHole::serialize ( Archive & ar)
inline
67 {
69 }

References failed, height, normal, pos, and radius.

◆ to_mesh()

indexed_triangle_set Slic3r::sla::DrainHole::to_mesh ( ) const
170{
171 auto r = double(radius);
172 auto h = double(height);
173 indexed_triangle_set hole = sla::cylinder(r, h, steps);
174 Eigen::Quaternionf q;
175 q.setFromTwoVectors(Vec3f{0.f, 0.f, 1.f}, normal);
176 for(auto& p : hole.vertices) p = q * p + pos;
177
178 return hole;
179}
indexed_triangle_set cylinder(double r, double h, size_t ssteps, const Vec3d &sp)
Definition SupportTreeMesher.cpp:105
static constexpr size_t steps
Definition Hollowing.hpp:71

References Slic3r::sla::cylinder(), height, normal, pos, radius, and steps.

Here is the call graph for this function:

Member Data Documentation

◆ failed

bool Slic3r::sla::DrainHole::failed = false

Referenced by DrainHole(), and serialize().

◆ height

float Slic3r::sla::DrainHole::height

◆ normal

Vec3f Slic3r::sla::DrainHole::normal

◆ pos

Vec3f Slic3r::sla::DrainHole::pos

◆ radius

float Slic3r::sla::DrainHole::radius

◆ steps

size_t Slic3r::sla::DrainHole::steps = 32
staticconstexpr

The documentation for this struct was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/SLA/Hollowing.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/SLA/Hollowing.cpp