diff --git a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp index 5d085f333b3..19d49c3e12f 100644 --- a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp +++ b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp @@ -542,7 +542,7 @@ void SkeletalTrapezoidation::generateToolpaths(std::vector & export_graph_to_svg(debug_out_path("ST-updateIsCentral-final-%d.svg", iRun), this->graph, this->outline); #endif - filterCentral(central_filter_dist); + filterCentral(central_filter_dist()); #ifdef ARACHNE_DEBUG export_graph_to_svg(debug_out_path("ST-filterCentral-final-%d.svg", iRun), this->graph, this->outline); @@ -729,7 +729,7 @@ void SkeletalTrapezoidation::filterNoncentralRegions() BOOST_LOG_TRIVIAL(warning) << "Encountered an uninitialized bead at the boundary!"; } assert(edge.to->data.bead_count >= 0 || edge.to->data.distance_to_boundary == 0); - constexpr coord_t max_dist = scaled(0.4); + const coord_t max_dist = scaled(0.4); filterNoncentralRegions(&edge, edge.to->data.bead_count, 0, max_dist); } } @@ -1303,6 +1303,7 @@ static inline Point normal(const Point& p0, coord_t len) void SkeletalTrapezoidation::applyTransitions(ptr_vector_t>& edge_transition_ends) { + const auto _snap_dist = snap_dist(); for (edge_t& edge : graph.edges) { if (edge.twin->data.hasTransitionEnds()) @@ -1348,7 +1349,7 @@ void SkeletalTrapezoidation::applyTransitions(ptr_vector_t ab_size - snap_dist) + if ((end_pos < _snap_dist || end_pos > ab_size - _snap_dist) && close_node->data.bead_count == new_node_bead_count ) { @@ -1390,6 +1391,7 @@ bool SkeletalTrapezoidation::isEndOfCentral(const edge_t& edge_to) const void SkeletalTrapezoidation::generateExtraRibs() { + const auto _snap_dist = snap_dist(); for (auto edge_it = graph.edges.begin(); edge_it != graph.edges.end(); ++edge_it) { edge_t& edge = *edge_it; @@ -1433,7 +1435,7 @@ void SkeletalTrapezoidation::generateExtraRibs() assert(end_pos > 0); assert(end_pos < ab_size); node_t* close_node = (end_pos < ab_size / 2)? from : to; - if ((end_pos < snap_dist || end_pos > ab_size - snap_dist) + if ((end_pos < _snap_dist || end_pos > ab_size - _snap_dist) && close_node->data.bead_count == new_node_bead_count ) { @@ -1593,6 +1595,7 @@ SkeletalTrapezoidation::edge_t* SkeletalTrapezoidation::getQuadMaxRedgeTo(edge_t void SkeletalTrapezoidation::propagateBeadingsUpward(std::vector& upward_quad_mids, ptr_vector_t& node_beadings) { + const auto _central_filter_dist = central_filter_dist(); for (auto upward_quad_mids_it = upward_quad_mids.rbegin(); upward_quad_mids_it != upward_quad_mids.rend(); ++upward_quad_mids_it) { edge_t* upward_edge = *upward_quad_mids_it; @@ -1609,7 +1612,7 @@ void SkeletalTrapezoidation::propagateBeadingsUpward(std::vector& upwar { // Only propagate to places where there is place continue; } - assert((upward_edge->from->data.distance_to_boundary != upward_edge->to->data.distance_to_boundary || shorter_then(upward_edge->to->p - upward_edge->from->p, central_filter_dist)) && "zero difference R edges should always be central"); + assert((upward_edge->from->data.distance_to_boundary != upward_edge->to->data.distance_to_boundary || shorter_then(upward_edge->to->p - upward_edge->from->p, _central_filter_dist)) && "zero difference R edges should always be central"); coord_t length = (upward_edge->to->p - upward_edge->from->p).cast().norm(); BeadingPropagation upper_beading = lower_beading; upper_beading.dist_to_bottom_source += length; @@ -1839,7 +1842,7 @@ std::shared_ptr SkeletalTrapezo { if (node->data.bead_count == -1) { // This bug is due to too small central edges - constexpr coord_t nearby_dist = scaled(0.1); + const coord_t nearby_dist = scaled(0.1); auto nearest_beading = getNearestBeading(node, nearby_dist); if (nearest_beading) { diff --git a/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp b/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp index 75ff9401559..ca8e13473f5 100644 --- a/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp +++ b/src/libslic3r/Arachne/SkeletalTrapezoidation.hpp @@ -65,8 +65,10 @@ class SkeletalTrapezoidation coord_t transition_filter_dist; //!< Filter transition mids (i.e. anchors) closer together than this coord_t allowed_filter_deviation; //!< The allowed line width deviation induced by filtering coord_t beading_propagation_transition_dist; //!< When there are different beadings propagated from below and from above, use this transitioning distance - static constexpr coord_t central_filter_dist = scaled(0.02); //!< Filter areas marked as 'central' smaller than this - static constexpr coord_t snap_dist = scaled(0.02); //!< Generic arithmatic inaccuracy. Only used to determine whether a transition really needs to insert an extra edge. + //!< Filter areas marked as 'central' smaller than this + inline coord_t central_filter_dist() { return scaled(0.02); } + //!< Generic arithmatic inaccuracy. Only used to determine whether a transition really needs to insert an extra edge. + inline coord_t snap_dist() { return scaled(0.02); } /*! * The strategy to use to fill a certain shape with lines. diff --git a/src/libslic3r/Arachne/WallToolPaths.cpp b/src/libslic3r/Arachne/WallToolPaths.cpp index bb01050c10e..20e9a4f5970 100644 --- a/src/libslic3r/Arachne/WallToolPaths.cpp +++ b/src/libslic3r/Arachne/WallToolPaths.cpp @@ -261,7 +261,7 @@ void fixSelfIntersections(const coord_t epsilon, Polygons &thiss) // Points too close to line segments should be moved a little away from those line segments, but less than epsilon, // so at least half-epsilon distance between points can still be guaranteed. - constexpr coord_t grid_size = scaled(2.); + const coord_t grid_size = scaled(2.); auto query_grid = createLocToLineGrid(thiss, grid_size); const auto move_dist = std::max(2L, half_epsilon - 2); @@ -473,11 +473,11 @@ const std::vector &WallToolPaths::generate() if (this->inset_count < 1) return toolpaths; - const coord_t smallest_segment = Slic3r::Arachne::meshfix_maximum_resolution; - const coord_t allowed_distance = Slic3r::Arachne::meshfix_maximum_deviation; + const coord_t smallest_segment = Slic3r::Arachne::meshfix_maximum_resolution(); + const coord_t allowed_distance = Slic3r::Arachne::meshfix_maximum_deviation(); const coord_t epsilon_offset = (allowed_distance / 2) - 1; const double transitioning_angle = Geometry::deg2rad(m_params.wall_transition_angle); - constexpr coord_t discretization_step_size = scaled(0.8); + const coord_t discretization_step_size = scaled(0.8); // Simplify outline for boost::voronoi consumption. Absolutely no self intersections or near-self intersections allowed: // TODO: Open question: Does this indeed fix all (or all-but-one-in-a-million) cases for manifold but otherwise possibly complex polygons? @@ -692,9 +692,9 @@ void WallToolPaths::simplifyToolPaths(std::vector &toolpaths { for (size_t toolpaths_idx = 0; toolpaths_idx < toolpaths.size(); ++toolpaths_idx) { - const int64_t maximum_resolution = Slic3r::Arachne::meshfix_maximum_resolution; - const int64_t maximum_deviation = Slic3r::Arachne::meshfix_maximum_deviation; - const int64_t maximum_extrusion_area_deviation = Slic3r::Arachne::meshfix_maximum_extrusion_area_deviation; // unit: μm² + const int64_t maximum_resolution = Slic3r::Arachne::meshfix_maximum_resolution(); + const int64_t maximum_deviation = Slic3r::Arachne::meshfix_maximum_deviation(); + const int64_t maximum_extrusion_area_deviation = Slic3r::Arachne::meshfix_maximum_extrusion_area_deviation(); // unit: μm² for (auto& line : toolpaths[toolpaths_idx]) { line.simplify(maximum_resolution * maximum_resolution, maximum_deviation * maximum_deviation, maximum_extrusion_area_deviation); diff --git a/src/libslic3r/Arachne/WallToolPaths.hpp b/src/libslic3r/Arachne/WallToolPaths.hpp index 09e2ae55088..457f7e71494 100644 --- a/src/libslic3r/Arachne/WallToolPaths.hpp +++ b/src/libslic3r/Arachne/WallToolPaths.hpp @@ -16,9 +16,9 @@ namespace Slic3r::Arachne { constexpr bool fill_outline_gaps = true; -constexpr coord_t meshfix_maximum_resolution = scaled(0.5); -constexpr coord_t meshfix_maximum_deviation = scaled(0.025); -constexpr coord_t meshfix_maximum_extrusion_area_deviation = scaled(2.); +inline coord_t meshfix_maximum_resolution() { return scaled(0.5); } +inline coord_t meshfix_maximum_deviation() { return scaled(0.025); } +inline coord_t meshfix_maximum_extrusion_area_deviation() { return scaled(2.); } class WallToolPathsParams { diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 926619dbf33..2a37967de58 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -211,6 +211,7 @@ set(lisbslic3r_sources Layer.hpp LayerRegion.cpp libslic3r.h + libslic3r.cpp Line.cpp Line.hpp BlacklistedLibraryCheck.cpp diff --git a/src/libslic3r/Fill/Lightning/Generator.cpp b/src/libslic3r/Fill/Lightning/Generator.cpp index 309b576e018..bf1142ee456 100644 --- a/src/libslic3r/Fill/Lightning/Generator.cpp +++ b/src/libslic3r/Fill/Lightning/Generator.cpp @@ -177,6 +177,7 @@ const Layer& Generator::getTreesForLayer(const size_t& layer_id) const void Generator::generateTrees(const PrintObject &print_object, const std::function &throw_on_cancel_callback) { + const auto _locator_cell_size = locator_cell_size(); m_lightning_layers.resize(print_object.layers().size()); bboxs.resize(print_object.layers().size()); std::vector infill_outlines(print_object.layers().size(), Polygons()); @@ -193,7 +194,7 @@ void Generator::generateTrees(const PrintObject &print_object, const std::functi // For various operations its beneficial to quickly locate nearby features on the polygon: const size_t top_layer_id = print_object.layers().size() - 1; EdgeGrid::Grid outlines_locator(get_extents(infill_outlines[top_layer_id]).inflated(SCALED_EPSILON)); - outlines_locator.create(infill_outlines[top_layer_id], locator_cell_size); + outlines_locator.create(infill_outlines[top_layer_id], _locator_cell_size); // For-each layer from top to bottom: for (int layer_id = int(top_layer_id); layer_id >= 0; layer_id--) { @@ -223,11 +224,11 @@ void Generator::generateTrees(const PrintObject &print_object, const std::functi below_outlines_bbox.merge(get_extents(current_lightning_layer.tree_roots).inflated(SCALED_EPSILON)); outlines_locator.set_bbox(below_outlines_bbox); - outlines_locator.create(below_outlines, locator_cell_size); + outlines_locator.create(below_outlines, _locator_cell_size); std::vector& lower_trees = m_lightning_layers[layer_id - 1].tree_roots; for (auto& tree : current_lightning_layer.tree_roots) - tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, locator_cell_size / 2); + tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, _locator_cell_size / 2); } } @@ -238,10 +239,11 @@ void Generator::generateTreesforSupport(std::vector& contours, const s m_lightning_layers.resize(contours.size()); bboxs.resize(contours.size()); + const auto _locator_cell_size = locator_cell_size(); // For various operations its beneficial to quickly locate nearby features on the polygon: const size_t top_layer_id = contours.size() - 1; EdgeGrid::Grid outlines_locator(get_extents(contours[top_layer_id]).inflated(SCALED_EPSILON)); - outlines_locator.create(contours[top_layer_id], locator_cell_size); + outlines_locator.create(contours[top_layer_id], _locator_cell_size); // For-each layer from top to bottom: for (int layer_id = int(top_layer_id); layer_id >= 0; layer_id--) { @@ -271,11 +273,11 @@ void Generator::generateTreesforSupport(std::vector& contours, const s below_outlines_bbox.merge(get_extents(current_lightning_layer.tree_roots).inflated(SCALED_EPSILON)); outlines_locator.set_bbox(below_outlines_bbox); - outlines_locator.create(below_outlines, locator_cell_size); + outlines_locator.create(below_outlines, _locator_cell_size); std::vector& lower_trees = m_lightning_layers[layer_id - 1].tree_roots; for (auto& tree : current_lightning_layer.tree_roots) - tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, locator_cell_size / 2); + tree->propagateToNextLayer(lower_trees, below_outlines, outlines_locator, m_prune_length, m_straightening_max_distance, _locator_cell_size / 2); } } diff --git a/src/libslic3r/Fill/Lightning/Layer.cpp b/src/libslic3r/Fill/Lightning/Layer.cpp index 354623e5191..4a30a95f457 100644 --- a/src/libslic3r/Fill/Lightning/Layer.cpp +++ b/src/libslic3r/Fill/Lightning/Layer.cpp @@ -29,7 +29,7 @@ Point GroundingLocation::p() const inline static Point to_grid_point(const Point &point, const BoundingBox &bbox) { - return (point - bbox.min) / locator_cell_size; + return (point - bbox.min) / locator_cell_size(); } void Layer::fillLocator(SparseNodeGrid &tree_node_locator, const BoundingBox& current_outlines_bbox) @@ -150,7 +150,7 @@ GroundingLocation Layer::getBestGroundingLocation coord_t current_dist = getWeightedDistance(node_location, unsupported_location); if (current_dist >= wall_supporting_radius) { // Only reconnect tree roots to other trees if they are not already close to the outlines. const coord_t search_radius = std::min(current_dist, within_dist); - BoundingBox region(unsupported_location - Point(search_radius, search_radius), unsupported_location + Point(search_radius + locator_cell_size, search_radius + locator_cell_size)); + BoundingBox region(unsupported_location - Point(search_radius, search_radius), unsupported_location + Point(search_radius + locator_cell_size(), search_radius + locator_cell_size())); region.min = to_grid_point(region.min, current_outlines_bbox); region.max = to_grid_point(region.max, current_outlines_bbox); diff --git a/src/libslic3r/Fill/Lightning/TreeNode.hpp b/src/libslic3r/Fill/Lightning/TreeNode.hpp index 8e0c029a958..14aa5e4888f 100644 --- a/src/libslic3r/Fill/Lightning/TreeNode.hpp +++ b/src/libslic3r/Fill/Lightning/TreeNode.hpp @@ -18,7 +18,7 @@ namespace Slic3r::FillLightning { -constexpr auto locator_cell_size = scaled(4.); +inline coord_t locator_cell_size() { return scaled(4.); } class Node; diff --git a/src/libslic3r/GCode/ConflictChecker.cpp b/src/libslic3r/GCode/ConflictChecker.cpp index 99661540946..012eed74590 100644 --- a/src/libslic3r/GCode/ConflictChecker.cpp +++ b/src/libslic3r/GCode/ConflictChecker.cpp @@ -13,9 +13,6 @@ namespace RasterizationImpl { using IndexPair = std::pair; using Grids = std::vector; -inline constexpr int64_t RasteXDistance = scale_(1); -inline constexpr int64_t RasteYDistance = scale_(1); - inline IndexPair point_map_grid_index(const Point &pt, int64_t xdist, int64_t ydist) { auto x = pt.x() / xdist; @@ -25,7 +22,7 @@ inline IndexPair point_map_grid_index(const Point &pt, int64_t xdist, int64_t yd inline bool nearly_equal(const Point &p1, const Point &p2) { return std::abs(p1.x() - p2.x()) < SCALED_EPSILON && std::abs(p1.y() - p2.y()) < SCALED_EPSILON; } -inline Grids line_rasterization(const Line &line, int64_t xdist = RasteXDistance, int64_t ydist = RasteYDistance) +inline Grids line_rasterization(const Line &line, int64_t xdist = scale_(1), int64_t ydist = scale_(1)) { Grids res; Point rayStart = line.a; diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index 69ac1824cca..224c2a8dafa 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -408,7 +408,7 @@ void LayerRegion::process_external_surfaces(const Layer *lower_layer, const Poly float expansion_bottom = expansion_top; float expansion_bottom_bridge = expansion_top; // Expand by waves of expansion_step size (expansion_step is scaled), but with no more steps than max_nr_expansion_steps. - static constexpr const float expansion_step = scaled(0.1); + const auto expansion_step = scaled(0.1); // Don't take more than max_nr_steps for small expansion_step. static constexpr const size_t max_nr_expansion_steps = 5; // Radius (with added epsilon) to absorb empty regions emering from regularization of ensuring, viz const float narrow_ensure_vertical_wall_thickness_region_radius = 0.5f * 0.65f * min_perimeter_infill_spacing; diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 78f3e69fa56..8cd6fc2b353 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -3151,7 +3151,7 @@ void PrintObject::clip_fill_surfaces() } // Merge the new overhangs, find new internal infill. polygons_append(upper_internal, std::move(overhangs)); - static constexpr const auto closing_radius = scaled(2.f); + const auto closing_radius = scaled(2.f); upper_internal = intersection( // Regularize the overhang regions, so that the infill areas will not become excessively jagged. smooth_outward( diff --git a/src/libslic3r/Support/TreeModelVolumes.hpp b/src/libslic3r/Support/TreeModelVolumes.hpp index 57ca9fae7ae..9234061b49c 100644 --- a/src/libslic3r/Support/TreeModelVolumes.hpp +++ b/src/libslic3r/Support/TreeModelVolumes.hpp @@ -34,8 +34,8 @@ namespace FFFTreeSupport { static constexpr const double SUPPORT_TREE_EXPONENTIAL_FACTOR = 1.5; -static constexpr const coord_t SUPPORT_TREE_EXPONENTIAL_THRESHOLD = scaled(1. * SUPPORT_TREE_EXPONENTIAL_FACTOR); -static constexpr const coord_t SUPPORT_TREE_COLLISION_RESOLUTION = scaled(0.5); +#define SUPPORT_TREE_EXPONENTIAL_THRESHOLD scaled(1. * SUPPORT_TREE_EXPONENTIAL_FACTOR) +#define SUPPORT_TREE_COLLISION_RESOLUTION scaled(0.5) static constexpr const bool SUPPORT_TREE_AVOID_SUPPORT_BLOCKER = true; class TreeModelVolumes diff --git a/src/libslic3r/Support/TreeSupport.cpp b/src/libslic3r/Support/TreeSupport.cpp index cbde8ba00b3..f52f1e218cb 100644 --- a/src/libslic3r/Support/TreeSupport.cpp +++ b/src/libslic3r/Support/TreeSupport.cpp @@ -474,7 +474,7 @@ static std::optional> polyline_sample_next_point_at_dis { const double dist2 = sqr(dist); const auto dist2i = int64_t(dist2); - static constexpr const auto eps = scaled(0.01); + const auto eps = scaled(0.01); for (size_t i = start_idx + 1; i < polyline.size(); ++ i) { const Point p1 = polyline[i]; @@ -836,6 +836,9 @@ class RichInterfacePlacer : public InterfacePlacer { { m_already_inserted.assign(num_support_layers, {}); this->min_xy_dist = this->config.xy_distance > this->config.xy_min_distance; + m_base_radius = scaled(0.01); + m_base_circle = Polygon{ make_circle(m_base_radius, SUPPORT_TREE_CIRCLE_RESOLUTION) }; + } const TreeModelVolumes &volumes; // Radius of the tree tip is large enough to be covered by an interface. @@ -971,8 +974,8 @@ class RichInterfacePlacer : public InterfacePlacer { std::vector &move_bounds; // Temps - static constexpr const auto m_base_radius = scaled(0.01); - const Polygon m_base_circle { make_circle(m_base_radius, SUPPORT_TREE_CIRCLE_RESOLUTION) }; + coord_t m_base_radius; + Polygon m_base_circle; // Mutexes, guards std::mutex m_mutex_movebounds; @@ -1567,6 +1570,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di current_elem.effective_radius_height += 1; coord_t radius = support_element_collision_radius(config, current_elem); + const auto _tiny_area_threshold = tiny_area_threshold(); if (settings.move) { increased = relevant_offset; if (overspeed > 0) { @@ -1587,7 +1591,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di if (mergelayer || current_elem.to_buildplate) { to_bp_data = safe_union(diff_clipped(increased, volumes.getAvoidance(radius, layer_idx - 1, settings.type, false, settings.use_min_distance))); - if (! current_elem.to_buildplate && area(to_bp_data) > tiny_area_threshold) { + if (! current_elem.to_buildplate && area(to_bp_data) > _tiny_area_threshold) { // mostly happening in the tip, but with merges one should check every time, just to be sure. current_elem.to_buildplate = true; // sometimes nodes that can reach the buildplate are marked as cant reach, tainting subtrees. This corrects it. BOOST_LOG_TRIVIAL(debug) << "Corrected taint leading to a wrong to model value on layer " << layer_idx - 1 << " targeting " << @@ -1599,7 +1603,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di to_model_data = safe_union(diff_clipped(increased, volumes.getAvoidance(radius, layer_idx - 1, settings.type, true, settings.use_min_distance))); if (!current_elem.to_model_gracious) { - if (mergelayer && area(to_model_data) >= tiny_area_threshold) { + if (mergelayer && area(to_model_data) >= _tiny_area_threshold) { current_elem.to_model_gracious = true; BOOST_LOG_TRIVIAL(debug) << "Corrected taint leading to a wrong non gracious value on layer " << layer_idx - 1 << " targeting " << current_elem.target_height << " with radius " << radius; @@ -1611,7 +1615,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di check_layer_data = current_elem.to_buildplate ? to_bp_data : to_model_data; - if (settings.increase_radius && area(check_layer_data) > tiny_area_threshold) { + if (settings.increase_radius && area(check_layer_data) > _tiny_area_threshold) { auto validWithRadius = [&](coord_t next_radius) { if (volumes.ceilRadius(next_radius, settings.use_min_distance) <= volumes.ceilRadius(radius, settings.use_min_distance)) return true; @@ -1627,7 +1631,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di volumes.getAvoidance(next_radius, layer_idx - 1, settings.type, true, settings.use_min_distance) : volumes.getCollision(next_radius, layer_idx - 1, settings.use_min_distance)); Polygons check_layer_data_2 = current_elem.to_buildplate ? to_bp_data_2 : to_model_data_2; - return area(check_layer_data_2) > tiny_area_threshold; + return area(check_layer_data_2) > _tiny_area_threshold; }; coord_t ceil_radius_before = volumes.ceilRadius(radius, settings.use_min_distance); @@ -1670,7 +1674,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di volumes.getCollision(radius, layer_idx - 1, settings.use_min_distance) )); check_layer_data = current_elem.to_buildplate ? to_bp_data : to_model_data; - if (area(check_layer_data) < tiny_area_threshold) { + if (area(check_layer_data) < _tiny_area_threshold) { BOOST_LOG_TRIVIAL(error) << "Lost area by doing catch up from " << ceil_radius_before << " to radius " << volumes.ceilRadius(support_element_collision_radius(config, current_elem), settings.use_min_distance); tree_supports_show_error("Area lost catching up radius. May not cause visible malformation."sv, true); @@ -1678,7 +1682,7 @@ static Point move_inside_if_outside(const Polygons &polygons, Point from, int di } } - return area(check_layer_data) > tiny_area_threshold ? std::optional(current_elem) : std::optional(); + return area(check_layer_data) > _tiny_area_threshold ? std::optional(current_elem) : std::optional(); } struct SupportElementInfluenceAreas { @@ -2147,13 +2151,14 @@ static bool merge_influence_areas_two_elements( merging_to_bp ? smaller_rad.areas.to_bp_areas : smaller_rad.areas.to_model_areas, merging_to_bp ? bigger_rad.areas.to_bp_areas : bigger_rad.areas.to_model_areas); + const auto _tiny_area_threshold = tiny_area_threshold(); // dont use empty as a line is not empty, but for this use-case it very well may be (and would be one layer down as union does not keep lines) // check if the overlap is large enough (Small ares tend to attract rounding errors in clipper). - if (area(intersect) <= tiny_area_threshold) + if (area(intersect) <= _tiny_area_threshold) return false; // While 0.025 was guessed as enough, i did not have reason to change it. - if (area(offset(intersect, scaled(-0.025), jtMiter, 1.2)) <= tiny_area_threshold) + if (area(offset(intersect, scaled(-0.025), jtMiter, 1.2)) <= _tiny_area_threshold) return false; #ifdef TREES_MERGE_RATHER_LATER @@ -2417,6 +2422,7 @@ static void create_layer_pathing(const TreeModelVolumes &volumes, const TreeSupp LayerIndex last_merge_layer_idx = move_bounds.size(); bool new_element = false; + const auto _tiny_area_threshold = tiny_area_threshold(); // Ensures at least one merge operation per 3mm height, 50 layers, 1 mm movement of slow speed or 5mm movement of fast speed (whatever is lowest). Values were guessed. size_t max_merge_every_x_layers = std::min(std::min(5000 / (std::max(config.maximum_move_distance, coord_t(100))), 1000 / std::max(config.maximum_move_distance_slow, coord_t(20))), 3000 / config.layer_height); @@ -2447,12 +2453,12 @@ static void create_layer_pathing(const TreeModelVolumes &volumes, const TreeSupp // Place already fully constructed elements to the output, remove them from influence_areas. SupportElements &this_layer = move_bounds[layer_idx - 1]; influence_areas.erase(std::remove_if(influence_areas.begin(), influence_areas.end(), - [&this_layer, layer_idx](SupportElementMerging &elem) { + [&this_layer, &_tiny_area_threshold, layer_idx](SupportElementMerging &elem) { if (elem.areas.influence_areas.empty()) // This area was removed completely due to collisions. return true; if (elem.areas.to_bp_areas.empty() && elem.areas.to_model_areas.empty()) { - if (area(elem.areas.influence_areas) < tiny_area_threshold) { + if (area(elem.areas.influence_areas) < _tiny_area_threshold) { BOOST_LOG_TRIVIAL(error) << "Insert Error of Influence area bypass on layer " << layer_idx - 1; tree_supports_show_error("Insert error of area after bypassing merge.\n"sv, true); } @@ -2485,7 +2491,7 @@ static void create_layer_pathing(const TreeModelVolumes &volumes, const TreeSupp for (SupportElementMerging &elem : influence_areas) if (! elem.areas.influence_areas.empty()) { Polygons new_area = safe_union(elem.areas.influence_areas); - if (area(new_area) < tiny_area_threshold) { + if (area(new_area) < _tiny_area_threshold) { BOOST_LOG_TRIVIAL(error) << "Insert Error of Influence area on layer " << layer_idx - 1 << ". Origin of " << elem.parents.size() << " areas. Was to bp " << elem.state.to_buildplate; tree_supports_show_error("Insert error of area after merge.\n"sv, true); } @@ -3050,6 +3056,7 @@ static void drop_non_gracious_areas( std::vector &support_layer_storage, std::function throw_on_cancel) { + const auto _tiny_area_threshold = tiny_area_threshold(); std::vector>> dropped_down_areas(linear_data.size()); tbb::parallel_for(tbb::blocked_range(0, linear_data.size()), [&](const tbb::blocked_range &range) { @@ -3058,7 +3065,7 @@ static void drop_non_gracious_areas( if (const DrawArea &draw_element = linear_data[idx]; ! draw_element.element->state.to_model_gracious && draw_element.child_element == nullptr) { Polygons rest_support; const LayerIndex layer_idx_first = draw_element.element->state.layer_idx - 1; - for (LayerIndex layer_idx = layer_idx_first; area(rest_support) > tiny_area_threshold && layer_idx >= 0; -- layer_idx) { + for (LayerIndex layer_idx = layer_idx_first; area(rest_support) > _tiny_area_threshold && layer_idx >= 0; -- layer_idx) { rest_support = diff_clipped(layer_idx == layer_idx_first ? draw_element.polygons : rest_support, volumes.getCollision(0, layer_idx, false)); dropped_down_areas[idx].emplace_back(layer_idx, rest_support); } diff --git a/src/libslic3r/Support/TreeSupport3D.cpp b/src/libslic3r/Support/TreeSupport3D.cpp index 434036e5000..ba3b1810ce9 100644 --- a/src/libslic3r/Support/TreeSupport3D.cpp +++ b/src/libslic3r/Support/TreeSupport3D.cpp @@ -133,7 +133,7 @@ static inline void check_self_intersections(const ExPolygon &expoly, const std:: #endif // TREE_SUPPORT_SHOW_ERRORS_WIN32 } -static constexpr const auto tiny_area_threshold = sqr(scaled(0.001)); +// static constexpr const auto tiny_area_threshold = sqr(scaled(0.001)); static std::vector>> group_meshes(const Print &print, const std::vector &print_object_ids) { diff --git a/src/libslic3r/Support/TreeSupportCommon.hpp b/src/libslic3r/Support/TreeSupportCommon.hpp index 52cfe485222..0f14c96e20b 100644 --- a/src/libslic3r/Support/TreeSupportCommon.hpp +++ b/src/libslic3r/Support/TreeSupportCommon.hpp @@ -452,7 +452,7 @@ struct TreeSupportSettings static constexpr const bool polygons_strictly_simple = false; -static constexpr const auto tiny_area_threshold = sqr(scaled(0.001)); +inline double tiny_area_threshold() { return sqr(scaled(0.001)); } void tree_supports_show_error(std::string_view message, bool critical); diff --git a/src/libslic3r/TriangleMeshSlicer.cpp b/src/libslic3r/TriangleMeshSlicer.cpp index acd36d78058..07a685184b2 100644 --- a/src/libslic3r/TriangleMeshSlicer.cpp +++ b/src/libslic3r/TriangleMeshSlicer.cpp @@ -1832,7 +1832,7 @@ static void make_expolygons(const Polygons &loops, const float closing_radius, c static inline Transform3f make_trafo_for_slicing(const Transform3d &trafo) { auto t = trafo; - static constexpr const double s = 1. / SCALING_FACTOR; + const double s = 1. / SCALING_FACTOR; t.prescale(Vec3d(s, s, 1.)); return t.cast(); } @@ -1846,7 +1846,7 @@ static std::vector transform_mesh_vertices_for_slicing(const indexed { // Copy and scale vertices in XY, don't scale in Z. // Possibly apply the transformation. - static constexpr const double s = 1. / SCALING_FACTOR; + const double s = 1. / SCALING_FACTOR; std::vector out(mesh.vertices); if (is_identity(trafo)) { // Identity. diff --git a/src/libslic3r/libslic3r.cpp b/src/libslic3r/libslic3r.cpp new file mode 100644 index 00000000000..e94d99dcd0c --- /dev/null +++ b/src/libslic3r/libslic3r.cpp @@ -0,0 +1,3 @@ +#include "libslic3r.h" + +double SCALING_FACTOR = SCALING_FACTOR_INTERNAL; diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index e95222f5020..3e71ada5ab0 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -55,7 +55,13 @@ static constexpr double EPSILON = 1e-4; // 0..4294mm with 1nm resolution // int32_t fits an interval of (-2147.48mm, +2147.48mm) // with int64_t we don't have to worry anymore about the size of the int. -static constexpr double SCALING_FACTOR = 0.000001; + +// Orca todo: might be better to use 1e-5 for all, namometer resolution is not needed for 3D printing +static constexpr double SCALING_FACTOR_INTERNAL = 0.000001; +static constexpr double SCALING_FACTOR_INTERNAL_LARGE_PRINTER = 0.00001; +static constexpr double LARGE_BED_THRESHOLD = 2147; + +extern double SCALING_FACTOR; // for creating circles (for brim_ear) #define POLY_SIDES 24 static constexpr double PI = 3.141592653589793238; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index db6a7f2f2d0..95129dfcd91 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -84,9 +84,9 @@ wxString last_used_directory = wxEmptyString; /// File path to svg std::string choose_svg_file(); -constexpr double get_tesselation_tolerance(double scale){ - constexpr double tesselation_tolerance_in_mm = .1; //8e-2; - constexpr double tesselation_tolerance_scaled = (tesselation_tolerance_in_mm*tesselation_tolerance_in_mm) / SCALING_FACTOR / SCALING_FACTOR; +double get_tesselation_tolerance(double scale){ + double tesselation_tolerance_in_mm = .1; //8e-2; + double tesselation_tolerance_scaled = (tesselation_tolerance_in_mm*tesselation_tolerance_in_mm) / SCALING_FACTOR / SCALING_FACTOR; return tesselation_tolerance_scaled / scale / scale; } diff --git a/src/slic3r/GUI/IMSlider.cpp b/src/slic3r/GUI/IMSlider.cpp index 1320e28084c..a0f15066b11 100644 --- a/src/slic3r/GUI/IMSlider.cpp +++ b/src/slic3r/GUI/IMSlider.cpp @@ -11,8 +11,10 @@ namespace Slic3r { namespace GUI { -constexpr double min_delta_area = scale_(scale_(25)); // equal to 25 mm2 -constexpr double miscalculation = scale_(scale_(1)); // equal to 1 mm2 +// equal to 25 mm2 +inline double min_delta_area() { return scale_(scale_(25)); } +// equal to 1 mm2 +inline double miscalculation() { return scale_(scale_(1)); } static const float LEFT_MARGIN = 13.0f + 100.0f; // avoid thumbnail toolbar static const float HORIZONTAL_SLIDER_WINDOW_HEIGHT = 64.0f; @@ -33,7 +35,7 @@ static ImVec4 m_tick_rect; bool equivalent_areas(const double& bottom_area, const double& top_area) { - return fabs(bottom_area - top_area) <= miscalculation; + return fabs(bottom_area - top_area) <= miscalculation(); } bool check_color_change(PrintObject *object, size_t frst_layer_id, size_t layers_cnt, bool check_overhangs, std::function break_condition) @@ -50,7 +52,7 @@ bool check_color_change(PrintObject *object, size_t frst_layer_id, size_t layers // Check percent of the area decrease. // This value have to be more than min_delta_area and more then 10% - if ((prev_area - cur_area > min_delta_area) && (cur_area / prev_area < 0.9)) { + if ((prev_area - cur_area > min_delta_area()) && (cur_area / prev_area < 0.9)) { detected = true; if (break_condition(layer)) break; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f812ae2b069..39f135c1083 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7972,6 +7972,13 @@ bool Plater::priv::show_publish_dlg(bool show) //BBS: add bed exclude area void Plater::priv::set_bed_shape(const Pointfs& shape, const Pointfs& exclude_areas, const double printable_height, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom) { + //Orca: reduce resolution for large bed printer + BoundingBoxf bed_size = get_extents(shape); + if (bed_size.size().maxCoeff() <= LARGE_BED_THRESHOLD) + SCALING_FACTOR = SCALING_FACTOR_INTERNAL; + else + SCALING_FACTOR = SCALING_FACTOR_INTERNAL_LARGE_PRINTER; + //BBS: add shape position Vec2d shape_position = partplate_list.get_current_shape_position(); bool new_shape = bed.set_shape(shape, printable_height, custom_model, force_as_custom, shape_position);