Skip to content

Commit

Permalink
Fix for issue Ultimaker/Cura#19586 in the cradle branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRahm committed Aug 28, 2024
1 parent 4b9a595 commit ad51551
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,8 @@ void AreaSupport::generateSupportRoof(SliceDataStorage& storage, const SliceMesh
{
return;
}
const coord_t z_distance_top = round_up_divide(mesh.settings.get<coord_t>("support_top_distance"), layer_height); // Number of layers between support roof and model.
const coord_t z_distance_top = mesh.settings.get<coord_t>("support_top_distance");
const coord_t z_distance_top_layers = round_up_divide(z_distance_top, layer_height); // Number of layers between support roof and model.
const coord_t roof_line_width = mesh_group_settings.get<ExtruderTrain&>("support_roof_extruder_nr").settings_.get<coord_t>("support_roof_line_width");
const coord_t roof_outline_offset = mesh_group_settings.get<ExtruderTrain&>("support_roof_extruder_nr").settings_.get<coord_t>("support_roof_offset");
const coord_t roof_line_distance = mesh.settings.get<coord_t>("support_roof_line_distance");
Expand All @@ -1722,21 +1723,21 @@ void AreaSupport::generateSupportRoof(SliceDataStorage& storage, const SliceMesh

std::vector<SupportLayer>& support_layers = storage.support.supportLayers;
Shape roofs_before;
for (LayerIndex layer_idx = static_cast<int>(support_layers.size() - z_distance_top) - 1; layer_idx >= 0; --layer_idx)
for (LayerIndex layer_idx = static_cast<int>(support_layers.size() - z_distance_top_layers) - 1; layer_idx >= 0; --layer_idx)
{
const LayerIndex top_layer_idx_above{
std::min(LayerIndex{ support_layers.size() - 1 }, LayerIndex{ layer_idx + roof_layer_count + z_distance_top })
std::min(LayerIndex{ support_layers.size() - 1 }, LayerIndex{ layer_idx + roof_layer_count + z_distance_top_layers })
}; // Maximum layer of the model that generates support roof.
Shape mesh_outlines;
for (auto layer_idx_above = top_layer_idx_above; layer_idx_above > layer_idx + z_distance_top - 1; layer_idx_above -= 1)
for (auto layer_idx_above = top_layer_idx_above; layer_idx_above > layer_idx + z_distance_top_layers - 1; layer_idx_above -= 1)
{
mesh_outlines.push_back(mesh.layers[layer_idx_above].getOutlines());
}
Shape roofs;
generateSupportInterfaceLayer(global_support_areas_per_layer[layer_idx], mesh_outlines, roof_line_width, roof_outline_offset, minimum_roof_area, roofs);
// If roof is added as fractional, even though non can exist because remaining z distance is 0 it will be regular roof.
support_layers[layer_idx].fillRoofParts(layer_idx > 0 ? roofs.intersection(roofs_before) : roofs, roof_line_width, roof_wall_line_count);
if (layer_idx > 0)
support_layers[layer_idx].fillRoofParts(layer_idx > 0 && z_distance_top % layer_height != 0? roofs.intersection(roofs_before) : roofs, roof_line_width, roof_wall_line_count);
if (layer_idx > 0 && z_distance_top % layer_height != 0)
{
support_layers[layer_idx].fillRoofParts(roofs.difference(roofs_before), roof_line_width, roof_wall_line_count, true);
}
Expand All @@ -1745,15 +1746,15 @@ void AreaSupport::generateSupportRoof(SliceDataStorage& storage, const SliceMesh
}

// Remove support in between the support roof and the model. Subtracts the roof polygons from the support polygons on the layers above it.
for (auto [layer_idx, support_layer] : support_layers | ranges::views::enumerate | ranges::views::drop(1) | ranges::views::drop_last(z_distance_top))
for (auto [layer_idx, support_layer] : support_layers | ranges::views::enumerate | ranges::views::drop(1) | ranges::views::drop_last(z_distance_top_layers))
{
if (support_layer.support_roof.empty())
{
continue;
}

int lower = static_cast<int>(layer_idx);
int upper = std::min(static_cast<int>(layer_idx + roof_layer_count + z_distance_top + 5), static_cast<int>(global_support_areas_per_layer.size()) - 1);
int upper = std::min(static_cast<int>(layer_idx + roof_layer_count + z_distance_top_layers + 5), static_cast<int>(global_support_areas_per_layer.size()) - 1);
for (Shape& global_support : global_support_areas_per_layer | ranges::views::slice(lower, upper))
{
global_support = global_support.difference(support_layer.getTotalAreaFromParts(support_layer.support_roof));
Expand Down

0 comments on commit ad51551

Please sign in to comment.