Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2013-12-04 03:10:31 +0400
committerAlessandro Ranellucci <aar@cpan.org>2013-12-04 03:11:08 +0400
commite9b87b69df85e0693224afb40ebbbd0e24d3d710 (patch)
tree0cd8a02d3b82cc1d81b37c0f86f458e2bbde279c /xs/src/SurfaceCollection.cpp
parent57fd6ad5637430b8acbbbac2f874beb227203946 (diff)
Bugfix: segfault in SurfaceCollection->group(), fixed with a better implementation. #1566
Diffstat (limited to 'xs/src/SurfaceCollection.cpp')
-rw-r--r--xs/src/SurfaceCollection.cpp41
1 files changed, 19 insertions, 22 deletions
diff --git a/xs/src/SurfaceCollection.cpp b/xs/src/SurfaceCollection.cpp
index ce4995eae..fb63d3333 100644
--- a/xs/src/SurfaceCollection.cpp
+++ b/xs/src/SurfaceCollection.cpp
@@ -21,34 +21,31 @@ SurfaceCollection::simplify(double tolerance)
/* group surfaces by common properties */
void
-SurfaceCollection::group(std::vector<SurfacesPtr> &retval, bool merge_solid)
+SurfaceCollection::group(std::vector<SurfacesPtr> *retval, bool merge_solid)
{
- typedef std::map<t_surface_group_key,SurfacesPtr> t_unique_map;
- t_unique_map unique_map;
-
for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
- // build the t_surface_group_key struct with this surface's properties
- t_surface_group_key key;
- if (merge_solid && it->is_solid()) {
- key.surface_type = stTop;
- } else {
- key.surface_type = it->surface_type;
+ // find a group with the same properties
+ SurfacesPtr* group = NULL;
+ for (std::vector<SurfacesPtr>::iterator git = retval->begin(); git != retval->end(); ++git) {
+ Surface* gkey = git->front();
+ if ((gkey->surface_type == it->surface_type || (merge_solid && gkey->is_solid() && it->is_solid()))
+ && gkey->thickness == it->thickness
+ && gkey->thickness_layers == it->thickness_layers
+ && gkey->bridge_angle == it->bridge_angle) {
+ group = &*git;
+ break;
+ }
}
- key.thickness = it->thickness;
- key.thickness_layers = it->thickness_layers;
- key.bridge_angle = it->bridge_angle;
- // check whether we already have a group for these properties
- if (unique_map.find(key) == unique_map.end()) {
- // no group exists, add it
- unique_map[key] = SurfacesPtr();
+ // if no group with these properties exists, add one
+ if (group == NULL) {
+ retval->resize(retval->size() + 1);
+ group = &retval->back();
}
- unique_map[key].push_back(&*it);
+
+ // append surface to group
+ group->push_back(&*it);
}
-
- retval.reserve(unique_map.size());
- for (t_unique_map::const_iterator it = unique_map.begin(); it != unique_map.end(); ++it)
- retval.push_back(it->second);
}
}