mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
Renamed monotonous infill to monotonic.
This commit is contained in:
parent
8d45b4c468
commit
7fbdda9080
9 changed files with 96 additions and 96 deletions
|
@ -535,7 +535,7 @@ void Layer::make_ironing()
|
||||||
fill_params.density = 1.;
|
fill_params.density = 1.;
|
||||||
// fill_params.dont_connect = true;
|
// fill_params.dont_connect = true;
|
||||||
fill_params.dont_connect = false;
|
fill_params.dont_connect = false;
|
||||||
fill_params.monotonous = true;
|
fill_params.monotonic = true;
|
||||||
|
|
||||||
for (size_t i = 0; i < by_extruder.size(); ++ i) {
|
for (size_t i = 0; i < by_extruder.size(); ++ i) {
|
||||||
// Find span of regions equivalent to the ironing operation.
|
// Find span of regions equivalent to the ironing operation.
|
||||||
|
@ -579,7 +579,7 @@ void Layer::make_ironing()
|
||||||
// Save into layer.
|
// Save into layer.
|
||||||
ExtrusionEntityCollection *eec = nullptr;
|
ExtrusionEntityCollection *eec = nullptr;
|
||||||
ironing_params.layerm->fills.entities.push_back(eec = new ExtrusionEntityCollection());
|
ironing_params.layerm->fills.entities.push_back(eec = new ExtrusionEntityCollection());
|
||||||
// Don't sort the ironing infill lines as they are monotonously ordered.
|
// Don't sort the ironing infill lines as they are monotonicly ordered.
|
||||||
eec->no_sort = true;
|
eec->no_sort = true;
|
||||||
extrusion_entities_append_paths(
|
extrusion_entities_append_paths(
|
||||||
eec->entities, std::move(polylines),
|
eec->entities, std::move(polylines),
|
||||||
|
|
|
@ -221,7 +221,7 @@ static const std::array<Vec3d, 8> child_centers {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Traversal order of octree children cells for three infill directions,
|
// Traversal order of octree children cells for three infill directions,
|
||||||
// so that a single line will be discretized in a strictly monotonous order.
|
// so that a single line will be discretized in a strictly monotonic order.
|
||||||
static constexpr std::array<std::array<int, 8>, 3> child_traversal_order {
|
static constexpr std::array<std::array<int, 8>, 3> child_traversal_order {
|
||||||
std::array<int, 8>{ 2, 3, 0, 1, 6, 7, 4, 5 },
|
std::array<int, 8>{ 2, 3, 0, 1, 6, 7, 4, 5 },
|
||||||
std::array<int, 8>{ 4, 0, 6, 2, 5, 1, 7, 3 },
|
std::array<int, 8>{ 4, 0, 6, 2, 5, 1, 7, 3 },
|
||||||
|
|
|
@ -28,7 +28,7 @@ Fill* Fill::new_from_type(const InfillPattern type)
|
||||||
case ip3DHoneycomb: return new Fill3DHoneycomb();
|
case ip3DHoneycomb: return new Fill3DHoneycomb();
|
||||||
case ipGyroid: return new FillGyroid();
|
case ipGyroid: return new FillGyroid();
|
||||||
case ipRectilinear: return new FillRectilinear2();
|
case ipRectilinear: return new FillRectilinear2();
|
||||||
case ipMonotonous: return new FillMonotonous();
|
case ipMonotonic: return new FillMonotonic();
|
||||||
case ipLine: return new FillLine();
|
case ipLine: return new FillLine();
|
||||||
case ipGrid: return new FillGrid2();
|
case ipGrid: return new FillGrid2();
|
||||||
case ipTriangles: return new FillTriangles();
|
case ipTriangles: return new FillTriangles();
|
||||||
|
|
|
@ -43,8 +43,8 @@ struct FillParams
|
||||||
// Don't adjust spacing to fill the space evenly.
|
// Don't adjust spacing to fill the space evenly.
|
||||||
bool dont_adjust { true };
|
bool dont_adjust { true };
|
||||||
|
|
||||||
// Monotonous infill - strictly left to right for better surface quality of top infills.
|
// Monotonic infill - strictly left to right for better surface quality of top infills.
|
||||||
bool monotonous { false };
|
bool monotonic { false };
|
||||||
|
|
||||||
// For Honeycomb.
|
// For Honeycomb.
|
||||||
// we were requested to complete each loop;
|
// we were requested to complete each loop;
|
||||||
|
|
|
@ -1387,7 +1387,7 @@ static void traverse_graph_generate_polylines(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MonotonousRegion
|
struct MonotonicRegion
|
||||||
{
|
{
|
||||||
struct Boundary {
|
struct Boundary {
|
||||||
int vline;
|
int vline;
|
||||||
|
@ -1412,13 +1412,13 @@ struct MonotonousRegion
|
||||||
|
|
||||||
#if NDEBUG
|
#if NDEBUG
|
||||||
// Left regions are used to track whether all regions left to this one have already been printed.
|
// Left regions are used to track whether all regions left to this one have already been printed.
|
||||||
boost::container::small_vector<MonotonousRegion*, 4> left_neighbors;
|
boost::container::small_vector<MonotonicRegion*, 4> left_neighbors;
|
||||||
// Right regions are held to pick a next region to be extruded using the "Ant colony" heuristics.
|
// Right regions are held to pick a next region to be extruded using the "Ant colony" heuristics.
|
||||||
boost::container::small_vector<MonotonousRegion*, 4> right_neighbors;
|
boost::container::small_vector<MonotonicRegion*, 4> right_neighbors;
|
||||||
#else
|
#else
|
||||||
// For debugging, use the normal vector as it is better supported by debug visualizers.
|
// For debugging, use the normal vector as it is better supported by debug visualizers.
|
||||||
std::vector<MonotonousRegion*> left_neighbors;
|
std::vector<MonotonicRegion*> left_neighbors;
|
||||||
std::vector<MonotonousRegion*> right_neighbors;
|
std::vector<MonotonicRegion*> right_neighbors;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1429,9 +1429,9 @@ struct AntPath
|
||||||
float pheromone { 0 }; // <0, 1>
|
float pheromone { 0 }; // <0, 1>
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MonotonousRegionLink
|
struct MonotonicRegionLink
|
||||||
{
|
{
|
||||||
MonotonousRegion *region;
|
MonotonicRegion *region;
|
||||||
bool flipped;
|
bool flipped;
|
||||||
// Distance of right side of this region to left side of the next region, if the "flipped" flag of this region and the next region
|
// Distance of right side of this region to left side of the next region, if the "flipped" flag of this region and the next region
|
||||||
// is applied as defined.
|
// is applied as defined.
|
||||||
|
@ -1447,7 +1447,7 @@ class AntPathMatrix
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AntPathMatrix(
|
AntPathMatrix(
|
||||||
const std::vector<MonotonousRegion> ®ions,
|
const std::vector<MonotonicRegion> ®ions,
|
||||||
const ExPolygonWithOffset &poly_with_offset,
|
const ExPolygonWithOffset &poly_with_offset,
|
||||||
const std::vector<SegmentedIntersectionLine> &segs,
|
const std::vector<SegmentedIntersectionLine> &segs,
|
||||||
const float initial_pheromone) :
|
const float initial_pheromone) :
|
||||||
|
@ -1463,7 +1463,7 @@ public:
|
||||||
ap.pheromone = initial_pheromone;
|
ap.pheromone = initial_pheromone;
|
||||||
}
|
}
|
||||||
|
|
||||||
AntPath& operator()(const MonotonousRegion ®ion_from, bool flipped_from, const MonotonousRegion ®ion_to, bool flipped_to)
|
AntPath& operator()(const MonotonicRegion ®ion_from, bool flipped_from, const MonotonicRegion ®ion_to, bool flipped_to)
|
||||||
{
|
{
|
||||||
int row = 2 * int(®ion_from - m_regions.data()) + flipped_from;
|
int row = 2 * int(®ion_from - m_regions.data()) + flipped_from;
|
||||||
int col = 2 * int(®ion_to - m_regions.data()) + flipped_to;
|
int col = 2 * int(®ion_to - m_regions.data()) + flipped_to;
|
||||||
|
@ -1490,16 +1490,16 @@ public:
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
AntPath& operator()(const MonotonousRegionLink ®ion_from, const MonotonousRegion ®ion_to, bool flipped_to)
|
AntPath& operator()(const MonotonicRegionLink ®ion_from, const MonotonicRegion ®ion_to, bool flipped_to)
|
||||||
{ return (*this)(*region_from.region, region_from.flipped, region_to, flipped_to); }
|
{ return (*this)(*region_from.region, region_from.flipped, region_to, flipped_to); }
|
||||||
AntPath& operator()(const MonotonousRegion ®ion_from, bool flipped_from, const MonotonousRegionLink ®ion_to)
|
AntPath& operator()(const MonotonicRegion ®ion_from, bool flipped_from, const MonotonicRegionLink ®ion_to)
|
||||||
{ return (*this)(region_from, flipped_from, *region_to.region, region_to.flipped); }
|
{ return (*this)(region_from, flipped_from, *region_to.region, region_to.flipped); }
|
||||||
AntPath& operator()(const MonotonousRegionLink ®ion_from, const MonotonousRegionLink ®ion_to)
|
AntPath& operator()(const MonotonicRegionLink ®ion_from, const MonotonicRegionLink ®ion_to)
|
||||||
{ return (*this)(*region_from.region, region_from.flipped, *region_to.region, region_to.flipped); }
|
{ return (*this)(*region_from.region, region_from.flipped, *region_to.region, region_to.flipped); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Source regions, used for addressing and updating m_matrix.
|
// Source regions, used for addressing and updating m_matrix.
|
||||||
const std::vector<MonotonousRegion> &m_regions;
|
const std::vector<MonotonicRegion> &m_regions;
|
||||||
// To calculate the intersection points and contour lengths.
|
// To calculate the intersection points and contour lengths.
|
||||||
const ExPolygonWithOffset &m_poly_with_offset;
|
const ExPolygonWithOffset &m_poly_with_offset;
|
||||||
const std::vector<SegmentedIntersectionLine> &m_segs;
|
const std::vector<SegmentedIntersectionLine> &m_segs;
|
||||||
|
@ -1652,9 +1652,9 @@ static std::pair<SegmentIntersection*, SegmentIntersection*> right_overlap(std::
|
||||||
return start_end.first == nullptr ? start_end : right_overlap(*start_end.first, *start_end.second, vline_this, vline_right);
|
return start_end.first == nullptr ? start_end : right_overlap(*start_end.first, *start_end.second, vline_this, vline_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<MonotonousRegion> generate_montonous_regions(std::vector<SegmentedIntersectionLine> &segs)
|
static std::vector<MonotonicRegion> generate_montonous_regions(std::vector<SegmentedIntersectionLine> &segs)
|
||||||
{
|
{
|
||||||
std::vector<MonotonousRegion> monotonous_regions;
|
std::vector<MonotonicRegion> monotonic_regions;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#define SLIC3R_DEBUG_MONOTONOUS_REGIONS
|
#define SLIC3R_DEBUG_MONOTONOUS_REGIONS
|
||||||
|
@ -1685,11 +1685,11 @@ static std::vector<MonotonousRegion> generate_montonous_regions(std::vector<Segm
|
||||||
SegmentIntersection *start = &vline_seed.intersections[i_intersection_seed];
|
SegmentIntersection *start = &vline_seed.intersections[i_intersection_seed];
|
||||||
SegmentIntersection *end = &end_of_vertical_run(vline_seed, *start);
|
SegmentIntersection *end = &end_of_vertical_run(vline_seed, *start);
|
||||||
if (! start->consumed_vertical_up) {
|
if (! start->consumed_vertical_up) {
|
||||||
// Draw a new monotonous region starting with this segment.
|
// Draw a new monotonic region starting with this segment.
|
||||||
// while there is only a single right neighbor
|
// while there is only a single right neighbor
|
||||||
int i_vline = i_vline_seed;
|
int i_vline = i_vline_seed;
|
||||||
std::pair<SegmentIntersection*, SegmentIntersection*> left(start, end);
|
std::pair<SegmentIntersection*, SegmentIntersection*> left(start, end);
|
||||||
MonotonousRegion region;
|
MonotonicRegion region;
|
||||||
region.left.vline = i_vline;
|
region.left.vline = i_vline;
|
||||||
region.left.low = int(left.first - vline_seed.intersections.data());
|
region.left.low = int(left.first - vline_seed.intersections.data());
|
||||||
region.left.high = int(left.second - vline_seed.intersections.data());
|
region.left.high = int(left.second - vline_seed.intersections.data());
|
||||||
|
@ -1722,19 +1722,19 @@ static std::vector<MonotonousRegion> generate_montonous_regions(std::vector<Segm
|
||||||
}
|
}
|
||||||
// Even number of lines makes the infill zig-zag to exit on the other side of the region than where it starts.
|
// Even number of lines makes the infill zig-zag to exit on the other side of the region than where it starts.
|
||||||
region.flips = (num_lines & 1) != 0;
|
region.flips = (num_lines & 1) != 0;
|
||||||
monotonous_regions.emplace_back(region);
|
monotonic_regions.emplace_back(region);
|
||||||
}
|
}
|
||||||
i_intersection_seed = int(end - vline_seed.intersections.data()) + 1;
|
i_intersection_seed = int(end - vline_seed.intersections.data()) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return monotonous_regions;
|
return monotonic_regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse path, calculate length of the draw for the purpose of optimization.
|
// Traverse path, calculate length of the draw for the purpose of optimization.
|
||||||
// This function is very similar to polylines_from_paths() in the way how it traverses the path, but
|
// This function is very similar to polylines_from_paths() in the way how it traverses the path, but
|
||||||
// polylines_from_paths() emits a path, while this function just calculates the path length.
|
// polylines_from_paths() emits a path, while this function just calculates the path length.
|
||||||
static float montonous_region_path_length(const MonotonousRegion ®ion, bool dir, const ExPolygonWithOffset &poly_with_offset, const std::vector<SegmentedIntersectionLine> &segs)
|
static float montonous_region_path_length(const MonotonicRegion ®ion, bool dir, const ExPolygonWithOffset &poly_with_offset, const std::vector<SegmentedIntersectionLine> &segs)
|
||||||
{
|
{
|
||||||
// From the initial point (i_vline, i_intersection), follow a path.
|
// From the initial point (i_vline, i_intersection), follow a path.
|
||||||
int i_intersection = region.left_intersection_point(dir);
|
int i_intersection = region.left_intersection_point(dir);
|
||||||
|
@ -1822,15 +1822,15 @@ static float montonous_region_path_length(const MonotonousRegion ®ion, bool d
|
||||||
return unscale<float>(total_length);
|
return unscale<float>(total_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void connect_monotonous_regions(std::vector<MonotonousRegion> ®ions, const ExPolygonWithOffset &poly_with_offset, std::vector<SegmentedIntersectionLine> &segs)
|
static void connect_monotonic_regions(std::vector<MonotonicRegion> ®ions, const ExPolygonWithOffset &poly_with_offset, std::vector<SegmentedIntersectionLine> &segs)
|
||||||
{
|
{
|
||||||
// Map from low intersection to left / right side of a monotonous region.
|
// Map from low intersection to left / right side of a monotonic region.
|
||||||
using MapType = std::pair<SegmentIntersection*, MonotonousRegion*>;
|
using MapType = std::pair<SegmentIntersection*, MonotonicRegion*>;
|
||||||
std::vector<MapType> map_intersection_to_region_start;
|
std::vector<MapType> map_intersection_to_region_start;
|
||||||
std::vector<MapType> map_intersection_to_region_end;
|
std::vector<MapType> map_intersection_to_region_end;
|
||||||
map_intersection_to_region_start.reserve(regions.size());
|
map_intersection_to_region_start.reserve(regions.size());
|
||||||
map_intersection_to_region_end.reserve(regions.size());
|
map_intersection_to_region_end.reserve(regions.size());
|
||||||
for (MonotonousRegion ®ion : regions) {
|
for (MonotonicRegion ®ion : regions) {
|
||||||
map_intersection_to_region_start.emplace_back(&segs[region.left.vline].intersections[region.left.low], ®ion);
|
map_intersection_to_region_start.emplace_back(&segs[region.left.vline].intersections[region.left.low], ®ion);
|
||||||
map_intersection_to_region_end.emplace_back(&segs[region.right.vline].intersections[region.right.low], ®ion);
|
map_intersection_to_region_end.emplace_back(&segs[region.right.vline].intersections[region.right.low], ®ion);
|
||||||
}
|
}
|
||||||
|
@ -1840,7 +1840,7 @@ static void connect_monotonous_regions(std::vector<MonotonousRegion> ®ions, c
|
||||||
std::sort(map_intersection_to_region_end.begin(), map_intersection_to_region_end.end(), intersections_lower);
|
std::sort(map_intersection_to_region_end.begin(), map_intersection_to_region_end.end(), intersections_lower);
|
||||||
|
|
||||||
// Scatter links to neighboring regions.
|
// Scatter links to neighboring regions.
|
||||||
for (MonotonousRegion ®ion : regions) {
|
for (MonotonicRegion ®ion : regions) {
|
||||||
if (region.left.vline > 0) {
|
if (region.left.vline > 0) {
|
||||||
auto &vline = segs[region.left.vline];
|
auto &vline = segs[region.left.vline];
|
||||||
auto &vline_left = segs[region.left.vline - 1];
|
auto &vline_left = segs[region.left.vline - 1];
|
||||||
|
@ -1884,17 +1884,17 @@ static void connect_monotonous_regions(std::vector<MonotonousRegion> ®ions, c
|
||||||
// Sometimes a segment may indicate that it connects to a segment on the other side while the other does not.
|
// Sometimes a segment may indicate that it connects to a segment on the other side while the other does not.
|
||||||
// This may be a valid case if one side contains runs of OUTER_LOW, INNER_LOW, {INNER_HIGH, INNER_LOW}*, INNER_HIGH, OUTER_HIGH,
|
// This may be a valid case if one side contains runs of OUTER_LOW, INNER_LOW, {INNER_HIGH, INNER_LOW}*, INNER_HIGH, OUTER_HIGH,
|
||||||
// where the part in the middle does not connect to the other side, but it will be extruded through.
|
// where the part in the middle does not connect to the other side, but it will be extruded through.
|
||||||
for (MonotonousRegion ®ion : regions) {
|
for (MonotonicRegion ®ion : regions) {
|
||||||
std::sort(region.left_neighbors.begin(), region.left_neighbors.end());
|
std::sort(region.left_neighbors.begin(), region.left_neighbors.end());
|
||||||
std::sort(region.right_neighbors.begin(), region.right_neighbors.end());
|
std::sort(region.right_neighbors.begin(), region.right_neighbors.end());
|
||||||
}
|
}
|
||||||
for (MonotonousRegion ®ion : regions) {
|
for (MonotonicRegion ®ion : regions) {
|
||||||
for (MonotonousRegion *neighbor : region.left_neighbors) {
|
for (MonotonicRegion *neighbor : region.left_neighbors) {
|
||||||
auto it = std::lower_bound(neighbor->right_neighbors.begin(), neighbor->right_neighbors.end(), ®ion);
|
auto it = std::lower_bound(neighbor->right_neighbors.begin(), neighbor->right_neighbors.end(), ®ion);
|
||||||
if (it == neighbor->right_neighbors.end() || *it != ®ion)
|
if (it == neighbor->right_neighbors.end() || *it != ®ion)
|
||||||
neighbor->right_neighbors.insert(it, ®ion);
|
neighbor->right_neighbors.insert(it, ®ion);
|
||||||
}
|
}
|
||||||
for (MonotonousRegion *neighbor : region.right_neighbors) {
|
for (MonotonicRegion *neighbor : region.right_neighbors) {
|
||||||
auto it = std::lower_bound(neighbor->left_neighbors.begin(), neighbor->left_neighbors.end(), ®ion);
|
auto it = std::lower_bound(neighbor->left_neighbors.begin(), neighbor->left_neighbors.end(), ®ion);
|
||||||
if (it == neighbor->left_neighbors.end() || *it != ®ion)
|
if (it == neighbor->left_neighbors.end() || *it != ®ion)
|
||||||
neighbor->left_neighbors.insert(it, ®ion);
|
neighbor->left_neighbors.insert(it, ®ion);
|
||||||
|
@ -1903,12 +1903,12 @@ static void connect_monotonous_regions(std::vector<MonotonousRegion> ®ions, c
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// Verify symmetry of the left_neighbors / right_neighbors.
|
// Verify symmetry of the left_neighbors / right_neighbors.
|
||||||
for (MonotonousRegion ®ion : regions) {
|
for (MonotonicRegion ®ion : regions) {
|
||||||
for (MonotonousRegion *neighbor : region.left_neighbors) {
|
for (MonotonicRegion *neighbor : region.left_neighbors) {
|
||||||
assert(std::count(region.left_neighbors.begin(), region.left_neighbors.end(), neighbor) == 1);
|
assert(std::count(region.left_neighbors.begin(), region.left_neighbors.end(), neighbor) == 1);
|
||||||
assert(std::find(neighbor->right_neighbors.begin(), neighbor->right_neighbors.end(), ®ion) != neighbor->right_neighbors.end());
|
assert(std::find(neighbor->right_neighbors.begin(), neighbor->right_neighbors.end(), ®ion) != neighbor->right_neighbors.end());
|
||||||
}
|
}
|
||||||
for (MonotonousRegion *neighbor : region.right_neighbors) {
|
for (MonotonicRegion *neighbor : region.right_neighbors) {
|
||||||
assert(std::count(region.right_neighbors.begin(), region.right_neighbors.end(), neighbor) == 1);
|
assert(std::count(region.right_neighbors.begin(), region.right_neighbors.end(), neighbor) == 1);
|
||||||
assert(std::find(neighbor->left_neighbors.begin(), neighbor->left_neighbors.end(), ®ion) != neighbor->left_neighbors.end());
|
assert(std::find(neighbor->left_neighbors.begin(), neighbor->left_neighbors.end(), ®ion) != neighbor->left_neighbors.end());
|
||||||
}
|
}
|
||||||
|
@ -1916,7 +1916,7 @@ static void connect_monotonous_regions(std::vector<MonotonousRegion> ®ions, c
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
// Fill in sum length of connecting lines of a region. This length is used for optimizing the infill path for minimum length.
|
// Fill in sum length of connecting lines of a region. This length is used for optimizing the infill path for minimum length.
|
||||||
for (MonotonousRegion ®ion : regions) {
|
for (MonotonicRegion ®ion : regions) {
|
||||||
region.len1 = montonous_region_path_length(region, false, poly_with_offset, segs);
|
region.len1 = montonous_region_path_length(region, false, poly_with_offset, segs);
|
||||||
region.len2 = montonous_region_path_length(region, true, poly_with_offset, segs);
|
region.len2 = montonous_region_path_length(region, true, poly_with_offset, segs);
|
||||||
// Subtract the smaller length from the longer one, so we will optimize just with the positive difference of the two.
|
// Subtract the smaller length from the longer one, so we will optimize just with the positive difference of the two.
|
||||||
|
@ -1934,7 +1934,7 @@ static void connect_monotonous_regions(std::vector<MonotonousRegion> ®ions, c
|
||||||
// https://www.chalmers.se/en/departments/math/research/research-groups/optimization/OptimizationMasterTheses/MScThesis-RaadSalman-final.pdf
|
// https://www.chalmers.se/en/departments/math/research/research-groups/optimization/OptimizationMasterTheses/MScThesis-RaadSalman-final.pdf
|
||||||
// Algorithm 6.1 Lexicographic Path Preserving 3-opt
|
// Algorithm 6.1 Lexicographic Path Preserving 3-opt
|
||||||
// Optimize path while maintaining the ordering constraints.
|
// Optimize path while maintaining the ordering constraints.
|
||||||
void monotonous_3_opt(std::vector<MonotonousRegionLink> &path, const std::vector<SegmentedIntersectionLine> &segs)
|
void monotonic_3_opt(std::vector<MonotonicRegionLink> &path, const std::vector<SegmentedIntersectionLine> &segs)
|
||||||
{
|
{
|
||||||
// When doing the 3-opt path preserving flips, one has to fulfill two constraints:
|
// When doing the 3-opt path preserving flips, one has to fulfill two constraints:
|
||||||
//
|
//
|
||||||
|
@ -1949,7 +1949,7 @@ void monotonous_3_opt(std::vector<MonotonousRegionLink> &path, const std::vector
|
||||||
// then the precedence constraint verification is amortized inside the O(n^3) loop. Now which is better for our task?
|
// then the precedence constraint verification is amortized inside the O(n^3) loop. Now which is better for our task?
|
||||||
//
|
//
|
||||||
// It is beneficial to also try flipping of the infill zig-zags, for which a prefix sum of both flipped and non-flipped paths over
|
// It is beneficial to also try flipping of the infill zig-zags, for which a prefix sum of both flipped and non-flipped paths over
|
||||||
// MonotonousRegionLinks may be utilized, however updating the prefix sum has a linear complexity, the same complexity as doing the 3-opt
|
// MonotonicRegionLinks may be utilized, however updating the prefix sum has a linear complexity, the same complexity as doing the 3-opt
|
||||||
// exchange by copying the pieces.
|
// exchange by copying the pieces.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1962,17 +1962,17 @@ inline void print_ant(const std::string& fmt, TArgs&&... args) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a run through monotonous infill blocks using an 'Ant colony" optimization method.
|
// Find a run through monotonic infill blocks using an 'Ant colony" optimization method.
|
||||||
// http://www.scholarpedia.org/article/Ant_colony_optimization
|
// http://www.scholarpedia.org/article/Ant_colony_optimization
|
||||||
static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
static std::vector<MonotonicRegionLink> chain_monotonic_regions(
|
||||||
std::vector<MonotonousRegion> ®ions, const ExPolygonWithOffset &poly_with_offset, const std::vector<SegmentedIntersectionLine> &segs, std::mt19937_64 &rng)
|
std::vector<MonotonicRegion> ®ions, const ExPolygonWithOffset &poly_with_offset, const std::vector<SegmentedIntersectionLine> &segs, std::mt19937_64 &rng)
|
||||||
{
|
{
|
||||||
// Number of left neighbors (regions that this region depends on, this region cannot be printed before the regions left of it are printed) + self.
|
// Number of left neighbors (regions that this region depends on, this region cannot be printed before the regions left of it are printed) + self.
|
||||||
std::vector<int32_t> left_neighbors_unprocessed(regions.size(), 1);
|
std::vector<int32_t> left_neighbors_unprocessed(regions.size(), 1);
|
||||||
// Queue of regions, which have their left neighbors already printed.
|
// Queue of regions, which have their left neighbors already printed.
|
||||||
std::vector<MonotonousRegion*> queue;
|
std::vector<MonotonicRegion*> queue;
|
||||||
queue.reserve(regions.size());
|
queue.reserve(regions.size());
|
||||||
for (MonotonousRegion ®ion : regions)
|
for (MonotonicRegion ®ion : regions)
|
||||||
if (region.left_neighbors.empty())
|
if (region.left_neighbors.empty())
|
||||||
queue.emplace_back(®ion);
|
queue.emplace_back(®ion);
|
||||||
else
|
else
|
||||||
|
@ -1981,13 +1981,13 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
auto left_neighbors_unprocessed_initial = left_neighbors_unprocessed;
|
auto left_neighbors_unprocessed_initial = left_neighbors_unprocessed;
|
||||||
auto queue_initial = queue;
|
auto queue_initial = queue;
|
||||||
|
|
||||||
std::vector<MonotonousRegionLink> path, best_path;
|
std::vector<MonotonicRegionLink> path, best_path;
|
||||||
path.reserve(regions.size());
|
path.reserve(regions.size());
|
||||||
best_path.reserve(regions.size());
|
best_path.reserve(regions.size());
|
||||||
float best_path_length = std::numeric_limits<float>::max();
|
float best_path_length = std::numeric_limits<float>::max();
|
||||||
|
|
||||||
struct NextCandidate {
|
struct NextCandidate {
|
||||||
MonotonousRegion *region;
|
MonotonicRegion *region;
|
||||||
AntPath *link;
|
AntPath *link;
|
||||||
AntPath *link_flipped;
|
AntPath *link_flipped;
|
||||||
float probability;
|
float probability;
|
||||||
|
@ -2002,22 +2002,22 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
[®ions, &left_neighbors_unprocessed, &path, &queue]() {
|
[®ions, &left_neighbors_unprocessed, &path, &queue]() {
|
||||||
std::vector<unsigned char> regions_processed(regions.size(), false);
|
std::vector<unsigned char> regions_processed(regions.size(), false);
|
||||||
std::vector<unsigned char> regions_in_queue(regions.size(), false);
|
std::vector<unsigned char> regions_in_queue(regions.size(), false);
|
||||||
for (const MonotonousRegion *region : queue) {
|
for (const MonotonicRegion *region : queue) {
|
||||||
// This region is not processed yet, his predecessors are processed.
|
// This region is not processed yet, his predecessors are processed.
|
||||||
assert(left_neighbors_unprocessed[region - regions.data()] == 1);
|
assert(left_neighbors_unprocessed[region - regions.data()] == 1);
|
||||||
regions_in_queue[region - regions.data()] = true;
|
regions_in_queue[region - regions.data()] = true;
|
||||||
}
|
}
|
||||||
for (const MonotonousRegionLink &link : path) {
|
for (const MonotonicRegionLink &link : path) {
|
||||||
assert(left_neighbors_unprocessed[link.region - regions.data()] == 0);
|
assert(left_neighbors_unprocessed[link.region - regions.data()] == 0);
|
||||||
regions_processed[link.region - regions.data()] = true;
|
regions_processed[link.region - regions.data()] = true;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < regions_processed.size(); ++ i) {
|
for (size_t i = 0; i < regions_processed.size(); ++ i) {
|
||||||
assert(! regions_processed[i] || ! regions_in_queue[i]);
|
assert(! regions_processed[i] || ! regions_in_queue[i]);
|
||||||
const MonotonousRegion ®ion = regions[i];
|
const MonotonicRegion ®ion = regions[i];
|
||||||
if (regions_processed[i] || regions_in_queue[i]) {
|
if (regions_processed[i] || regions_in_queue[i]) {
|
||||||
assert(left_neighbors_unprocessed[i] == (regions_in_queue[i] ? 1 : 0));
|
assert(left_neighbors_unprocessed[i] == (regions_in_queue[i] ? 1 : 0));
|
||||||
// All left neighbors should be processed already.
|
// All left neighbors should be processed already.
|
||||||
for (const MonotonousRegion *left : region.left_neighbors) {
|
for (const MonotonicRegion *left : region.left_neighbors) {
|
||||||
assert(regions_processed[left - regions.data()]);
|
assert(regions_processed[left - regions.data()]);
|
||||||
assert(left_neighbors_unprocessed[left - regions.data()] == 0);
|
assert(left_neighbors_unprocessed[left - regions.data()] == 0);
|
||||||
}
|
}
|
||||||
|
@ -2026,7 +2026,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
assert(left_neighbors_unprocessed[i] > 1);
|
assert(left_neighbors_unprocessed[i] > 1);
|
||||||
size_t num_predecessors_unprocessed = 0;
|
size_t num_predecessors_unprocessed = 0;
|
||||||
bool has_left_last_on_path = false;
|
bool has_left_last_on_path = false;
|
||||||
for (const MonotonousRegion* left : region.left_neighbors) {
|
for (const MonotonicRegion* left : region.left_neighbors) {
|
||||||
size_t iprev = left - regions.data();
|
size_t iprev = left - regions.data();
|
||||||
if (regions_processed[iprev]) {
|
if (regions_processed[iprev]) {
|
||||||
assert(left_neighbors_unprocessed[iprev] == 0);
|
assert(left_neighbors_unprocessed[iprev] == 0);
|
||||||
|
@ -2080,18 +2080,18 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
left_neighbors_unprocessed = left_neighbors_unprocessed_initial;
|
left_neighbors_unprocessed = left_neighbors_unprocessed_initial;
|
||||||
assert(validate_unprocessed());
|
assert(validate_unprocessed());
|
||||||
// Pick the last of the queue.
|
// Pick the last of the queue.
|
||||||
MonotonousRegionLink path_end { queue.back(), false };
|
MonotonicRegionLink path_end { queue.back(), false };
|
||||||
queue.pop_back();
|
queue.pop_back();
|
||||||
-- left_neighbors_unprocessed[path_end.region - regions.data()];
|
-- left_neighbors_unprocessed[path_end.region - regions.data()];
|
||||||
|
|
||||||
float total_length = path_end.region->length(false);
|
float total_length = path_end.region->length(false);
|
||||||
while (! queue.empty() || ! path_end.region->right_neighbors.empty()) {
|
while (! queue.empty() || ! path_end.region->right_neighbors.empty()) {
|
||||||
// Chain.
|
// Chain.
|
||||||
MonotonousRegion ®ion = *path_end.region;
|
MonotonicRegion ®ion = *path_end.region;
|
||||||
bool dir = path_end.flipped;
|
bool dir = path_end.flipped;
|
||||||
NextCandidate next_candidate;
|
NextCandidate next_candidate;
|
||||||
next_candidate.probability = 0;
|
next_candidate.probability = 0;
|
||||||
for (MonotonousRegion *next : region.right_neighbors) {
|
for (MonotonicRegion *next : region.right_neighbors) {
|
||||||
int &unprocessed = left_neighbors_unprocessed[next - regions.data()];
|
int &unprocessed = left_neighbors_unprocessed[next - regions.data()];
|
||||||
assert(unprocessed > 1);
|
assert(unprocessed > 1);
|
||||||
if (left_neighbors_unprocessed[next - regions.data()] == 2) {
|
if (left_neighbors_unprocessed[next - regions.data()] == 2) {
|
||||||
|
@ -2106,7 +2106,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
}
|
}
|
||||||
bool from_queue = next_candidate.probability == 0;
|
bool from_queue = next_candidate.probability == 0;
|
||||||
if (from_queue) {
|
if (from_queue) {
|
||||||
for (MonotonousRegion *next : queue) {
|
for (MonotonicRegion *next : queue) {
|
||||||
AntPath &path1 = path_matrix(region, dir, *next, false);
|
AntPath &path1 = path_matrix(region, dir, *next, false);
|
||||||
AntPath &path2 = path_matrix(region, dir, *next, true);
|
AntPath &path2 = path_matrix(region, dir, *next, true);
|
||||||
if (path1.visibility > next_candidate.probability)
|
if (path1.visibility > next_candidate.probability)
|
||||||
|
@ -2116,7 +2116,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Move the other right neighbors with satisified constraints to the queue.
|
// Move the other right neighbors with satisified constraints to the queue.
|
||||||
for (MonotonousRegion *next : region.right_neighbors)
|
for (MonotonicRegion *next : region.right_neighbors)
|
||||||
if (-- left_neighbors_unprocessed[next - regions.data()] == 1 && next_candidate.region != next)
|
if (-- left_neighbors_unprocessed[next - regions.data()] == 1 && next_candidate.region != next)
|
||||||
queue.emplace_back(next);
|
queue.emplace_back(next);
|
||||||
if (from_queue) {
|
if (from_queue) {
|
||||||
|
@ -2127,7 +2127,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
queue.pop_back();
|
queue.pop_back();
|
||||||
}
|
}
|
||||||
// Extend the path.
|
// Extend the path.
|
||||||
MonotonousRegion *next_region = next_candidate.region;
|
MonotonicRegion *next_region = next_candidate.region;
|
||||||
bool next_dir = next_candidate.dir;
|
bool next_dir = next_candidate.dir;
|
||||||
total_length += next_region->length(next_dir) + path_matrix(*path_end.region, path_end.flipped, *next_region, next_dir).length;
|
total_length += next_region->length(next_dir) + path_matrix(*path_end.region, path_end.flipped, *next_region, next_dir).length;
|
||||||
path_end = { next_region, next_dir };
|
path_end = { next_region, next_dir };
|
||||||
|
@ -2140,7 +2140,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
path_matrix.update_inital_pheromone(pheromone_initial_deposit);
|
path_matrix.update_inital_pheromone(pheromone_initial_deposit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Probability (unnormalized) of traversing a link between two monotonous regions.
|
// Probability (unnormalized) of traversing a link between two monotonic regions.
|
||||||
auto path_probability = [pheromone_alpha, pheromone_beta](AntPath &path) {
|
auto path_probability = [pheromone_alpha, pheromone_beta](AntPath &path) {
|
||||||
return pow(path.pheromone, pheromone_alpha) * pow(path.visibility, pheromone_beta);
|
return pow(path.pheromone, pheromone_alpha) * pow(path.visibility, pheromone_beta);
|
||||||
};
|
};
|
||||||
|
@ -2163,10 +2163,10 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
left_neighbors_unprocessed = left_neighbors_unprocessed_initial;
|
left_neighbors_unprocessed = left_neighbors_unprocessed_initial;
|
||||||
assert(validate_unprocessed());
|
assert(validate_unprocessed());
|
||||||
// Pick randomly the first from the queue at random orientation.
|
// Pick randomly the first from the queue at random orientation.
|
||||||
//FIXME picking the 1st monotonous region should likely be done based on accumulated pheromone level as well,
|
//FIXME picking the 1st monotonic region should likely be done based on accumulated pheromone level as well,
|
||||||
// but the inefficiency caused by the random pick of the 1st monotonous region is likely insignificant.
|
// but the inefficiency caused by the random pick of the 1st monotonic region is likely insignificant.
|
||||||
int first_idx = std::uniform_int_distribution<>(0, int(queue.size()) - 1)(rng);
|
int first_idx = std::uniform_int_distribution<>(0, int(queue.size()) - 1)(rng);
|
||||||
path.emplace_back(MonotonousRegionLink{ queue[first_idx], rng() > rng.max() / 2 });
|
path.emplace_back(MonotonicRegionLink{ queue[first_idx], rng() > rng.max() / 2 });
|
||||||
*(queue.begin() + first_idx) = std::move(queue.back());
|
*(queue.begin() + first_idx) = std::move(queue.back());
|
||||||
queue.pop_back();
|
queue.pop_back();
|
||||||
-- left_neighbors_unprocessed[path.back().region - regions.data()];
|
-- left_neighbors_unprocessed[path.back().region - regions.data()];
|
||||||
|
@ -2182,12 +2182,12 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
|
|
||||||
while (! queue.empty() || ! path.back().region->right_neighbors.empty()) {
|
while (! queue.empty() || ! path.back().region->right_neighbors.empty()) {
|
||||||
// Chain.
|
// Chain.
|
||||||
MonotonousRegion ®ion = *path.back().region;
|
MonotonicRegion ®ion = *path.back().region;
|
||||||
bool dir = path.back().flipped;
|
bool dir = path.back().flipped;
|
||||||
// Sort by distance to pt.
|
// Sort by distance to pt.
|
||||||
next_candidates.clear();
|
next_candidates.clear();
|
||||||
next_candidates.reserve(region.right_neighbors.size() * 2);
|
next_candidates.reserve(region.right_neighbors.size() * 2);
|
||||||
for (MonotonousRegion *next : region.right_neighbors) {
|
for (MonotonicRegion *next : region.right_neighbors) {
|
||||||
int &unprocessed = left_neighbors_unprocessed[next - regions.data()];
|
int &unprocessed = left_neighbors_unprocessed[next - regions.data()];
|
||||||
assert(unprocessed > 1);
|
assert(unprocessed > 1);
|
||||||
if (-- unprocessed == 1) {
|
if (-- unprocessed == 1) {
|
||||||
|
@ -2204,7 +2204,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
//FIXME add the queue items to the candidates? These are valid moves as well.
|
//FIXME add the queue items to the candidates? These are valid moves as well.
|
||||||
if (num_direct_neighbors == 0) {
|
if (num_direct_neighbors == 0) {
|
||||||
// Add the queue candidates.
|
// Add the queue candidates.
|
||||||
for (MonotonousRegion *next : queue) {
|
for (MonotonicRegion *next : queue) {
|
||||||
assert(left_neighbors_unprocessed[next - regions.data()] == 1);
|
assert(left_neighbors_unprocessed[next - regions.data()] == 1);
|
||||||
AntPath &path1 = path_matrix(region, dir, *next, false);
|
AntPath &path1 = path_matrix(region, dir, *next, false);
|
||||||
AntPath &path1_flipped = path_matrix(region, ! dir, *next, true);
|
AntPath &path1_flipped = path_matrix(region, ! dir, *next, true);
|
||||||
|
@ -2247,11 +2247,11 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
queue.pop_back();
|
queue.pop_back();
|
||||||
}
|
}
|
||||||
// Extend the path.
|
// Extend the path.
|
||||||
MonotonousRegion *next_region = take_path->region;
|
MonotonicRegion *next_region = take_path->region;
|
||||||
bool next_dir = take_path->dir;
|
bool next_dir = take_path->dir;
|
||||||
path.back().next = take_path->link;
|
path.back().next = take_path->link;
|
||||||
path.back().next_flipped = take_path->link_flipped;
|
path.back().next_flipped = take_path->link_flipped;
|
||||||
path.emplace_back(MonotonousRegionLink{ next_region, next_dir });
|
path.emplace_back(MonotonicRegionLink{ next_region, next_dir });
|
||||||
assert(left_neighbors_unprocessed[next_region - regions.data()] == 1);
|
assert(left_neighbors_unprocessed[next_region - regions.data()] == 1);
|
||||||
left_neighbors_unprocessed[next_region - regions.data()] = 0;
|
left_neighbors_unprocessed[next_region - regions.data()] = 0;
|
||||||
print_ant("\tRegion (%1%:%2%,%3%) (%4%:%5%,%6%) length to prev %7%",
|
print_ant("\tRegion (%1%:%2%,%3%) (%4%:%5%,%6%) length to prev %7%",
|
||||||
|
@ -2279,14 +2279,14 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform 3-opt local optimization of the path.
|
// Perform 3-opt local optimization of the path.
|
||||||
monotonous_3_opt(path, segs);
|
monotonic_3_opt(path, segs);
|
||||||
|
|
||||||
// Measure path length.
|
// Measure path length.
|
||||||
assert(! path.empty());
|
assert(! path.empty());
|
||||||
float path_length = std::accumulate(path.begin(), path.end() - 1,
|
float path_length = std::accumulate(path.begin(), path.end() - 1,
|
||||||
path.back().region->length(path.back().flipped),
|
path.back().region->length(path.back().flipped),
|
||||||
[&path_matrix](const float l, const MonotonousRegionLink &r) {
|
[&path_matrix](const float l, const MonotonicRegionLink &r) {
|
||||||
const MonotonousRegionLink &next = *(&r + 1);
|
const MonotonicRegionLink &next = *(&r + 1);
|
||||||
return l + r.region->length(r.flipped) + path_matrix(*r.region, r.flipped, *next.region, next.flipped).length;
|
return l + r.region->length(r.flipped) + path_matrix(*r.region, r.flipped, *next.region, next.flipped).length;
|
||||||
});
|
});
|
||||||
// Save the shortest path.
|
// Save the shortest path.
|
||||||
|
@ -2309,7 +2309,7 @@ static std::vector<MonotonousRegionLink> chain_monotonous_regions(
|
||||||
// Reinforce the path pheromones with the best path.
|
// Reinforce the path pheromones with the best path.
|
||||||
float total_cost = best_path_length + float(EPSILON);
|
float total_cost = best_path_length + float(EPSILON);
|
||||||
for (size_t i = 0; i + 1 < path.size(); ++ i) {
|
for (size_t i = 0; i + 1 < path.size(); ++ i) {
|
||||||
MonotonousRegionLink &link = path[i];
|
MonotonicRegionLink &link = path[i];
|
||||||
link.next->pheromone = (1.f - pheromone_evaporation) * link.next->pheromone + pheromone_evaporation / total_cost;
|
link.next->pheromone = (1.f - pheromone_evaporation) * link.next->pheromone + pheromone_evaporation / total_cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2324,7 +2324,7 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse path, produce polylines.
|
// Traverse path, produce polylines.
|
||||||
static void polylines_from_paths(const std::vector<MonotonousRegionLink> &path, const ExPolygonWithOffset &poly_with_offset, const std::vector<SegmentedIntersectionLine> &segs, Polylines &polylines_out)
|
static void polylines_from_paths(const std::vector<MonotonicRegionLink> &path, const ExPolygonWithOffset &poly_with_offset, const std::vector<SegmentedIntersectionLine> &segs, Polylines &polylines_out)
|
||||||
{
|
{
|
||||||
Polyline *polyline = nullptr;
|
Polyline *polyline = nullptr;
|
||||||
auto finish_polyline = [&polyline, &polylines_out]() {
|
auto finish_polyline = [&polyline, &polylines_out]() {
|
||||||
|
@ -2340,8 +2340,8 @@ static void polylines_from_paths(const std::vector<MonotonousRegionLink> &path,
|
||||||
polyline = nullptr;
|
polyline = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const MonotonousRegionLink &path_segment : path) {
|
for (const MonotonicRegionLink &path_segment : path) {
|
||||||
MonotonousRegion ®ion = *path_segment.region;
|
MonotonicRegion ®ion = *path_segment.region;
|
||||||
bool dir = path_segment.flipped;
|
bool dir = path_segment.flipped;
|
||||||
|
|
||||||
// From the initial point (i_vline, i_intersection), follow a path.
|
// From the initial point (i_vline, i_intersection), follow a path.
|
||||||
|
@ -2350,8 +2350,8 @@ static void polylines_from_paths(const std::vector<MonotonousRegionLink> &path,
|
||||||
|
|
||||||
if (polyline != nullptr && &path_segment != path.data()) {
|
if (polyline != nullptr && &path_segment != path.data()) {
|
||||||
// Connect previous path segment with the new one.
|
// Connect previous path segment with the new one.
|
||||||
const MonotonousRegionLink &path_segment_prev = *(&path_segment - 1);
|
const MonotonicRegionLink &path_segment_prev = *(&path_segment - 1);
|
||||||
const MonotonousRegion ®ion_prev = *path_segment_prev.region;
|
const MonotonicRegion ®ion_prev = *path_segment_prev.region;
|
||||||
bool dir_prev = path_segment_prev.flipped;
|
bool dir_prev = path_segment_prev.flipped;
|
||||||
int i_vline_prev = region_prev.right.vline;
|
int i_vline_prev = region_prev.right.vline;
|
||||||
const SegmentedIntersectionLine &vline_prev = segs[i_vline_prev];
|
const SegmentedIntersectionLine &vline_prev = segs[i_vline_prev];
|
||||||
|
@ -2456,7 +2456,7 @@ static void polylines_from_paths(const std::vector<MonotonousRegionLink> &path,
|
||||||
|
|
||||||
if (polyline != nullptr) {
|
if (polyline != nullptr) {
|
||||||
// Finish the current vertical line,
|
// Finish the current vertical line,
|
||||||
const MonotonousRegion ®ion = *path.back().region;
|
const MonotonicRegion ®ion = *path.back().region;
|
||||||
const SegmentedIntersectionLine &vline = segs[region.right.vline];
|
const SegmentedIntersectionLine &vline = segs[region.right.vline];
|
||||||
const SegmentIntersection *ip = &vline.intersections[region.right_intersection_point(path.back().flipped)];
|
const SegmentIntersection *ip = &vline.intersections[region.right_intersection_point(path.back().flipped)];
|
||||||
assert(ip->is_inner());
|
assert(ip->is_inner());
|
||||||
|
@ -2558,14 +2558,14 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
||||||
svg.Close();
|
svg.Close();
|
||||||
#endif /* SLIC3R_DEBUG */
|
#endif /* SLIC3R_DEBUG */
|
||||||
|
|
||||||
//FIXME this is a hack to get the monotonous infill rolling. We likely want a smarter switch, likely based on user decison.
|
//FIXME this is a hack to get the monotonic infill rolling. We likely want a smarter switch, likely based on user decison.
|
||||||
bool monotonous_infill = params.monotonous; // || params.density > 0.99;
|
bool monotonic_infill = params.monotonic; // || params.density > 0.99;
|
||||||
if (monotonous_infill) {
|
if (monotonic_infill) {
|
||||||
std::vector<MonotonousRegion> regions = generate_montonous_regions(segs);
|
std::vector<MonotonicRegion> regions = generate_montonous_regions(segs);
|
||||||
connect_monotonous_regions(regions, poly_with_offset, segs);
|
connect_monotonic_regions(regions, poly_with_offset, segs);
|
||||||
if (! regions.empty()) {
|
if (! regions.empty()) {
|
||||||
std::mt19937_64 rng;
|
std::mt19937_64 rng;
|
||||||
std::vector<MonotonousRegionLink> path = chain_monotonous_regions(regions, poly_with_offset, segs, rng);
|
std::vector<MonotonicRegionLink> path = chain_monotonic_regions(regions, poly_with_offset, segs, rng);
|
||||||
polylines_from_paths(path, poly_with_offset, segs, polylines_out);
|
polylines_from_paths(path, poly_with_offset, segs, polylines_out);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -2616,13 +2616,13 @@ Polylines FillRectilinear2::fill_surface(const Surface *surface, const FillParam
|
||||||
return polylines_out;
|
return polylines_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
Polylines FillMonotonous::fill_surface(const Surface *surface, const FillParams ¶ms)
|
Polylines FillMonotonic::fill_surface(const Surface *surface, const FillParams ¶ms)
|
||||||
{
|
{
|
||||||
FillParams params2 = params;
|
FillParams params2 = params;
|
||||||
params2.monotonous = true;
|
params2.monotonic = true;
|
||||||
Polylines polylines_out;
|
Polylines polylines_out;
|
||||||
if (! fill_surface_by_lines(surface, params2, 0.f, 0.f, polylines_out)) {
|
if (! fill_surface_by_lines(surface, params2, 0.f, 0.f, polylines_out)) {
|
||||||
printf("FillMonotonous::fill_surface() failed to fill a region.\n");
|
printf("FillMonotonic::fill_surface() failed to fill a region.\n");
|
||||||
}
|
}
|
||||||
return polylines_out;
|
return polylines_out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,11 @@ protected:
|
||||||
bool fill_surface_by_lines(const Surface *surface, const FillParams ¶ms, float angleBase, float pattern_shift, Polylines &polylines_out);
|
bool fill_surface_by_lines(const Surface *surface, const FillParams ¶ms, float angleBase, float pattern_shift, Polylines &polylines_out);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FillMonotonous : public FillRectilinear2
|
class FillMonotonic : public FillRectilinear2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual Fill* clone() const { return new FillMonotonous(*this); };
|
virtual Fill* clone() const { return new FillMonotonic(*this); };
|
||||||
virtual ~FillMonotonous() = default;
|
virtual ~FillMonotonic() = default;
|
||||||
virtual Polylines fill_surface(const Surface *surface, const FillParams ¶ms);
|
virtual Polylines fill_surface(const Surface *surface, const FillParams ¶ms);
|
||||||
virtual bool no_sort() const { return true; }
|
virtual bool no_sort() const { return true; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -457,20 +457,20 @@ void PrintConfigDef::init_fff_params()
|
||||||
def->cli = "top-fill-pattern|external-fill-pattern|solid-fill-pattern";
|
def->cli = "top-fill-pattern|external-fill-pattern|solid-fill-pattern";
|
||||||
def->enum_keys_map = &ConfigOptionEnum<InfillPattern>::get_enum_values();
|
def->enum_keys_map = &ConfigOptionEnum<InfillPattern>::get_enum_values();
|
||||||
def->enum_values.push_back("rectilinear");
|
def->enum_values.push_back("rectilinear");
|
||||||
def->enum_values.push_back("monotonous");
|
def->enum_values.push_back("monotonic");
|
||||||
def->enum_values.push_back("concentric");
|
def->enum_values.push_back("concentric");
|
||||||
def->enum_values.push_back("hilbertcurve");
|
def->enum_values.push_back("hilbertcurve");
|
||||||
def->enum_values.push_back("archimedeanchords");
|
def->enum_values.push_back("archimedeanchords");
|
||||||
def->enum_values.push_back("octagramspiral");
|
def->enum_values.push_back("octagramspiral");
|
||||||
def->enum_labels.push_back(L("Rectilinear"));
|
def->enum_labels.push_back(L("Rectilinear"));
|
||||||
def->enum_labels.push_back(L("Monotonous"));
|
def->enum_labels.push_back(L("Monotonic"));
|
||||||
def->enum_labels.push_back(L("Concentric"));
|
def->enum_labels.push_back(L("Concentric"));
|
||||||
def->enum_labels.push_back(L("Hilbert Curve"));
|
def->enum_labels.push_back(L("Hilbert Curve"));
|
||||||
def->enum_labels.push_back(L("Archimedean Chords"));
|
def->enum_labels.push_back(L("Archimedean Chords"));
|
||||||
def->enum_labels.push_back(L("Octagram Spiral"));
|
def->enum_labels.push_back(L("Octagram Spiral"));
|
||||||
// solid_fill_pattern is an obsolete equivalent to top_fill_pattern/bottom_fill_pattern.
|
// solid_fill_pattern is an obsolete equivalent to top_fill_pattern/bottom_fill_pattern.
|
||||||
def->aliases = { "solid_fill_pattern", "external_fill_pattern" };
|
def->aliases = { "solid_fill_pattern", "external_fill_pattern" };
|
||||||
def->set_default_value(new ConfigOptionEnum<InfillPattern>(ipMonotonous));
|
def->set_default_value(new ConfigOptionEnum<InfillPattern>(ipMonotonic));
|
||||||
|
|
||||||
def = this->add("bottom_fill_pattern", coEnum);
|
def = this->add("bottom_fill_pattern", coEnum);
|
||||||
def->label = L("Bottom fill pattern");
|
def->label = L("Bottom fill pattern");
|
||||||
|
|
|
@ -45,7 +45,7 @@ enum AuthorizationType {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum InfillPattern : int {
|
enum InfillPattern : int {
|
||||||
ipRectilinear, ipMonotonous, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
|
ipRectilinear, ipMonotonic, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
|
||||||
ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipSupportCubic, ipCount,
|
ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipAdaptiveCubic, ipSupportCubic, ipCount,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ template<> inline const t_config_enum_values& ConfigOptionEnum<InfillPattern>::g
|
||||||
static t_config_enum_values keys_map;
|
static t_config_enum_values keys_map;
|
||||||
if (keys_map.empty()) {
|
if (keys_map.empty()) {
|
||||||
keys_map["rectilinear"] = ipRectilinear;
|
keys_map["rectilinear"] = ipRectilinear;
|
||||||
keys_map["monotonous"] = ipMonotonous;
|
keys_map["monotonic"] = ipMonotonic;
|
||||||
keys_map["grid"] = ipGrid;
|
keys_map["grid"] = ipGrid;
|
||||||
keys_map["triangles"] = ipTriangles;
|
keys_map["triangles"] = ipTriangles;
|
||||||
keys_map["stars"] = ipStars;
|
keys_map["stars"] = ipStars;
|
||||||
|
|
|
@ -2706,7 +2706,7 @@ void PrintObject::combine_infill()
|
||||||
// Because fill areas for rectilinear and honeycomb are grown
|
// Because fill areas for rectilinear and honeycomb are grown
|
||||||
// later to overlap perimeters, we need to counteract that too.
|
// later to overlap perimeters, we need to counteract that too.
|
||||||
((region->config().fill_pattern == ipRectilinear ||
|
((region->config().fill_pattern == ipRectilinear ||
|
||||||
region->config().fill_pattern == ipMonotonous ||
|
region->config().fill_pattern == ipMonotonic ||
|
||||||
region->config().fill_pattern == ipGrid ||
|
region->config().fill_pattern == ipGrid ||
|
||||||
region->config().fill_pattern == ipLine ||
|
region->config().fill_pattern == ipLine ||
|
||||||
region->config().fill_pattern == ipHoneycomb) ? 1.5f : 0.5f) *
|
region->config().fill_pattern == ipHoneycomb) ? 1.5f : 0.5f) *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue