Skip to content

Commit

Permalink
Improvements in Inner Outer Inner wall ordering logic (#6138)
Browse files Browse the repository at this point in the history
* Improvements in Inner Outer Inner wall ordering logic

* Updated to BFS algorithm, made ordering more robust and corrected edge cases

* Doc updates

* Refinements in perimeter sorting

* Removal of touch threshold and code debugging to improve sequencing

* Code cleanup

* Code refinements on perimeter distance thresholds

* Extend perimeter re-ordering to more than inset index 2, to reduce travel moves when printing neighbouring features

* Refinements to IOI perimeter re-ordering algorithm to improve travel scenarios where multiple external perimeters are contained in the same island.

* Documentation updates

* Removed unnecessary code

* Removed bespoke to_points function and replaced with ExtrusionLine member already present. Removed squaredDistance and replaced with Eigen library call.

* Refactor code to move distancing functions to the multipoint class. Renamed for more clarity on their purpose.
  • Loading branch information
igiannakas authored Aug 13, 2024
1 parent 7082e94 commit 9a26001
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 45 deletions.
18 changes: 9 additions & 9 deletions src/libslic3r/Arachne/utils/ExtrusionLine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ static inline Polygon to_polygon(const ExtrusionLine &line)
return out;
}

static Points to_points(const ExtrusionLine &extrusion_line)
{
Points points;
points.reserve(extrusion_line.junctions.size());
for (const ExtrusionJunction &junction : extrusion_line.junctions)
points.emplace_back(junction.p);
return points;
}

#if 0
static BoundingBox get_extents(const ExtrusionLine &extrusion_line)
{
Expand Down Expand Up @@ -272,15 +281,6 @@ static BoundingBox get_extents(const std::vector<const ExtrusionLine *> &extrusi
return bbox;
}

static Points to_points(const ExtrusionLine &extrusion_line)
{
Points points;
points.reserve(extrusion_line.junctions.size());
for (const ExtrusionJunction &junction : extrusion_line.junctions)
points.emplace_back(junction.p);
return points;
}

static std::vector<Points> to_points(const std::vector<const ExtrusionLine *> &extrusion_lines)
{
std::vector<Points> points;
Expand Down
53 changes: 53 additions & 0 deletions src/libslic3r/MultiPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,59 @@ Points MultiPoint::concave_hull_2d(const Points& pts, const double tolerence)
}


//Orca: Distancing function used by IOI wall ordering algorithm for arachne
/**
* @brief Calculates the squared distance between a point and a line segment defined by two points.
*
* @param p The point.
* @param v The starting point of the line segment.
* @param w The ending point of the line segment.
* @return double The squared distance between the point and the line segment.
*/
double MultiPoint::squaredDistanceToLineSegment(const Point& p, const Point& v, const Point& w) {
// Calculate the squared length of the line segment
double l2 = (v - w).squaredNorm();
// If the segment is a single point, return the squared distance to that point
if (l2 == 0.0) return (p - v).squaredNorm();
// Project point p onto the line defined by v and w, and clamp the projection to the segment
double t = std::max(0.0, std::min(1.0, ((p - v).dot(w - v)) / l2));
// Compute the projection point
Point projection{v.x() + t * (w.x() - v.x()), v.y() + t * (w.y() - v.y())};
// Return the squared distance between the point and the projection
return (p - projection).squaredNorm();
}

//Orca: Distancing function used by IOI wall ordering algorithm for arachne
/**
* @brief Calculates the minimum distance between two lines defined by sets of points.
*
* @param A The first set of points defining a polyline.
* @param B The second set of points defining a polyline.
* @return double The minimum distance between the two polylines.
*/
double MultiPoint::minimumDistanceBetweenLinesDefinedByPoints(const Points& A, const Points& B) {
double min_distance = std::numeric_limits<double>::infinity();

// Calculate the minimum distance between segments in A and points in B
for (size_t i = 0; i < A.size() - 1; ++i) {
for (const auto& b : B) {
double distance = squaredDistanceToLineSegment(b, A[i], A[i + 1]);
min_distance = std::min(min_distance, std::sqrt(distance));
}
}

// Calculate the minimum distance between segments in B and points in A
for (size_t i = 0; i < B.size() - 1; ++i) {
for (const auto& a : A) {
double distance = squaredDistanceToLineSegment(a, B[i], B[i + 1]);
min_distance = std::min(min_distance, std::sqrt(distance));
}
}

return min_distance;
}


void MultiPoint3::translate(double x, double y)
{
for (Vec3crd &p : points) {
Expand Down
7 changes: 7 additions & 0 deletions src/libslic3r/MultiPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,20 @@ class MultiPoint
static Points _douglas_peucker(const Points &points, const double tolerance);
static Points visivalingam(const Points& pts, const double tolerance);
static Points concave_hull_2d(const Points& pts, const double tolerence);

//Orca: Distancing function used by IOI wall ordering algorithm for arachne
static double minimumDistanceBetweenLinesDefinedByPoints(const Points& A, const Points& B);

inline auto begin() { return points.begin(); }
inline auto begin() const { return points.begin(); }
inline auto end() { return points.end(); }
inline auto end() const { return points.end(); }
inline auto cbegin() const { return points.begin(); }
inline auto cend() const { return points.end(); }

private:
//Orca: Distancing function used by IOI wall ordering algorithm for arachne
static double squaredDistanceToLineSegment(const Point& p, const Point& v, const Point& w);
};

class MultiPoint3
Expand Down
Loading

0 comments on commit 9a26001

Please sign in to comment.