Fixed wrong refactoring of perimeter tree traversal. #1832
This commit is contained in:
parent
b71d28bd5a
commit
52de292a48
@ -233,7 +233,7 @@ sub make_perimeters {
|
|||||||
|
|
||||||
# use a nearest neighbor search to order these children
|
# use a nearest neighbor search to order these children
|
||||||
# TODO: supply second argument to chained_path() too?
|
# TODO: supply second argument to chained_path() too?
|
||||||
my $sorted_collection = $collection->chained_path(0);
|
my $sorted_collection = $collection->chained_path_indices(0);
|
||||||
my @orig_indices = @{$sorted_collection->orig_indices};
|
my @orig_indices = @{$sorted_collection->orig_indices};
|
||||||
|
|
||||||
my @loops = ();
|
my @loops = ();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "ExtrusionEntityCollection.hpp"
|
#include "ExtrusionEntityCollection.hpp"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
@ -34,25 +35,30 @@ ExtrusionEntityCollection::last_point() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
ExtrusionEntityCollection*
|
ExtrusionEntityCollection*
|
||||||
ExtrusionEntityCollection::chained_path(bool no_reverse) const
|
ExtrusionEntityCollection::chained_path(bool no_reverse, std::vector<size_t>* orig_indices) const
|
||||||
{
|
{
|
||||||
if (this->entities.empty()) {
|
if (this->entities.empty()) {
|
||||||
return new ExtrusionEntityCollection ();
|
return new ExtrusionEntityCollection ();
|
||||||
}
|
}
|
||||||
return this->chained_path_from(this->entities.front()->first_point(), no_reverse);
|
return this->chained_path_from(this->entities.front()->first_point(), no_reverse, orig_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtrusionEntityCollection*
|
ExtrusionEntityCollection*
|
||||||
ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse) const
|
ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse, std::vector<size_t>* orig_indices) const
|
||||||
{
|
{
|
||||||
if (this->no_sort) return this->clone();
|
if (this->no_sort) return this->clone();
|
||||||
ExtrusionEntityCollection* retval = new ExtrusionEntityCollection;
|
ExtrusionEntityCollection* retval = new ExtrusionEntityCollection;
|
||||||
retval->entities.reserve(this->entities.size());
|
retval->entities.reserve(this->entities.size());
|
||||||
retval->orig_indices.reserve(this->entities.size());
|
retval->orig_indices.reserve(this->entities.size());
|
||||||
|
|
||||||
|
// if we're asked to return the original indices, build a map
|
||||||
|
std::map<ExtrusionEntity*,size_t> indices_map;
|
||||||
|
|
||||||
ExtrusionEntitiesPtr my_paths;
|
ExtrusionEntitiesPtr my_paths;
|
||||||
for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
|
for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
|
||||||
my_paths.push_back((*it)->clone());
|
ExtrusionEntity* entity = (*it)->clone();
|
||||||
|
my_paths.push_back(entity);
|
||||||
|
if (orig_indices != NULL) indices_map[entity] = it - this->entities.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
Points endpoints;
|
Points endpoints;
|
||||||
@ -69,11 +75,12 @@ ExtrusionEntityCollection::chained_path_from(Point* start_near, bool no_reverse)
|
|||||||
// find nearest point
|
// find nearest point
|
||||||
int start_index = start_near->nearest_point_index(endpoints);
|
int start_index = start_near->nearest_point_index(endpoints);
|
||||||
int path_index = start_index/2;
|
int path_index = start_index/2;
|
||||||
|
ExtrusionEntity* entity = my_paths.at(path_index);
|
||||||
if (start_index % 2 && !no_reverse) {
|
if (start_index % 2 && !no_reverse) {
|
||||||
my_paths.at(path_index)->reverse();
|
entity->reverse();
|
||||||
}
|
}
|
||||||
retval->entities.push_back(my_paths.at(path_index));
|
retval->entities.push_back(my_paths.at(path_index));
|
||||||
retval->orig_indices.push_back(path_index);
|
if (orig_indices != NULL) orig_indices->push_back(indices_map[entity]);
|
||||||
my_paths.erase(my_paths.begin() + path_index);
|
my_paths.erase(my_paths.begin() + path_index);
|
||||||
endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
|
endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
|
||||||
start_near = retval->entities.back()->last_point();
|
start_near = retval->entities.back()->last_point();
|
||||||
|
@ -11,11 +11,11 @@ class ExtrusionEntityCollection : public ExtrusionEntity
|
|||||||
public:
|
public:
|
||||||
ExtrusionEntityCollection* clone() const;
|
ExtrusionEntityCollection* clone() const;
|
||||||
ExtrusionEntitiesPtr entities;
|
ExtrusionEntitiesPtr entities;
|
||||||
std::vector<int> orig_indices;
|
std::vector<size_t> orig_indices; // handy for XS
|
||||||
bool no_sort;
|
bool no_sort;
|
||||||
ExtrusionEntityCollection(): no_sort(false) {};
|
ExtrusionEntityCollection(): no_sort(false) {};
|
||||||
ExtrusionEntityCollection* chained_path(bool no_reverse) const;
|
ExtrusionEntityCollection* chained_path(bool no_reverse, std::vector<size_t>* orig_indices = NULL) const;
|
||||||
ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse) const;
|
ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse, std::vector<size_t>* orig_indices = NULL) const;
|
||||||
void reverse();
|
void reverse();
|
||||||
Point* first_point() const;
|
Point* first_point() const;
|
||||||
Point* last_point() const;
|
Point* last_point() const;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
|
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %};
|
||||||
int count()
|
int count()
|
||||||
%code{% RETVAL = THIS->entities.size(); %};
|
%code{% RETVAL = THIS->entities.size(); %};
|
||||||
std::vector<int> orig_indices()
|
std::vector<size_t> orig_indices()
|
||||||
%code{% RETVAL = THIS->orig_indices; %};
|
%code{% RETVAL = THIS->orig_indices; %};
|
||||||
%{
|
%{
|
||||||
|
|
||||||
@ -79,5 +79,16 @@ ExtrusionEntityCollection::no_sort(...)
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
ExtrusionEntityCollection*
|
||||||
|
ExtrusionEntityCollection::chained_path_indices(bool no_reverse)
|
||||||
|
PREINIT:
|
||||||
|
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
|
||||||
|
CODE:
|
||||||
|
std::vector<size_t> indices;
|
||||||
|
RETVAL = THIS->chained_path(no_reverse, &indices);
|
||||||
|
RETVAL->orig_indices = indices;
|
||||||
|
OUTPUT:
|
||||||
|
RETVAL
|
||||||
|
|
||||||
%}
|
%}
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
std::vector<Points::size_type> T_STD_VECTOR_INT
|
std::vector<Points::size_type> T_STD_VECTOR_INT
|
||||||
|
std::vector<size_t> T_STD_VECTOR_INT
|
||||||
t_config_option_key T_STD_STRING
|
t_config_option_key T_STD_STRING
|
||||||
|
|
||||||
BoundingBox* O_OBJECT
|
BoundingBox* O_OBJECT
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
%typemap{std::string};
|
%typemap{std::string};
|
||||||
%typemap{t_config_option_key};
|
%typemap{t_config_option_key};
|
||||||
%typemap{std::vector<int>};
|
%typemap{std::vector<int>};
|
||||||
|
%typemap{std::vector<size_t>};
|
||||||
%typemap{std::vector<unsigned int>*};
|
%typemap{std::vector<unsigned int>*};
|
||||||
%typemap{std::vector<double>};
|
%typemap{std::vector<double>};
|
||||||
%typemap{std::vector<double>*};
|
%typemap{std::vector<double>*};
|
||||||
|
Loading…
Reference in New Issue
Block a user