FIX: fix two tree support bugs
1. hybrid(auto) on_buildplate_only option not working correctly because parent is not set. 2. tree(auto) on_buildplate_only not working correctly because unsupported branch isn't deleted completely. I add child to track the dangling nodes and then delete nodes with no child. Change-Id: I24c69a7cf400d2961b22a720a6069cf95db6c1a5 (cherry picked from commit bce77c16128d35c668b175e7135b9fe9acd71d13)
This commit is contained in:
parent
c37f489f35
commit
c9e8ef3f93
|
@ -2,6 +2,8 @@
|
|||
#define FIRSTFIT_HPP
|
||||
|
||||
#include "selection_boilerplate.hpp"
|
||||
// for writing SVG
|
||||
//#include "../tools/svgtools.hpp"
|
||||
|
||||
namespace libnest2d { namespace selections {
|
||||
|
||||
|
@ -60,14 +62,11 @@ public:
|
|||
pconfig.m_excluded_items.emplace_back(itm);
|
||||
});
|
||||
|
||||
// If the packed_items array is not empty we have to create as many
|
||||
// placers as there are elements in packed bins and preload each item
|
||||
// into the appropriate placer
|
||||
//for(ItemGroup& ig : fixed_bins) {
|
||||
// placers.emplace_back(bin);
|
||||
// placers.back().configure(pconfig);
|
||||
// placers.back().preload(ig);
|
||||
//}
|
||||
#ifdef SVGTOOLS_HPP
|
||||
svg::SVGWriter<RawShape> svgwriter;
|
||||
std::for_each(first, last, [this,&svgwriter](Item &itm) { svgwriter.writeShape(itm, "none", "blue"); });
|
||||
svgwriter.save(boost::filesystem::path("SVG") / "all_items.svg");
|
||||
#endif
|
||||
|
||||
std::function<bool(Item& i1, Item& i2)> sortfunc;
|
||||
if (pconfig.sortfunc)
|
||||
|
|
|
@ -2271,11 +2271,9 @@ void TreeSupport::drop_nodes(std::vector<std::vector<Node*>>& contact_nodes)
|
|||
for (Node* p_node : layer_contact_nodes)
|
||||
{
|
||||
if (p_node->type == ePolygon) {
|
||||
Node* next_node = new Node(*p_node);
|
||||
next_node->distance_to_top++;
|
||||
next_node->support_roof_layers_below--;
|
||||
next_node->print_z -= m_object->get_layer(layer_nr)->height;
|
||||
next_node->to_buildplate = !is_inside_ex(m_ts_data->m_layer_outlines[layer_nr], next_node->position);
|
||||
const bool to_buildplate = !is_inside_ex(m_ts_data->m_layer_outlines[layer_nr], p_node->position);
|
||||
Node * next_node = new Node(p_node->position, p_node->distance_to_top + 1, p_node->skin_direction, p_node->support_roof_layers_below - 1, to_buildplate, p_node,
|
||||
m_object->get_layer(layer_nr - 1)->print_z, m_object->get_layer(layer_nr - 1)->height);
|
||||
contact_nodes[layer_nr - 1].emplace_back(next_node);
|
||||
}
|
||||
}
|
||||
|
@ -2607,6 +2605,20 @@ void TreeSupport::drop_nodes(std::vector<std::vector<Node*>>& contact_nodes)
|
|||
}
|
||||
}
|
||||
|
||||
// delete nodes with no children (means either it's a single layer nodes, or the branch has been deleted but not completely)
|
||||
for (size_t layer_nr = contact_nodes.size() - 1; layer_nr > 0; layer_nr--){
|
||||
auto layer_contact_nodes = contact_nodes[layer_nr];
|
||||
for (Node *p_node : layer_contact_nodes) {
|
||||
if (p_node->child==nullptr) {
|
||||
std::vector<Node *>::iterator to_erase = std::find(contact_nodes[layer_nr].begin(), contact_nodes[layer_nr].end(), p_node);
|
||||
if (to_erase != contact_nodes[layer_nr].end()) {
|
||||
to_free_node_set.insert(*to_erase);
|
||||
contact_nodes[layer_nr].erase(to_erase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << "after m_avoidance_cache.size()=" << m_ts_data->m_avoidance_cache.size();
|
||||
|
||||
for (Node *node : to_free_node_set)
|
||||
|
|
|
@ -222,7 +222,7 @@ public:
|
|||
, height(0.0)
|
||||
{}
|
||||
|
||||
Node(const Point position, const size_t distance_to_top, const bool skin_direction, const int support_roof_layers_below, const bool to_buildplate, Node* const parent,
|
||||
Node(const Point position, const size_t distance_to_top, const bool skin_direction, const int support_roof_layers_below, const bool to_buildplate, Node* parent,
|
||||
coordf_t print_z_, coordf_t height_)
|
||||
: distance_to_top(distance_to_top)
|
||||
, position(position)
|
||||
|
@ -233,7 +233,13 @@ public:
|
|||
, parent(parent)
|
||||
, print_z(print_z_)
|
||||
, height(height_)
|
||||
{}
|
||||
{
|
||||
if (parent) {
|
||||
type = parent->type;
|
||||
overhang = parent->overhang;
|
||||
parent->child = this;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG // Clear the delete node's data so if there's invalid access after, we may get a clue by inspecting that node.
|
||||
~Node()
|
||||
|
@ -294,6 +300,7 @@ public:
|
|||
* the entire branch needs to be known.
|
||||
*/
|
||||
Node *parent;
|
||||
Node *child = nullptr;
|
||||
|
||||
/*!
|
||||
* \brief All neighbours (on the same layer) that where merged into this node.
|
||||
|
|
Loading…
Reference in New Issue