Variable-width thin walls. Yay!

This commit is contained in:
Alessandro Ranellucci 2016-03-19 19:40:11 +01:00
parent 6dc42ee902
commit dfb1ec99ac
3 changed files with 21 additions and 22 deletions

View File

@ -54,6 +54,7 @@ class ExtrusionEntity
virtual Polygons grow() const = 0; virtual Polygons grow() const = 0;
virtual double min_mm3_per_mm() const = 0; virtual double min_mm3_per_mm() const = 0;
virtual Polyline as_polyline() const = 0; virtual Polyline as_polyline() const = 0;
virtual double length() const { return 0; };
}; };
typedef std::vector<ExtrusionEntity*> ExtrusionEntitiesPtr; typedef std::vector<ExtrusionEntity*> ExtrusionEntitiesPtr;
@ -76,7 +77,7 @@ class ExtrusionPath : public ExtrusionEntity
void subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const; void subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const;
void clip_end(double distance); void clip_end(double distance);
void simplify(double tolerance); void simplify(double tolerance);
double length() const; virtual double length() const;
bool is_perimeter() const; bool is_perimeter() const;
bool is_infill() const; bool is_infill() const;
bool is_solid_infill() const; bool is_solid_infill() const;
@ -121,7 +122,7 @@ class ExtrusionLoop : public ExtrusionEntity
Point first_point() const; Point first_point() const;
Point last_point() const; Point last_point() const;
Polygon polygon() const; Polygon polygon() const;
double length() const; virtual double length() const;
bool split_at_vertex(const Point &point); bool split_at_vertex(const Point &point);
void split_at(const Point &point); void split_at(const Point &point);
void clip_end(double distance, ExtrusionPaths* paths) const; void clip_end(double distance, ExtrusionPaths* paths) const;

View File

@ -64,7 +64,7 @@ PerimeterGenerator::process()
std::vector<PerimeterGeneratorLoops> contours(loop_number+1); // depth => loops std::vector<PerimeterGeneratorLoops> contours(loop_number+1); // depth => loops
std::vector<PerimeterGeneratorLoops> holes(loop_number+1); // depth => loops std::vector<PerimeterGeneratorLoops> holes(loop_number+1); // depth => loops
Polylines thin_walls; ThickPolylines thin_walls;
// we loop one time more than needed in order to find gaps after the last perimeter was applied // we loop one time more than needed in order to find gaps after the last perimeter was applied
for (signed short i = 0; i <= loop_number+1; ++i) { // outer loop is 0 for (signed short i = 0; i <= loop_number+1; ++i) { // outer loop is 0
@ -96,16 +96,8 @@ PerimeterGenerator::process()
ExPolygons expp = offset2_ex(diffpp, -min_width/2, +min_width/2); ExPolygons expp = offset2_ex(diffpp, -min_width/2, +min_width/2);
// the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop // the maximum thickness of our thin wall area is equal to the minimum thickness of a single loop
Polylines pp;
for (ExPolygons::const_iterator ex = expp.begin(); ex != expp.end(); ++ex) for (ExPolygons::const_iterator ex = expp.begin(); ex != expp.end(); ++ex)
ex->medial_axis(ext_pwidth + ext_pspacing2, min_width, &pp); ex->medial_axis(ext_pwidth + ext_pspacing2, min_width, &thin_walls);
double threshold = ext_pwidth * 2;
for (Polylines::const_iterator p = pp.begin(); p != pp.end(); ++p) {
if (p->length() > threshold) {
thin_walls.push_back(*p);
}
}
#ifdef DEBUG #ifdef DEBUG
printf(" %zu thin walls detected\n", thin_walls.size()); printf(" %zu thin walls detected\n", thin_walls.size());
@ -329,7 +321,7 @@ PerimeterGenerator::process()
ExtrusionEntityCollection ExtrusionEntityCollection
PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops, PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops,
Polylines &thin_walls) const ThickPolylines &thin_walls) const
{ {
// loops is an arrayref of ::Loop objects // loops is an arrayref of ::Loop objects
// turn each one into an ExtrusionLoop object // turn each one into an ExtrusionLoop object
@ -403,15 +395,21 @@ PerimeterGenerator::_traverse_loops(const PerimeterGeneratorLoops &loops,
} }
// append thin walls to the nearest-neighbor search (only for first iteration) // append thin walls to the nearest-neighbor search (only for first iteration)
for (Polylines::const_iterator polyline = thin_walls.begin(); polyline != thin_walls.end(); ++polyline) { {
ExtrusionPath path(erExternalPerimeter); ExtrusionEntityCollection tw = this->_variable_width
path.polyline = *polyline; (thin_walls, erExternalPerimeter, this->ext_perimeter_flow);
path.mm3_per_mm = this->_mm3_per_mm;
path.width = this->perimeter_flow.width; const double threshold = this->ext_perimeter_flow.scaled_width() * 2;
path.height = this->layer_height; for (size_t i = 0; i < tw.entities.size(); ++i) {
coll.append(path); if (tw.entities[i]->length() < threshold) {
tw.remove(i);
--i;
}
}
coll.append(tw.entities);
thin_walls.clear();
} }
thin_walls.clear();
// sort entities into a new collection using a nearest-neighbor search, // sort entities into a new collection using a nearest-neighbor search,
// preserving the original indices which are useful for detecting thin walls // preserving the original indices which are useful for detecting thin walls

View File

@ -65,7 +65,7 @@ class PerimeterGenerator {
Polygons _lower_slices_p; Polygons _lower_slices_p;
ExtrusionEntityCollection _traverse_loops(const PerimeterGeneratorLoops &loops, ExtrusionEntityCollection _traverse_loops(const PerimeterGeneratorLoops &loops,
Polylines &thin_walls) const; ThickPolylines &thin_walls) const;
ExtrusionEntityCollection _variable_width ExtrusionEntityCollection _variable_width
(const ThickPolylines &polylines, ExtrusionRole role, Flow flow) const; (const ThickPolylines &polylines, ExtrusionRole role, Flow flow) const;
}; };