ENH: optimize area of top surface
Signed-off-by: salt.wei <salt.wei@bambulab.com> Change-Id: Ia3d1be6ad3b9f55ee1acda14d0be955055f6dfcb (cherry picked from commit 448fd3043950613a4d91df256fa9ee52a57fcaca)
This commit is contained in:
parent
9f4a54d280
commit
030d97bf78
3 changed files with 56 additions and 1 deletions
|
@ -350,6 +350,50 @@ void Layer::export_region_fill_surfaces_to_svg_debug(const char *name) const
|
|||
this->export_region_fill_surfaces_to_svg(debug_out_path("Layer-fill_surfaces-%s-%d.svg", name, idx ++).c_str());
|
||||
}
|
||||
|
||||
coordf_t Layer::get_sparse_infill_max_void_area()
|
||||
{
|
||||
double max_void_area = 0.;
|
||||
for (auto layerm : m_regions) {
|
||||
Flow flow = layerm->flow(frInfill);
|
||||
float density = layerm->region().config().sparse_infill_density;
|
||||
InfillPattern pattern = layerm->region().config().sparse_infill_pattern;
|
||||
if (density == 0.)
|
||||
return -1;
|
||||
|
||||
//BBS: rough estimation and need to be optimized
|
||||
double spacing = flow.scaled_spacing() * (100 - density) / density;
|
||||
switch (pattern) {
|
||||
case ipConcentric:
|
||||
case ipRectilinear:
|
||||
case ipLine:
|
||||
case ipGyroid:
|
||||
case ipAlignedRectilinear:
|
||||
case ipOctagramSpiral:
|
||||
case ipHilbertCurve:
|
||||
case ip3DHoneycomb:
|
||||
case ipArchimedeanChords:
|
||||
max_void_area = std::max(max_void_area, spacing * spacing);
|
||||
break;
|
||||
case ipGrid:
|
||||
case ipHoneycomb:
|
||||
case ipLightning:
|
||||
max_void_area = std::max(max_void_area, 4.0 * spacing * spacing);
|
||||
break;
|
||||
case ipCubic:
|
||||
case ipAdaptiveCubic:
|
||||
case ipTriangles:
|
||||
case ipStars:
|
||||
case ipSupportCubic:
|
||||
max_void_area = std::max(max_void_area, 4.5 * spacing * spacing);
|
||||
break;
|
||||
default:
|
||||
max_void_area = std::max(max_void_area, spacing * spacing);
|
||||
break;
|
||||
}
|
||||
};
|
||||
return max_void_area;
|
||||
}
|
||||
|
||||
BoundingBox get_extents(const LayerRegion &layer_region)
|
||||
{
|
||||
BoundingBox bbox;
|
||||
|
|
|
@ -184,6 +184,8 @@ public:
|
|||
|
||||
//BBS
|
||||
void simplify_extrusion_path() { for (auto layerm : m_regions) layerm->simplify_extrusion_entity();}
|
||||
//BBS: this function calculate the maximum void grid area of sparse infill of this layer. Just estimated value
|
||||
coordf_t get_sparse_infill_max_void_area();
|
||||
|
||||
protected:
|
||||
friend class PrintObject;
|
||||
|
|
|
@ -152,11 +152,20 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly
|
|||
{
|
||||
// Voids are sparse infills if infill rate is zero.
|
||||
Polygons voids;
|
||||
|
||||
double max_grid_area = -1;
|
||||
if (this->layer()->lower_layer != nullptr)
|
||||
max_grid_area = this->layer()->lower_layer->get_sparse_infill_max_void_area();
|
||||
for (const Surface &surface : this->fill_surfaces.surfaces) {
|
||||
if (surface.is_top()) {
|
||||
// Collect the top surfaces, inflate them and trim them by the bottom surfaces.
|
||||
// This gives the priority to bottom surfaces.
|
||||
surfaces_append(top, offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
|
||||
if (max_grid_area < 0 || surface.expolygon.area() < max_grid_area)
|
||||
surfaces_append(top, offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
|
||||
else
|
||||
//BBS: Don't need to expand too much in this situation. Expand 3mm to eliminate hole and 1mm for contour
|
||||
surfaces_append(top, intersection_ex(offset(surface.expolygon.contour, margin / 3.0, EXTERNAL_SURFACES_OFFSET_PARAMETERS),
|
||||
offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS)), surface);
|
||||
} else if (surface.surface_type == stBottom || (surface.surface_type == stBottomBridge && lower_layer == nullptr)) {
|
||||
// Grown by 3mm.
|
||||
surfaces_append(bottom, offset_ex(surface.expolygon, margin, EXTERNAL_SURFACES_OFFSET_PARAMETERS), surface);
|
||||
|
|
Loading…
Reference in a new issue