ENH: improve tree support

1. add a hook inside tree branches for improved strength
2. fix the issue that interface may fly as a mess (delete the logic
  where gap nodes can skip dropping down)
3. fix the issue that base nodes may fly as a mess (smoothing should
  skip polygon nodes, see Jira:STUDIO-4403)

Change-Id: Ie9f2039813c2ca3127ed8913304cc455fec8e7ee
(cherry picked from commit 83cef5f91d49ff3d275a89ec3df8b5f0fd573f8c)
This commit is contained in:
arthur 2023-09-23 16:31:49 +08:00 committed by Lane.Wei
parent a62bf3b838
commit 76f876a3c6
9 changed files with 476 additions and 330 deletions

View file

@ -11,6 +11,8 @@
#include "Flow.hpp"
#include "PrintConfig.hpp"
#include "Fill/Lightning/Generator.hpp"
#include "TreeModelVolumes.hpp"
#include "TreeSupport3D.hpp"
#ifndef SQ
#define SQ(x) ((x)*(x))
@ -244,7 +246,6 @@ public:
, position(Point(0, 0))
, obj_layer_nr(0)
, support_roof_layers_below(0)
, support_floor_layers_above(0)
, to_buildplate(true)
, parent(nullptr)
, print_z(0.0)
@ -258,7 +259,6 @@ public:
, position(position)
, obj_layer_nr(obj_layer_nr)
, support_roof_layers_below(support_roof_layers_below)
, support_floor_layers_above(0)
, to_buildplate(to_buildplate)
, parent(parent)
, print_z(print_z_)
@ -266,13 +266,16 @@ public:
, dist_mm_to_top(dist_mm_to_top_)
{
if (parent) {
parents.push_back(parent);
type = parent->type;
overhang = parent->overhang;
if (dist_mm_to_top==0)
dist_mm_to_top = parent->dist_mm_to_top + parent->height;
parent->child = this;
for (auto& neighbor : parent->merged_neighbours)
for (auto& neighbor : parent->merged_neighbours) {
neighbor->child = this;
parents.push_back(neighbor);
}
}
}
@ -299,10 +302,10 @@ public:
mutable double radius = 0.0;
mutable double max_move_dist = 0.0;
NodeType type = eCircle;
bool is_merged = false; // this node is generated by merging upper nodes
bool is_corner = false;
bool is_processed = false;
const ExPolygon *overhang = nullptr; // when type==ePolygon, set this value to get original overhang area
bool need_extra_wall = false;
ExPolygon overhang; // when type==ePolygon, set this value to get original overhang area
/*!
* \brief The direction of the skin lines above the tip of the branch.
@ -321,7 +324,6 @@ public:
* how far we need to extend that support roof downwards.
*/
int support_roof_layers_below;
int support_floor_layers_above;
int obj_layer_nr;
/*!
@ -341,6 +343,7 @@ public:
* the entire branch needs to be known.
*/
Node *parent;
std::vector<Node*> parents;
Node *child = nullptr;
/*!
@ -387,6 +390,7 @@ public:
InfillPattern interface_fill_pattern;
InfillPattern contact_fill_pattern;
bool with_sheath;
bool independent_layer_height = false;
const double thresh_big_overhang = SQ(scale_(10));
};
@ -417,6 +421,7 @@ private:
* \warning This class is NOT currently thread-safe and should not be accessed in OpenMP blocks
*/
std::shared_ptr<TreeSupportData> m_ts_data;
std::unique_ptr<TreeSupport3D::TreeModelVolumes> m_model_volumes;
PrintObject *m_object;
const PrintObjectConfig* m_object_config;
SlicingParameters m_slicing_params;
@ -431,6 +436,7 @@ private:
coordf_t MAX_BRANCH_RADIUS_FIRST_LAYER = 12.0;
coordf_t MIN_BRANCH_RADIUS = 0.5;
float tree_support_branch_diameter_angle = 5.0;
coord_t m_min_radius = scale_(1); // in mm
bool is_strong = false;
bool is_slim = false;
bool with_infill = false;
@ -465,7 +471,7 @@ private:
void smooth_nodes(std::vector<std::vector<Node *>> &contact_nodes);
void adjust_layer_heights(std::vector<std::vector<Node*>>& contact_nodes);
void smooth_nodes(std::vector<std::vector<Node*>>& contact_nodes, const TreeSupport3D::TreeSupportSettings& config);
/*! BBS: MusangKing: maximum layer height
* \brief Optimize the generation of tree support by pre-planning the layer_heights
@ -486,7 +492,7 @@ private:
* \return For each layer, a list of points where the tree should connect
* with the model.
*/
void generate_contact_points(std::vector<std::vector<Node*>>& contact_nodes);
void generate_contact_points(std::vector<std::vector<Node*>>& contact_nodes, const std::vector<TreeSupport3D::SupportElements>& move_bounds);
/*!
* \brief Add a node to the next layer.
@ -500,7 +506,11 @@ private:
Polygons contact_nodes_to_polygon(const std::vector<Node*>& contact_nodes, Polygons layer_contours, int layer_nr, std::vector<double>& radiis, std::vector<bool>& is_interface);
void clear_contact_nodes(std::vector<std::vector<Node*>>& contact_nodes);
coordf_t calc_branch_radius(coordf_t base_radius, size_t layers_to_top, size_t tip_layers, double diameter_angle_scale_factor);
coordf_t calc_branch_radius(coordf_t base_radius, coordf_t mm_to_top, double diameter_angle_scale_factor);
coordf_t calc_branch_radius(coordf_t base_radius, coordf_t mm_to_top, double diameter_angle_scale_factor, bool use_min_distance=true);
ExPolygons get_avoidance(coordf_t radius, size_t obj_layer_nr);
ExPolygons get_collision(coordf_t radius, size_t layer_nr);
// get Polygons instead of ExPolygons
Polygons get_collision_polys(coordf_t radius, size_t layer_nr);
// similar to SupportMaterial::trim_support_layers_by_object
Polygons get_trim_support_regions(