2014-11-15 21:41:22 +00:00
|
|
|
#ifndef slic3r_BridgeDetector_hpp_
|
|
|
|
#define slic3r_BridgeDetector_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2014-11-15 21:41:22 +00:00
|
|
|
#include "ExPolygon.hpp"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2016-11-08 08:59:25 +00:00
|
|
|
// The bridge detector optimizes a direction of bridges over a region or a set of regions.
|
|
|
|
// A bridge direction is considered optimal, if the length of the lines strang over the region is maximal.
|
|
|
|
// This is optimal if the bridge is supported in a single direction only, but
|
|
|
|
// it may not likely be optimal, if the bridge region is supported from all sides. Then an optimal
|
|
|
|
// solution would find a direction with shortest bridges.
|
|
|
|
// The bridge orientation is measured CCW from the X axis.
|
2014-11-15 21:41:22 +00:00
|
|
|
class BridgeDetector {
|
2016-09-26 10:53:41 +00:00
|
|
|
public:
|
2016-11-08 08:59:25 +00:00
|
|
|
// The non-grown holes.
|
|
|
|
const ExPolygons &expolygons;
|
|
|
|
// In case the caller gaves us the input polygons by a value, make a copy.
|
|
|
|
ExPolygons expolygons_owned;
|
2016-09-26 10:53:41 +00:00
|
|
|
// Lower slices, all regions.
|
2019-10-04 14:50:01 +00:00
|
|
|
const ExPolygons &lower_slices;
|
2016-09-26 10:53:41 +00:00
|
|
|
// Scaled extrusion width of the infill.
|
2016-11-08 08:59:25 +00:00
|
|
|
coord_t spacing;
|
2016-09-26 10:53:41 +00:00
|
|
|
// Angle resolution for the brute force search of the best bridging angle.
|
2016-11-08 08:59:25 +00:00
|
|
|
double resolution;
|
2016-09-26 10:53:41 +00:00
|
|
|
// The final optimal angle.
|
2016-11-08 08:59:25 +00:00
|
|
|
double angle;
|
2014-11-15 21:41:22 +00:00
|
|
|
|
2019-10-04 14:50:01 +00:00
|
|
|
BridgeDetector(ExPolygon _expolygon, const ExPolygons &_lower_slices, coord_t _extrusion_width);
|
|
|
|
BridgeDetector(const ExPolygons &_expolygons, const ExPolygons &_lower_slices, coord_t _extrusion_width);
|
2017-07-31 14:23:52 +00:00
|
|
|
// If bridge_direction_override != 0, then the angle is used instead of auto-detect.
|
|
|
|
bool detect_angle(double bridge_direction_override = 0.);
|
2021-02-09 17:36:28 +00:00
|
|
|
// Coverage is currently only used by the unit tests. It is extremely slow and unreliable!
|
2015-10-26 22:23:03 +00:00
|
|
|
Polygons coverage(double angle = -1) const;
|
2014-11-15 21:41:22 +00:00
|
|
|
void unsupported_edges(double angle, Polylines* unsupported) const;
|
2015-10-26 22:23:03 +00:00
|
|
|
Polylines unsupported_edges(double angle = -1) const;
|
2014-11-15 21:41:22 +00:00
|
|
|
|
2016-09-26 10:53:41 +00:00
|
|
|
private:
|
2017-05-03 16:28:22 +00:00
|
|
|
// Suppress warning "assignment operator could not be generated"
|
|
|
|
BridgeDetector& operator=(const BridgeDetector &);
|
|
|
|
|
2016-11-08 08:59:25 +00:00
|
|
|
void initialize();
|
|
|
|
|
|
|
|
struct BridgeDirection {
|
|
|
|
BridgeDirection(double a = -1.) : angle(a), coverage(0.), max_length(0.) {}
|
|
|
|
// the best direction is the one causing most lines to be bridged (thus most coverage)
|
|
|
|
bool operator<(const BridgeDirection &other) const {
|
|
|
|
// Initial sort by coverage only - comparator must obey strict weak ordering
|
|
|
|
return this->coverage > other.coverage;
|
|
|
|
};
|
|
|
|
double angle;
|
|
|
|
double coverage;
|
|
|
|
double max_length;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get possible briging direction candidates.
|
|
|
|
std::vector<double> bridge_direction_candidates() const;
|
|
|
|
|
2016-09-26 10:53:41 +00:00
|
|
|
// Open lines representing the supporting edges.
|
|
|
|
Polylines _edges;
|
|
|
|
// Closed polygons representing the supporting areas.
|
2016-11-08 08:59:25 +00:00
|
|
|
ExPolygons _anchor_regions;
|
2014-11-15 21:41:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|