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

« back to all changes in this revision

Viewing changes to xs/src/BoundingBox.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 "BoundingBox.hpp"
 
2
#include <algorithm>
 
3
 
 
4
namespace Slic3r {
 
5
 
 
6
template <class PointClass>
 
7
BoundingBoxBase<PointClass>::BoundingBoxBase(const std::vector<PointClass> &points)
 
8
{
 
9
    if (points.empty()) CONFESS("Empty point set supplied to BoundingBoxBase constructor");
 
10
    typename std::vector<PointClass>::const_iterator it = points.begin();
 
11
    this->min.x = this->max.x = it->x;
 
12
    this->min.y = this->max.y = it->y;
 
13
    for (++it; it != points.end(); ++it) {
 
14
        this->min.x = std::min(it->x, this->min.x);
 
15
        this->min.y = std::min(it->y, this->min.y);
 
16
        this->max.x = std::max(it->x, this->max.x);
 
17
        this->max.y = std::max(it->y, this->max.y);
 
18
    }
 
19
}
 
20
template BoundingBoxBase<Point>::BoundingBoxBase(const std::vector<Point> &points);
 
21
 
 
22
template <class PointClass>
 
23
BoundingBox3Base<PointClass>::BoundingBox3Base(const std::vector<PointClass> &points)
 
24
    : BoundingBoxBase<PointClass>(points)
 
25
{
 
26
    if (points.empty()) CONFESS("Empty point set supplied to BoundingBox3Base constructor");
 
27
    typename std::vector<PointClass>::const_iterator it = points.begin();
 
28
    this->min.z = this->max.z = it->z;
 
29
    for (++it; it != points.end(); ++it) {
 
30
        this->min.z = std::min(it->z, this->min.z);
 
31
        this->max.z = std::max(it->z, this->max.z);
 
32
    }
 
33
}
 
34
template BoundingBox3Base<Pointf3>::BoundingBox3Base(const std::vector<Pointf3> &points);
 
35
 
 
36
BoundingBox::BoundingBox(const Lines &lines)
 
37
{
 
38
    Points points;
 
39
    for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
 
40
        points.push_back(line->a);
 
41
        points.push_back(line->b);
 
42
    }
 
43
    *this = BoundingBox(points);
 
44
}
 
45
 
 
46
void
 
47
BoundingBox::polygon(Polygon* polygon) const
 
48
{
 
49
    polygon->points.clear();
 
50
    polygon->points.resize(4);
 
51
    polygon->points[0].x = this->min.x;
 
52
    polygon->points[0].y = this->min.y;
 
53
    polygon->points[1].x = this->max.x;
 
54
    polygon->points[1].y = this->min.y;
 
55
    polygon->points[2].x = this->max.x;
 
56
    polygon->points[2].y = this->max.y;
 
57
    polygon->points[3].x = this->min.x;
 
58
    polygon->points[3].y = this->max.y;
 
59
}
 
60
 
 
61
template <class PointClass> void
 
62
BoundingBoxBase<PointClass>::scale(double factor)
 
63
{
 
64
    this->min.scale(factor);
 
65
    this->max.scale(factor);
 
66
}
 
67
template void BoundingBoxBase<Point>::scale(double factor);
 
68
template void BoundingBoxBase<Pointf3>::scale(double factor);
 
69
 
 
70
template <class PointClass> void
 
71
BoundingBoxBase<PointClass>::merge(const PointClass &point)
 
72
{
 
73
    this->min.x = std::min(point.x, this->min.x);
 
74
    this->min.y = std::min(point.y, this->min.y);
 
75
    this->max.x = std::max(point.x, this->max.x);
 
76
    this->max.y = std::max(point.y, this->max.y);
 
77
}
 
78
template void BoundingBoxBase<Point>::merge(const Point &point);
 
79
 
 
80
template <class PointClass> void
 
81
BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
 
82
{
 
83
    this->min.x = std::min(bb.min.x, this->min.x);
 
84
    this->min.y = std::min(bb.min.y, this->min.y);
 
85
    this->max.x = std::max(bb.max.x, this->max.x);
 
86
    this->max.y = std::max(bb.max.y, this->max.y);
 
87
}
 
88
template void BoundingBoxBase<Point>::merge(const BoundingBoxBase<Point> &bb);
 
89
 
 
90
template <class PointClass> void
 
91
BoundingBox3Base<PointClass>::merge(const PointClass &point)
 
92
{
 
93
    BoundingBoxBase<PointClass>::merge(point);
 
94
    this->min.z = std::min(point.z, this->min.z);
 
95
    this->max.z = std::max(point.z, this->max.z);
 
96
}
 
97
template void BoundingBox3Base<Pointf3>::merge(const Pointf3 &point);
 
98
 
 
99
template <class PointClass> void
 
100
BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
 
101
{
 
102
    BoundingBoxBase<PointClass>::merge(bb);
 
103
    this->min.z = std::min(bb.min.z, this->min.z);
 
104
    this->max.z = std::max(bb.max.z, this->max.z);
 
105
}
 
106
template void BoundingBox3Base<Pointf3>::merge(const BoundingBox3Base<Pointf3> &bb);
 
107
 
 
108
template <class PointClass> PointClass
 
109
BoundingBoxBase<PointClass>::size() const
 
110
{
 
111
    return PointClass(this->max.x - this->min.x, this->max.y - this->min.y);
 
112
}
 
113
template Point BoundingBoxBase<Point>::size() const;
 
114
 
 
115
template <class PointClass> PointClass
 
116
BoundingBox3Base<PointClass>::size() const
 
117
{
 
118
    return PointClass(this->max.x - this->min.x, this->max.y - this->min.y, this->max.z - this->min.z);
 
119
}
 
120
template Pointf3 BoundingBox3Base<Pointf3>::size() const;
 
121
 
 
122
template <class PointClass> void
 
123
BoundingBoxBase<PointClass>::translate(coordf_t x, coordf_t y)
 
124
{
 
125
    this->min.translate(x, y);
 
126
    this->max.translate(x, y);
 
127
}
 
128
template void BoundingBoxBase<Point>::translate(coordf_t x, coordf_t y);
 
129
 
 
130
template <class PointClass> void
 
131
BoundingBox3Base<PointClass>::translate(coordf_t x, coordf_t y, coordf_t z)
 
132
{
 
133
    this->min.translate(x, y, z);
 
134
    this->max.translate(x, y, z);
 
135
}
 
136
template void BoundingBox3Base<Pointf3>::translate(coordf_t x, coordf_t y, coordf_t z);
 
137
 
 
138
template <class PointClass> PointClass
 
139
BoundingBoxBase<PointClass>::center() const
 
140
{
 
141
    return PointClass(
 
142
        (this->max.x + this->min.x)/2,
 
143
        (this->max.y + this->min.y)/2
 
144
    );
 
145
}
 
146
template Point BoundingBoxBase<Point>::center() const;
 
147
 
 
148
template <class PointClass> PointClass
 
149
BoundingBox3Base<PointClass>::center() const
 
150
{
 
151
    return PointClass(
 
152
        (this->max.x + this->min.x)/2,
 
153
        (this->max.y + this->min.y)/2,
 
154
        (this->max.z + this->min.z)/2
 
155
    );
 
156
}
 
157
template Pointf3 BoundingBox3Base<Pointf3>::center() const;
 
158
 
 
159
#ifdef SLIC3RXS
 
160
REGISTER_CLASS(BoundingBox, "Geometry::BoundingBox");
 
161
REGISTER_CLASS(BoundingBoxf, "Geometry::BoundingBoxf");
 
162
REGISTER_CLASS(BoundingBoxf3, "Geometry::BoundingBoxf3");
 
163
#endif
 
164
 
 
165
}