~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/src/SurfaceCollection.cpp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "SurfaceCollection.hpp"
 
2
#include <map>
 
3
 
 
4
namespace Slic3r {
 
5
 
 
6
void
 
7
SurfaceCollection::simplify(double tolerance)
 
8
{
 
9
    Surfaces ss;
 
10
    for (Surfaces::const_iterator it_s = this->surfaces.begin(); it_s != this->surfaces.end(); ++it_s) {
 
11
        ExPolygons expp;
 
12
        it_s->expolygon.simplify(tolerance, expp);
 
13
        for (ExPolygons::const_iterator it_e = expp.begin(); it_e != expp.end(); ++it_e) {
 
14
            Surface s = *it_s;
 
15
            s.expolygon = *it_e;
 
16
            ss.push_back(s);
 
17
        }
 
18
    }
 
19
    this->surfaces = ss;
 
20
}
 
21
 
 
22
/* group surfaces by common properties */
 
23
void
 
24
SurfaceCollection::group(std::vector<SurfacesPtr> *retval)
 
25
{
 
26
    for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
 
27
        // find a group with the same properties
 
28
        SurfacesPtr* group = NULL;
 
29
        for (std::vector<SurfacesPtr>::iterator git = retval->begin(); git != retval->end(); ++git) {
 
30
            Surface* gkey = git->front();
 
31
            if (   gkey->surface_type      == it->surface_type
 
32
                && gkey->thickness         == it->thickness
 
33
                && gkey->thickness_layers  == it->thickness_layers
 
34
                && gkey->bridge_angle      == it->bridge_angle) {
 
35
                group = &*git;
 
36
                break;
 
37
            }
 
38
        }
 
39
        
 
40
        // if no group with these properties exists, add one
 
41
        if (group == NULL) {
 
42
            retval->resize(retval->size() + 1);
 
43
            group = &retval->back();
 
44
        }
 
45
        
 
46
        // append surface to group
 
47
        group->push_back(&*it);
 
48
    }
 
49
}
 
50
 
 
51
#ifdef SLIC3RXS
 
52
REGISTER_CLASS(SurfaceCollection, "Surface::Collection");
 
53
#endif
 
54
 
 
55
}