Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::sla::DrainHole Struct Reference

#include <src/libslic3r/SLA/Hollowing.hpp>

+ Collaboration diagram for Slic3r::sla::DrainHole:

Public Member Functions

 DrainHole ()
 
 DrainHole (Vec3f p, Vec3f n, float r, float h, bool fl=false)
 
 DrainHole (const DrainHole &rhs)
 
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/3]

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

◆ DrainHole() [2/3]

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

◆ DrainHole() [3/3]

Slic3r::sla::DrainHole::DrainHole ( const DrainHole rhs)
inline
54 :
55 DrainHole(rhs.pos, rhs.normal, rhs.radius, rhs.height, rhs.failed) {}
DrainHole()
Definition Hollowing.hpp:46

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
159{
160 assert(is_approx(normal.norm(), 1.f));
161 const Eigen::ParametrizedLine<float, 3> ray(s, dir.normalized());
162
163 for (size_t i=0; i<2; ++i)
164 out[i] = std::make_pair(AABBMesh::hit_result::infty(), Vec3d::Zero());
165
166 const float sqr_radius = pow(radius, 2.f);
167
168 // first check a bounding sphere of the hole:
169 Vec3f center = pos+normal*height/2.f;
170 float sqr_dist_limit = pow(height/2.f, 2.f) + sqr_radius ;
171 if (ray.squaredDistance(center) > sqr_dist_limit)
172 return false;
173
174 // The line intersects the bounding sphere, look for intersections with
175 // bases of the cylinder.
176
177 size_t found = 0; // counts how many intersections were found
179 if (! is_approx(ray.direction().dot(normal), 0.f)) {
180 for (size_t i=1; i<=1; --i) {
181 Vec3f cylinder_center = pos+i*height*normal;
182 if (i == 0) {
183 // The hole base can be identical to mesh surface if it is flat
184 // let's better move the base outward a bit
185 cylinder_center -= EPSILON*normal;
186 }
187 base = Eigen::Hyperplane<float, 3>(normal, cylinder_center);
188 Vec3f intersection = ray.intersectionPoint(base);
189 // Only accept the point if it is inside the cylinder base.
190 if ((cylinder_center-intersection).squaredNorm() < sqr_radius) {
191 out[found].first = ray.intersectionParameter(base);
192 out[found].second = (i==0 ? 1. : -1.) * normal.cast<double>();
193 ++found;
194 }
195 }
196 }
197 else
198 {
199 // In case the line was perpendicular to the cylinder axis, previous
200 // block was skipped, but base will later be assumed to be valid.
202 }
203
204 // In case there is still an intersection to be found, check the wall
205 if (found != 2 && ! is_approx(std::abs(ray.direction().dot(normal)), 1.f)) {
206 // Project the ray onto the base plane
207 Vec3f proj_origin = base.projection(ray.origin());
208 Vec3f proj_dir = base.projection(ray.origin()+ray.direction())-proj_origin;
209 // save how the parameter scales and normalize the projected direction
210 float par_scale = proj_dir.norm();
211 proj_dir = proj_dir/par_scale;
212 Eigen::ParametrizedLine<float, 3> projected_ray(proj_origin, proj_dir);
213 // Calculate point on the secant that's closest to the center
214 // and its distance to the circle along the projected line
215 Vec3f closest = projected_ray.projection(pos);
216 float dist = sqrt((sqr_radius - (closest-pos).squaredNorm()));
217 // Unproject both intersections on the original line and check
218 // they are on the cylinder and not past it:
219 for (int i=-1; i<=1 && found !=2; i+=2) {
220 Vec3f isect = closest + i*dist * projected_ray.direction();
221 Vec3f to_isect = isect-proj_origin;
222 float par = to_isect.norm() / par_scale;
223 if (to_isect.normalized().dot(proj_dir.normalized()) < 0.f)
224 par *= -1.f;
225 Vec3d hit_normal = (pos-isect).normalized().cast<double>();
226 isect = ray.pointAt(par);
227 // check that the intersection is between the base planes:
228 float vert_dist = base.signedDistance(isect);
229 if (vert_dist > 0.f && vert_dist < height) {
230 out[found].first = par;
231 out[found].second = hit_normal;
232 ++found;
233 }
234 }
235 }
236
237 // If only one intersection was found, it is some corner case,
238 // no intersection will be returned:
239 if (found != 2)
240 return false;
241
242 // Sort the intersections:
243 if (out[0].first > out[1].first)
244 std::swap(out[0], out[1]);
245
246 return true;
247}
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition ArrayCwiseUnaryOps.h:152
static constexpr double infty()
Definition AABBMesh.hpp:80
EIGEN_DEVICE_FUNC Scalar signedDistance(const VectorType &p) const
Definition Hyperplane.h:143
EIGEN_DEVICE_FUNC VectorType projection(const VectorType &p) const
Definition Hyperplane.h:152
A parametrized line.
Definition ParametrizedLine.h:31
A hyperplane.
Definition Hyperplane.h:35
static constexpr double EPSILON
Definition libslic3r.h:51
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half &a, const half &b)
Definition Half.h:477
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:280
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition SpatIndex.hpp:15
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49
Slic3r::Polygons intersection(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:686
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:271

References Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::direction(), EPSILON, height, Slic3r::AABBMesh::hit_result::infty(), Slic3r::intersection(), Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::intersectionParameter(), Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::intersectionPoint(), Slic3r::is_approx(), normal, Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::origin(), Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::pointAt(), pos, Eigen::Hyperplane< _Scalar, _AmbientDim, _Options >::projection(), Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::projection(), radius, Eigen::Hyperplane< _Scalar, _AmbientDim, _Options >::signedDistance(), sqrt(), and Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::squaredDistance().

+ Here is the call graph for this function:

◆ is_inside()

bool Slic3r::sla::DrainHole::is_inside ( const Vec3f pt) const
140{
142 float dist = plane.signedDistance(pt);
143 if (dist < float(EPSILON) || dist > height)
144 return false;
145
147 if ( axis.squaredDistance(pt) < pow(radius, 2.f))
148 return true;
149
150 return false;
151}

References EPSILON, height, normal, pos, radius, Eigen::Hyperplane< _Scalar, _AmbientDim, _Options >::signedDistance(), and Eigen::ParametrizedLine< _Scalar, _AmbientDim, _Options >::squaredDistance().

+ Here is the call graph for this function:

◆ operator!=()

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

◆ operator==()

bool Slic3r::sla::DrainHole::operator== ( const DrainHole sp) const
133{
134 return (pos == sp.pos) && (normal == sp.normal) &&
135 is_approx(radius, sp.radius) &&
136 is_approx(height, sp.height);
137}

References 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
69 {
71 }

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

◆ to_mesh()

indexed_triangle_set Slic3r::sla::DrainHole::to_mesh ( ) const
121{
122 auto r = double(radius);
123 auto h = double(height);
124 indexed_triangle_set hole = its_make_cylinder(r, h); //sla::cylinder(r, h, steps);
126 q.setFromTwoVectors(Vec3f::UnitZ(), normal);
127 for(auto& p : hole.vertices) p = q * p + pos;
128
129 return hole;
130}
EIGEN_DEVICE_FUNC Derived & setFromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
Definition Quaternion.h:582
The quaternion class used to represent 3D orientations and rotations.
Definition Quaternion.h:233
indexed_triangle_set its_make_cylinder(double r, double h, double fa)
Definition TriangleMesh.cpp:955
Slic3r::Polygon & hole(Slic3r::ExPolygon &sh, unsigned long idx)
Definition geometries.hpp:200
Definition stl.h:157

References height, Slic3r::its_make_cylinder(), normal, pos, radius, and Eigen::QuaternionBase< Derived >::setFromTwoVectors().

Referenced by Slic3r::sla::hollow_mesh_and_drill().

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

Member Data Documentation

◆ failed

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

Referenced by serialize().

◆ height

◆ normal

◆ pos

◆ radius

◆ steps

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

The documentation for this struct was generated from the following files: