Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/CURA-11352' into CURA-11352
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/utils/ExtrusionLine.h
  • Loading branch information
casperlamboo committed Dec 22, 2023
2 parents dccf20f + cb684d4 commit 91800fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
9 changes: 7 additions & 2 deletions include/utils/ExtrusionLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#ifndef UTILS_EXTRUSION_LINE_H
#define UTILS_EXTRUSION_LINE_H

#include <range/v3/view/sliding.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/sliding.hpp>
//#include <range/v3/view/take.hpp>
//#include <range/v3/view/take_last.hpp>
//#include <range/v3/view/drop.hpp>
//#include <range/v3/view/drop_last.hpp>
#include <range/v3/view/enumerate.hpp>

#include "ExtrusionJunction.h"
Expand Down Expand Up @@ -238,7 +242,8 @@ struct ExtrusionLine
{
Polygon poly;

const auto add_line_direction = [&poly](const auto iterator){
const auto add_line_direction = [&poly](const auto iterator)
{
const auto window = iterator | ranges::views::sliding(2);

for (const auto& element : iterator | ranges::views::sliding(2))
Expand Down
55 changes: 30 additions & 25 deletions src/InsetOrderOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "InsetOrderOptimizer.h"

#include <tuple>
#include <functional>
#include <tuple>

#include <range/v3/algorithm/max.hpp>
#include <range/v3/algorithm/sort.hpp>
Expand Down Expand Up @@ -145,24 +145,32 @@ InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::v
}

// view on the extrusion lines, sorted by area
const auto sorted_extrusion_lines = [&extrusion_lines](){
auto extrusion_lines_area
= extrusion_lines
| ranges::views::addressof
| ranges::views::transform([](const ExtrusionLine* line) {
const auto poly = line->toPolygon();
AABB aabb;
aabb.include(poly);
return std::make_pair(line, aabb.area());
})
| ranges::to_vector;

ranges::sort(extrusion_lines_area, [](const auto& lhs, const auto& rhs)
{
return std::get<1>(lhs) < std::get<1>(rhs);
});

return extrusion_lines_area | ranges::views::transform([](const auto& pair) { return std::get<0>(pair); });
const auto sorted_extrusion_lines = [&extrusion_lines]()
{
auto extrusion_lines_area = extrusion_lines | ranges::views::addressof
| ranges::views::transform(
[](const ExtrusionLine* line)
{
const auto poly = line->toPolygon();
AABB aabb;
aabb.include(poly);
return std::make_pair(line, aabb.area());
})
| ranges::to_vector;

ranges::sort(
extrusion_lines_area,
[](const auto& lhs, const auto& rhs)
{
return std::get<1>(lhs) < std::get<1>(rhs);
});

return extrusion_lines_area
| ranges::views::transform(
[](const auto& pair)
{
return std::get<0>(pair);
});
}();

// graph will contain the parent-child relationships between the extrusion lines
Expand Down Expand Up @@ -209,11 +217,7 @@ InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::v
invariant_outer_parents.emplace(extrusion_line);
}

const std::vector<const ExtrusionLine*> outer_walls
= extrusion_lines
| ranges::views::filter(&ExtrusionLine::is_outer_wall)
| ranges::views::addressof
| ranges::to_vector;
const std::vector<const ExtrusionLine*> outer_walls = extrusion_lines | ranges::views::filter(&ExtrusionLine::is_outer_wall) | ranges::views::addressof | ranges::to_vector;

std::unordered_multimap<const ExtrusionLine*, const ExtrusionLine*> order;

Expand All @@ -222,7 +226,8 @@ InsetOrderOptimizer::value_type InsetOrderOptimizer::getRegionOrder(const std::v
std::unordered_map<const ExtrusionLine*, const ExtrusionLine*> min_node;
for (const ExtrusionLine* outer_wall : outer_walls)
{
const std::function<void(const ExtrusionLine*, const unsigned int)> update_nodes = [&outer_wall, &min_depth, &min_node](const ExtrusionLine* current_node, const unsigned int depth)
const std::function<void(const ExtrusionLine*, const unsigned int)> update_nodes
= [&outer_wall, &min_depth, &min_node](const ExtrusionLine* current_node, const unsigned int depth)
{
if (min_depth.find(current_node) == min_depth.end() || depth < min_depth[current_node])
{
Expand Down

0 comments on commit 91800fc

Please sign in to comment.