Finished porting BoundingBox to XS

This commit is contained in:
Alessandro Ranellucci 2014-01-07 12:48:09 +01:00
parent ea47f3b6e7
commit b17d06f9d1
24 changed files with 160 additions and 262 deletions

View file

@ -6,23 +6,30 @@ namespace Slic3r {
template <class PointClass>
BoundingBoxBase<PointClass>::BoundingBoxBase(const std::vector<PointClass> points)
{
for (typename std::vector<PointClass>::const_iterator it = points.begin(); it != points.end(); ++it) {
typename std::vector<PointClass>::const_iterator it = points.begin();
this->min.x = this->max.x = it->x;
this->min.y = this->max.y = it->y;
for (++it; it != points.end(); ++it) {
this->min.x = std::min(it->x, this->min.x);
this->min.y = std::min(it->y, this->min.y);
this->max.x = std::max(it->x, this->max.x);
this->max.y = std::max(it->y, this->max.y);
}
}
template BoundingBoxBase<Point>::BoundingBoxBase(const std::vector<Point> points);
template <class PointClass>
BoundingBox3Base<PointClass>::BoundingBox3Base(const std::vector<PointClass> points)
: BoundingBoxBase<PointClass>(points)
{
for (typename std::vector<PointClass>::const_iterator it = points.begin(); it != points.end(); ++it) {
typename std::vector<PointClass>::const_iterator it = points.begin();
this->min.z = this->max.z = it->z;
for (++it; it != points.end(); ++it) {
this->min.z = std::min(it->z, this->min.z);
this->max.z = std::max(it->z, this->max.z);
}
}
template BoundingBox3Base<Pointf3>::BoundingBox3Base(const std::vector<Pointf3> points);
void
BoundingBox::polygon(Polygon* polygon) const
@ -45,6 +52,18 @@ BoundingBoxBase<PointClass>::scale(double factor)
this->min.scale(factor);
this->max.scale(factor);
}
template void BoundingBoxBase<Point>::scale(double factor);
template void BoundingBoxBase<Pointf3>::scale(double factor);
template <class PointClass> void
BoundingBoxBase<PointClass>::merge(const PointClass &point)
{
this->min.x = std::min(point.x, this->min.x);
this->min.y = std::min(point.y, this->min.y);
this->max.x = std::max(point.x, this->max.x);
this->max.y = std::max(point.y, this->max.y);
}
template void BoundingBoxBase<Point>::merge(const Point &point);
template <class PointClass> void
BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
@ -54,6 +73,16 @@ BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
this->max.x = std::max(bb.max.x, this->max.x);
this->max.y = std::max(bb.max.y, this->max.y);
}
template void BoundingBoxBase<Point>::merge(const BoundingBoxBase<Point> &bb);
template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const PointClass &point)
{
BoundingBoxBase<PointClass>::merge(point);
this->min.z = std::min(point.z, this->min.z);
this->max.z = std::max(point.z, this->max.z);
}
template void BoundingBox3Base<Pointf3>::merge(const Pointf3 &point);
template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
@ -62,25 +91,29 @@ BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
this->min.z = std::min(bb.min.z, this->min.z);
this->max.z = std::max(bb.max.z, this->max.z);
}
template void BoundingBox3Base<Pointf3>::merge(const BoundingBox3Base<Pointf3> &bb);
template <class PointClass> PointClass
BoundingBox2Base<PointClass>::size() const
BoundingBoxBase<PointClass>::size() const
{
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y);
}
template Point BoundingBoxBase<Point>::size() const;
template <class PointClass> PointClass
BoundingBox3Base<PointClass>::size() const
{
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y, this->max.z - this->min.z);
}
template Pointf3 BoundingBox3Base<Pointf3>::size() const;
template <class PointClass> void
BoundingBox2Base<PointClass>::translate(coordf_t x, coordf_t y)
BoundingBoxBase<PointClass>::translate(coordf_t x, coordf_t y)
{
this->min.translate(x, y);
this->max.translate(x, y);
}
template void BoundingBoxBase<Point>::translate(coordf_t x, coordf_t y);
template <class PointClass> void
BoundingBox3Base<PointClass>::translate(coordf_t x, coordf_t y, coordf_t z)
@ -88,24 +121,27 @@ BoundingBox3Base<PointClass>::translate(coordf_t x, coordf_t y, coordf_t z)
this->min.translate(x, y, z);
this->max.translate(x, y, z);
}
template void BoundingBox3Base<Pointf3>::translate(coordf_t x, coordf_t y, coordf_t z);
template <class PointClass> PointClass
BoundingBox2Base<PointClass>::center() const
BoundingBoxBase<PointClass>::center() const
{
return PointClass(
(this->max.x - this->min.x)/2,
(this->max.y - this->min.y)/2
(this->max.x + this->min.x)/2,
(this->max.y + this->min.y)/2
);
}
template Point BoundingBoxBase<Point>::center() const;
template <class PointClass> PointClass
BoundingBox3Base<PointClass>::center() const
{
return PointClass(
(this->max.x - this->min.x)/2,
(this->max.y - this->min.y)/2,
(this->max.z - this->min.z)/2
(this->max.x + this->min.x)/2,
(this->max.y + this->min.y)/2,
(this->max.z + this->min.z)/2
);
}
template Pointf3 BoundingBox3Base<Pointf3>::center() const;
}

View file

@ -19,18 +19,11 @@ class BoundingBoxBase
PointClass min;
PointClass max;
BoundingBoxBase();
BoundingBoxBase() {};
BoundingBoxBase(const std::vector<PointClass> points);
void merge(const PointClass &point);
void merge(const BoundingBoxBase<PointClass> &bb);
void scale(double factor);
};
template <class PointClass>
class BoundingBox2Base : public BoundingBoxBase<PointClass>
{
public:
BoundingBox2Base();
BoundingBox2Base(const std::vector<PointClass> points) : BoundingBoxBase<PointClass>(points) {};
PointClass size() const;
void translate(coordf_t x, coordf_t y);
PointClass center() const;
@ -40,25 +33,28 @@ template <class PointClass>
class BoundingBox3Base : public BoundingBoxBase<PointClass>
{
public:
BoundingBox3Base();
BoundingBox3Base() {};
BoundingBox3Base(const std::vector<PointClass> points);
void merge(const PointClass &point);
void merge(const BoundingBox3Base<PointClass> &bb);
PointClass size() const;
void translate(coordf_t x, coordf_t y, coordf_t z);
PointClass center() const;
};
class BoundingBox : public BoundingBox2Base<Point>
class BoundingBox : public BoundingBoxBase<Point>
{
public:
void polygon(Polygon* polygon) const;
BoundingBox() {};
BoundingBox(const Points points) : BoundingBox2Base<Point>(points) {};
BoundingBox(const Points points) : BoundingBoxBase<Point>(points) {};
};
class BoundingBoxf : public BoundingBox2Base<Pointf> {};
/*
class BoundingBoxf : public BoundingBoxBase<Pointf> {};
class BoundingBox3 : public BoundingBox3Base<Point3> {};
*/
class BoundingBoxf3 : public BoundingBox3Base<Pointf3> {
public:

View file

@ -77,7 +77,6 @@ class ModelObject
void raw_mesh(TriangleMesh* mesh) const;
void mesh(TriangleMesh* mesh) const;
void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
void align_to_origin();
void center_around_origin();
void translate(coordf_t x, coordf_t y, coordf_t z);
size_t materials_count() const;

View file

@ -193,4 +193,32 @@ Pointf::from_SV(SV* point_sv)
}
#endif
void
Pointf::scale(double factor)
{
this->x *= factor;
this->y *= factor;
}
void
Pointf::translate(double x, double y)
{
this->x += x;
this->y += y;
}
void
Pointf3::scale(double factor)
{
Pointf::scale(factor);
this->z *= factor;
}
void
Pointf3::translate(double x, double y, double z)
{
Pointf::translate(x, y);
this->z += z;
}
}

View file

@ -57,6 +57,8 @@ class Pointf
coordf_t x;
coordf_t y;
explicit Pointf(coordf_t _x = 0, coordf_t _y = 0): x(_x), y(_y) {};
void scale(double factor);
void translate(double x, double y);
#ifdef SLIC3RXS
void from_SV(SV* point_sv);
@ -69,6 +71,8 @@ class Pointf3 : public Pointf
public:
coordf_t z;
explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), z(_z) {};
void scale(double factor);
void translate(double x, double y, double z);
};
}