bool GCode::needs_retraction(const Polyline &travel, ExtrusionRole role) { if (travel.length() < scale_(EXTRUDER_CONFIG(retract_before_travel))) { // skip retraction if the move is shorter than the configured threshold return false; } if (role == erSupportMaterial) { const SupportLayer* support_layer = dynamic_cast<const SupportLayer*>(this->layer); if (support_layer != NULL && support_layer->support_islands.contains(travel)) { // skip retraction if this is a travel move inside a support material island return false; } } if (this->config.only_retract_when_crossing_perimeters && this->layer != NULL) { if (this->config.fill_density.value > 0 && this->layer->any_internal_region_slice_contains(travel)) { /* skip retraction if travel is contained in an internal slice *and* internal infill is enabled (so that stringing is entirely not visible) */ return false; } else if (this->layer->any_bottom_region_slice_contains(travel) && this->layer->upper_layer != NULL && this->layer->upper_layer->slices.contains(travel) && (this->config.bottom_solid_layers.value >= 2 || this->config.fill_density.value > 0)) { /* skip retraction if travel is contained in an *infilled* bottom slice but only if it's also covered by an *infilled* upper layer's slice so that it's not visible from above (a bottom surface might not have an upper slice in case of a thin membrane) */ return false; } } // retract if only_retract_when_crossing_perimeters is disabled or doesn't apply return true; }
void MedialAxis::build(Polylines* polylines) { /* // build bounding box (we use it for clipping infinite segments) // --> we have no infinite segments this->bb = BoundingBox(this->lines); */ construct_voronoi(this->lines.begin(), this->lines.end(), &this->vd); /* // DEBUG: dump all Voronoi edges { for (VD::const_edge_iterator edge = this->vd.edges().begin(); edge != this->vd.edges().end(); ++edge) { if (edge->is_infinite()) continue; Polyline polyline; polyline.points.push_back(Point( edge->vertex0()->x(), edge->vertex0()->y() )); polyline.points.push_back(Point( edge->vertex1()->x(), edge->vertex1()->y() )); polylines->push_back(polyline); } return; } */ // collect valid edges (i.e. prune those not belonging to MAT) // note: this keeps twins, so it contains twice the number of the valid edges this->edges.clear(); for (VD::const_edge_iterator edge = this->vd.edges().begin(); edge != this->vd.edges().end(); ++edge) { // if we only process segments representing closed loops, none if the // infinite edges (if any) would be part of our MAT anyway if (edge->is_secondary() || edge->is_infinite()) continue; this->edges.insert(&*edge); } // count valid segments for each vertex std::map< const VD::vertex_type*,std::set<const VD::edge_type*> > vertex_edges; std::set<const VD::vertex_type*> entry_nodes; for (VD::const_vertex_iterator vertex = this->vd.vertices().begin(); vertex != this->vd.vertices().end(); ++vertex) { // get a reference to the list of valid edges originating from this vertex std::set<const VD::edge_type*>& edges = vertex_edges[&*vertex]; // get one random edge originating from this vertex const VD::edge_type* edge = vertex->incident_edge(); do { if (this->edges.count(edge) > 0) // only count valid edges edges.insert(edge); edge = edge->rot_next(); // next edge originating from this vertex } while (edge != vertex->incident_edge()); // if there's only one edge starting at this vertex then it's a leaf size_t edge_count = edges.size(); if (edge_count == 1) { entry_nodes.insert(&*vertex); } } // prune recursively while (!entry_nodes.empty()) { // get a random entry node const VD::vertex_type* v = *entry_nodes.begin(); // get edge starting from v assert(!vertex_edges[v].empty()); const VD::edge_type* edge = *vertex_edges[v].begin(); if (!this->is_valid_edge(*edge)) { // if edge is not valid, erase it from edge list (void)this->edges.erase(edge); (void)this->edges.erase(edge->twin()); // decrement edge counters for the affected nodes const VD::vertex_type* v1 = edge->vertex1(); (void)vertex_edges[v].erase(edge); (void)vertex_edges[v1].erase(edge->twin()); // also, check whether the end vertex is a new leaf if (vertex_edges[v1].size() == 1) { entry_nodes.insert(v1); } else if (vertex_edges[v1].empty()) { entry_nodes.erase(v1); } } // remove node from the set to prevent it from being visited again entry_nodes.erase(v); } // iterate through the valid edges to build polylines while (!this->edges.empty()) { const VD::edge_type& edge = **this->edges.begin(); // start a polyline Polyline polyline; polyline.points.push_back(Point( edge.vertex0()->x(), edge.vertex0()->y() )); polyline.points.push_back(Point( edge.vertex1()->x(), edge.vertex1()->y() )); // remove this edge and its twin from the available edges (void)this->edges.erase(&edge); (void)this->edges.erase(edge.twin()); // get next points this->process_edge_neighbors(edge, &polyline.points); // get previous points Points pp; this->process_edge_neighbors(*edge.twin(), &pp); polyline.points.insert(polyline.points.begin(), pp.rbegin(), pp.rend()); // append polyline to result if it's not too small if (polyline.length() > this->max_width) polylines->push_back(polyline); } }