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

« back to all changes in this revision

Viewing changes to xs/src/ExPolygon.hpp

  • 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
#ifndef slic3r_ExPolygon_hpp_
 
2
#define slic3r_ExPolygon_hpp_
 
3
 
 
4
#include "Polygon.hpp"
 
5
#include <vector>
 
6
 
 
7
namespace Slic3r {
 
8
 
 
9
class ExPolygon;
 
10
typedef std::vector<ExPolygon> ExPolygons;
 
11
 
 
12
class ExPolygon
 
13
{
 
14
    public:
 
15
    Polygon contour;
 
16
    Polygons holes;
 
17
    operator Points() const;
 
18
    operator Polygons() const;
 
19
    void scale(double factor);
 
20
    void translate(double x, double y);
 
21
    void rotate(double angle, const Point &center);
 
22
    double area() const;
 
23
    bool is_valid() const;
 
24
    bool contains_line(const Line &line) const;
 
25
    bool contains_point(const Point &point) const;
 
26
    Polygons simplify_p(double tolerance) const;
 
27
    ExPolygons simplify(double tolerance) const;
 
28
    void simplify(double tolerance, ExPolygons &expolygons) const;
 
29
    void medial_axis(double max_width, double min_width, Polylines* polylines) const;
 
30
    void get_trapezoids(Polygons* polygons) const;
 
31
    void get_trapezoids(Polygons* polygons, double angle) const;
 
32
    void get_trapezoids2(Polygons* polygons) const;
 
33
    void get_trapezoids2(Polygons* polygons, double angle) const;
 
34
    void triangulate(Polygons* polygons) const;
 
35
    void triangulate_pp(Polygons* polygons) const;
 
36
    void triangulate_p2t(Polygons* polygons) const;
 
37
    
 
38
    #ifdef SLIC3RXS
 
39
    void from_SV(SV* poly_sv);
 
40
    void from_SV_check(SV* poly_sv);
 
41
    SV* to_AV();
 
42
    SV* to_SV_pureperl() const;
 
43
    #endif
 
44
};
 
45
 
 
46
}
 
47
 
 
48
// start Boost
 
49
#include <boost/polygon/polygon.hpp>
 
50
namespace boost { namespace polygon {
 
51
    template <>
 
52
        struct polygon_traits<ExPolygon> {
 
53
        typedef coord_t coordinate_type;
 
54
        typedef Points::const_iterator iterator_type;
 
55
        typedef Point point_type;
 
56
 
 
57
        // Get the begin iterator
 
58
        static inline iterator_type begin_points(const ExPolygon& t) {
 
59
            return t.contour.points.begin();
 
60
        }
 
61
 
 
62
        // Get the end iterator
 
63
        static inline iterator_type end_points(const ExPolygon& t) {
 
64
            return t.contour.points.end();
 
65
        }
 
66
 
 
67
        // Get the number of sides of the polygon
 
68
        static inline std::size_t size(const ExPolygon& t) {
 
69
            return t.contour.points.size();
 
70
        }
 
71
 
 
72
        // Get the winding direction of the polygon
 
73
        static inline winding_direction winding(const ExPolygon& t) {
 
74
            return unknown_winding;
 
75
        }
 
76
    };
 
77
 
 
78
    template <>
 
79
    struct polygon_mutable_traits<ExPolygon> {
 
80
        //expects stl style iterators
 
81
        template <typename iT>
 
82
        static inline ExPolygon& set_points(ExPolygon& expolygon, iT input_begin, iT input_end) {
 
83
            expolygon.contour.points.assign(input_begin, input_end);
 
84
            // skip last point since Boost will set last point = first point
 
85
            expolygon.contour.points.pop_back();
 
86
            return expolygon;
 
87
        }
 
88
    };
 
89
    
 
90
    
 
91
    template <>
 
92
    struct geometry_concept<ExPolygon> { typedef polygon_with_holes_concept type; };
 
93
 
 
94
    template <>
 
95
    struct polygon_with_holes_traits<ExPolygon> {
 
96
        typedef Polygons::const_iterator iterator_holes_type;
 
97
        typedef Polygon hole_type;
 
98
        static inline iterator_holes_type begin_holes(const ExPolygon& t) {
 
99
            return t.holes.begin();
 
100
        }
 
101
        static inline iterator_holes_type end_holes(const ExPolygon& t) {
 
102
            return t.holes.end();
 
103
        }
 
104
        static inline unsigned int size_holes(const ExPolygon& t) {
 
105
            return t.holes.size();
 
106
        }
 
107
    };
 
108
 
 
109
    template <>
 
110
    struct polygon_with_holes_mutable_traits<ExPolygon> {
 
111
         template <typename iT>
 
112
         static inline ExPolygon& set_holes(ExPolygon& t, iT inputBegin, iT inputEnd) {
 
113
              t.holes.assign(inputBegin, inputEnd);
 
114
              return t;
 
115
         }
 
116
    };
 
117
    
 
118
    //first we register CPolygonSet as a polygon set
 
119
    template <>
 
120
    struct geometry_concept<ExPolygons> { typedef polygon_set_concept type; };
 
121
 
 
122
    //next we map to the concept through traits
 
123
    template <>
 
124
    struct polygon_set_traits<ExPolygons> {
 
125
        typedef coord_t coordinate_type;
 
126
        typedef ExPolygons::const_iterator iterator_type;
 
127
        typedef ExPolygons operator_arg_type;
 
128
 
 
129
        static inline iterator_type begin(const ExPolygons& polygon_set) {
 
130
            return polygon_set.begin();
 
131
        }
 
132
 
 
133
        static inline iterator_type end(const ExPolygons& polygon_set) {
 
134
            return polygon_set.end();
 
135
        }
 
136
 
 
137
        //don't worry about these, just return false from them
 
138
        static inline bool clean(const ExPolygons& polygon_set) { return false; }
 
139
        static inline bool sorted(const ExPolygons& polygon_set) { return false; }
 
140
    };
 
141
 
 
142
    template <>
 
143
    struct polygon_set_mutable_traits<ExPolygons> {
 
144
        template <typename input_iterator_type>
 
145
        static inline void set(ExPolygons& expolygons, input_iterator_type input_begin, input_iterator_type input_end) {
 
146
            expolygons.assign(input_begin, input_end);
 
147
        }
 
148
    };
 
149
} }
 
150
// end Boost
 
151
 
 
152
#endif