Completely replaced the homebrew Pointf3 class with Eigen Vec3d.

Replaced the unscale macro with a template, implemented templates
for unscaling Eigen vectors.
This commit is contained in:
bubnikv 2018-08-21 17:43:05 +02:00
parent c5256bdd2c
commit cb138a20b8
46 changed files with 329 additions and 373 deletions

View file

@ -9,7 +9,7 @@ namespace Slic3r {
template BoundingBoxBase<Point>::BoundingBoxBase(const std::vector<Point> &points);
template BoundingBoxBase<Pointf>::BoundingBoxBase(const std::vector<Pointf> &points);
template BoundingBox3Base<Pointf3>::BoundingBox3Base(const std::vector<Pointf3> &points);
template BoundingBox3Base<Vec3d>::BoundingBox3Base(const std::vector<Vec3d> &points);
BoundingBox::BoundingBox(const Lines &lines)
{
@ -22,8 +22,7 @@ BoundingBox::BoundingBox(const Lines &lines)
*this = BoundingBox(points);
}
void
BoundingBox::polygon(Polygon* polygon) const
void BoundingBox::polygon(Polygon* polygon) const
{
polygon->points.clear();
polygon->points.resize(4);
@ -37,8 +36,7 @@ BoundingBox::polygon(Polygon* polygon) const
polygon->points[3](1) = this->max(1);
}
Polygon
BoundingBox::polygon() const
Polygon BoundingBox::polygon() const
{
Polygon p;
this->polygon(&p);
@ -73,18 +71,17 @@ BoundingBoxBase<PointClass>::scale(double factor)
}
template void BoundingBoxBase<Point>::scale(double factor);
template void BoundingBoxBase<Pointf>::scale(double factor);
template void BoundingBoxBase<Pointf3>::scale(double factor);
template void BoundingBoxBase<Vec3d>::scale(double factor);
template <class PointClass> void
BoundingBoxBase<PointClass>::merge(const PointClass &point)
{
if (this->defined) {
this->min(0) = std::min(point(0), this->min(0));
this->min(1) = std::min(point(1), this->min(1));
this->max(0) = std::max(point(0), this->max(0));
this->max(1) = std::max(point(1), this->max(1));
this->min = this->min.cwiseMin(point);
this->max = this->max.cwiseMax(point);
} else {
this->min = this->max = point;
this->min = point;
this->max = point;
this->defined = true;
}
}
@ -105,10 +102,8 @@ BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
assert(bb.defined || bb.min(0) >= bb.max(0) || bb.min(1) >= bb.max(1));
if (bb.defined) {
if (this->defined) {
this->min(0) = std::min(bb.min(0), this->min(0));
this->min(1) = std::min(bb.min(1), this->min(1));
this->max(0) = std::max(bb.max(0), this->max(0));
this->max(1) = std::max(bb.max(1), this->max(1));
this->min = this->min.cwiseMin(bb.min);
this->max = this->max.cwiseMax(bb.max);
} else {
this->min = bb.min;
this->max = bb.max;
@ -123,19 +118,22 @@ template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const PointClass &point)
{
if (this->defined) {
this->min(2) = std::min(point(2), this->min(2));
this->max(2) = std::max(point(2), this->max(2));
this->min = this->min.cwiseMin(point);
this->max = this->max.cwiseMax(point);
} else {
this->min = point;
this->max = point;
this->defined = true;
}
BoundingBoxBase<PointClass>::merge(point);
}
template void BoundingBox3Base<Pointf3>::merge(const Pointf3 &point);
template void BoundingBox3Base<Vec3d>::merge(const Vec3d &point);
template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const std::vector<PointClass> &points)
{
this->merge(BoundingBox3Base(points));
}
template void BoundingBox3Base<Pointf3>::merge(const Pointf3s &points);
template void BoundingBox3Base<Vec3d>::merge(const Pointf3s &points);
template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
@ -143,13 +141,16 @@ BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
assert(bb.defined || bb.min(0) >= bb.max(0) || bb.min(1) >= bb.max(1) || bb.min(2) >= bb.max(2));
if (bb.defined) {
if (this->defined) {
this->min(2) = std::min(bb.min(2), this->min(2));
this->max(2) = std::max(bb.max(2), this->max(2));
this->min = this->min.cwiseMin(bb.min);
this->max = this->max.cwiseMax(bb.max);
} else {
this->min = bb.min;
this->max = bb.max;
this->defined = true;
}
BoundingBoxBase<PointClass>::merge(bb);
}
}
template void BoundingBox3Base<Pointf3>::merge(const BoundingBox3Base<Pointf3> &bb);
template void BoundingBox3Base<Vec3d>::merge(const BoundingBox3Base<Vec3d> &bb);
template <class PointClass> PointClass
BoundingBoxBase<PointClass>::size() const
@ -164,7 +165,7 @@ BoundingBox3Base<PointClass>::size() const
{
return PointClass(this->max(0) - this->min(0), this->max(1) - this->min(1), this->max(2) - this->min(2));
}
template Pointf3 BoundingBox3Base<Pointf3>::size() const;
template Vec3d BoundingBox3Base<Vec3d>::size() const;
template <class PointClass> double BoundingBoxBase<PointClass>::radius() const
{
@ -183,7 +184,7 @@ template <class PointClass> double BoundingBox3Base<PointClass>::radius() const
double z = this->max(2) - this->min(2);
return 0.5 * sqrt(x*x+y*y+z*z);
}
template double BoundingBox3Base<Pointf3>::radius() const;
template double BoundingBox3Base<Vec3d>::radius() const;
template <class PointClass> void
BoundingBoxBase<PointClass>::offset(coordf_t delta)
@ -202,15 +203,12 @@ BoundingBox3Base<PointClass>::offset(coordf_t delta)
this->min -= v;
this->max += v;
}
template void BoundingBox3Base<Pointf3>::offset(coordf_t delta);
template void BoundingBox3Base<Vec3d>::offset(coordf_t delta);
template <class PointClass> PointClass
BoundingBoxBase<PointClass>::center() const
{
return PointClass(
(this->max(0) + this->min(0))/2,
(this->max(1) + this->min(1))/2
);
return (this->min + this->max) / 2;
}
template Point BoundingBoxBase<Point>::center() const;
template Pointf BoundingBoxBase<Pointf>::center() const;
@ -218,13 +216,9 @@ template Pointf BoundingBoxBase<Pointf>::center() const;
template <class PointClass> PointClass
BoundingBox3Base<PointClass>::center() const
{
return PointClass(
(this->max(0) + this->min(0))/2,
(this->max(1) + this->min(1))/2,
(this->max(2) + this->min(2))/2
);
return (this->min + this->max) / 2;
}
template Pointf3 BoundingBox3Base<Pointf3>::center() const;
template Vec3d BoundingBox3Base<Vec3d>::center() const;
template <class PointClass> coordf_t
BoundingBox3Base<PointClass>::max_size() const
@ -232,7 +226,7 @@ BoundingBox3Base<PointClass>::max_size() const
PointClass s = size();
return std::max(s(0), std::max(s(1), s(2)));
}
template coordf_t BoundingBox3Base<Pointf3>::max_size() const;
template coordf_t BoundingBox3Base<Vec3d>::max_size() const;
// Align a coordinate to a grid. The coordinate may be negative,
// the aligned value will never be bigger than the original one.
@ -287,7 +281,7 @@ BoundingBoxf3 BoundingBoxf3::transformed(const Transform3f& matrix) const
max_z = std::max(max_z, transf_vertices(2, i));
}
return BoundingBoxf3(Pointf3((coordf_t)min_x, (coordf_t)min_y, (coordf_t)min_z), Pointf3((coordf_t)max_x, (coordf_t)max_y, (coordf_t)max_z));
return BoundingBoxf3(Vec3d((coordf_t)min_x, (coordf_t)min_y, (coordf_t)min_z), Vec3d((coordf_t)max_x, (coordf_t)max_y, (coordf_t)max_z));
}
}