WIP TreeSupports: Extracting make_circle() into Polygon.cpp,hpp

This commit is contained in:
Vojtech Bubnik 2022-09-01 15:47:13 +02:00
parent 19f0d94be3
commit f790468cca
3 changed files with 27 additions and 13 deletions

View File

@ -528,4 +528,23 @@ bool contains(const Polygons &polygons, const Point &p, bool border_result)
return (poly_count_inside % 2) == 1; return (poly_count_inside % 2) == 1;
} }
Polygon make_circle(double radius, double error)
{
double angle = 2. * acos(1. - error / radius);
size_t num_segments = size_t(ceil(2. * M_PI / angle));
return make_circle_num_segments(radius, num_segments);
}
Polygon make_circle_num_segments(double radius, size_t num_segments)
{
Polygon out;
out.points.reserve(num_segments);
double angle_inc = 2.0 * M_PI / num_segments;
for (size_t i = 0; i < num_segments; ++ i) {
const double angle = angle_inc * i;
out.points.emplace_back(coord_t(cos(angle) * radius), coord_t(sin(angle) * radius));
}
return out;
}
} }

View File

@ -253,6 +253,9 @@ inline Polygons to_polygons(std::vector<Points> &&paths)
// Returns true if inside. Returns border_result if on boundary. // Returns true if inside. Returns border_result if on boundary.
bool contains(const Polygons& polygons, const Point& p, bool border_result = true); bool contains(const Polygons& polygons, const Point& p, bool border_result = true);
Polygon make_circle(double radius, double error);
Polygon make_circle_num_segments(double radius, size_t num_segments);
} // Slic3r } // Slic3r
// start Boost // start Boost

View File

@ -1066,12 +1066,8 @@ void TreeSupport::generateInitialAreas(
SupportGeneratorLayersPtr &top_interface_layers, SupportGeneratorLayersPtr &top_interface_layers,
SupportGeneratorLayerStorage &layer_storage) SupportGeneratorLayerStorage &layer_storage)
{ {
Polygon base_circle; static constexpr const auto base_radius = scaled<int>(0.01);
const auto base_radius = scaled<int>(0.01); const Polygon base_circle = make_circle(base_radius, SUPPORT_TREE_CIRCLE_RESOLUTION);
for (unsigned int i = 0; i < SUPPORT_TREE_CIRCLE_RESOLUTION; ++ i) {
const double angle = static_cast<double>(i) / SUPPORT_TREE_CIRCLE_RESOLUTION * (2.0 * M_PI);
base_circle.points.emplace_back(coord_t(cos(angle) * base_radius), coord_t(sin(angle) * base_radius));
}
TreeSupportMeshGroupSettings mesh_group_settings(print_object); TreeSupportMeshGroupSettings mesh_group_settings(print_object);
TreeSupportSettings mesh_config{ mesh_group_settings }; TreeSupportSettings mesh_config{ mesh_group_settings };
SupportParameters support_params(print_object); SupportParameters support_params(print_object);
@ -1117,7 +1113,7 @@ void TreeSupport::generateInitialAreas(
[this, &print_object, &overhangs, &mesh_config, &mesh_group_settings, &support_params, [this, &print_object, &overhangs, &mesh_config, &mesh_group_settings, &support_params,
z_distance_delta, min_xy_dist, force_tip_to_roof, roof_enabled, support_roof_layers, extra_outset, circle_length_to_half_linewidth_change, connect_length, max_overhang_insert_lag, z_distance_delta, min_xy_dist, force_tip_to_roof, roof_enabled, support_roof_layers, extra_outset, circle_length_to_half_linewidth_change, connect_length, max_overhang_insert_lag,
&base_circle, &mutex_layer_storage, &mutex_movebounds, &top_contacts, &layer_storage, &already_inserted, &base_circle, &mutex_layer_storage, &mutex_movebounds, &top_contacts, &layer_storage, &already_inserted,
&move_bounds, &base_radius](const tbb::blocked_range<size_t> &range) { &move_bounds](const tbb::blocked_range<size_t> &range) {
for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) { for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) {
if (overhangs[layer_idx + z_distance_delta].empty()) if (overhangs[layer_idx + z_distance_delta].empty())
continue; continue;
@ -2405,12 +2401,8 @@ void TreeSupport::generateBranchAreas(
constexpr int progress_report_steps = 10; constexpr int progress_report_steps = 10;
#endif // SLIC3R_TREESUPPORTS_PROGRESS #endif // SLIC3R_TREESUPPORTS_PROGRESS
Polygon branch_circle; // Pre-generate a circle with correct diameter so that we don't have to recompute those (co)sines every time. // Pre-generate a circle with correct diameter so that we don't have to recompute those (co)sines every time.
for (unsigned int i = 0; i < SUPPORT_TREE_CIRCLE_RESOLUTION; ++ i) { const Polygon branch_circle = make_circle(m_config.branch_radius, SUPPORT_TREE_CIRCLE_RESOLUTION);
const double angle = static_cast<double>(i) / SUPPORT_TREE_CIRCLE_RESOLUTION * (2.0 * M_PI);
branch_circle.points.emplace_back(coord_t(cos(angle) * m_config.branch_radius), coord_t(sin(angle) * m_config.branch_radius));
}
std::vector<Polygons> linear_inserts(linear_data.size()); std::vector<Polygons> linear_inserts(linear_data.size());
#ifdef SLIC3R_TREESUPPORTS_PROGRESS #ifdef SLIC3R_TREESUPPORTS_PROGRESS