Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types, first step

This commit is contained in:
bubnikv 2018-08-14 18:33:26 +02:00
parent 077680b806
commit 86da661097
60 changed files with 1228 additions and 1206 deletions

View file

@ -27,14 +27,14 @@ BoundingBox::polygon(Polygon* polygon) const
{
polygon->points.clear();
polygon->points.resize(4);
polygon->points[0].x = this->min.x;
polygon->points[0].y = this->min.y;
polygon->points[1].x = this->max.x;
polygon->points[1].y = this->min.y;
polygon->points[2].x = this->max.x;
polygon->points[2].y = this->max.y;
polygon->points[3].x = this->min.x;
polygon->points[3].y = this->max.y;
polygon->points[0].x() = this->min.x();
polygon->points[0].y() = this->min.y();
polygon->points[1].x() = this->max.x();
polygon->points[1].y() = this->min.y();
polygon->points[2].x() = this->max.x();
polygon->points[2].y() = this->max.y();
polygon->points[3].x() = this->min.x();
polygon->points[3].y() = this->max.y();
}
Polygon
@ -50,8 +50,8 @@ BoundingBox BoundingBox::rotated(double angle) const
BoundingBox out;
out.merge(this->min.rotated(angle));
out.merge(this->max.rotated(angle));
out.merge(Point(this->min.x, this->max.y).rotated(angle));
out.merge(Point(this->max.x, this->min.y).rotated(angle));
out.merge(Point(this->min.x(), this->max.y()).rotated(angle));
out.merge(Point(this->max.x(), this->min.y()).rotated(angle));
return out;
}
@ -60,8 +60,8 @@ BoundingBox BoundingBox::rotated(double angle, const Point &center) const
BoundingBox out;
out.merge(this->min.rotated(angle, center));
out.merge(this->max.rotated(angle, center));
out.merge(Point(this->min.x, this->max.y).rotated(angle, center));
out.merge(Point(this->max.x, this->min.y).rotated(angle, center));
out.merge(Point(this->min.x(), this->max.y()).rotated(angle, center));
out.merge(Point(this->max.x(), this->min.y()).rotated(angle, center));
return out;
}
@ -79,10 +79,10 @@ template <class PointClass> void
BoundingBoxBase<PointClass>::merge(const PointClass &point)
{
if (this->defined) {
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);
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());
} else {
this->min = this->max = point;
this->defined = true;
@ -102,13 +102,13 @@ template void BoundingBoxBase<Pointf>::merge(const Pointfs &points);
template <class PointClass> void
BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
{
assert(bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y);
assert(bb.defined || bb.min.x() >= bb.max.x() || bb.min.y() >= bb.max.y());
if (bb.defined) {
if (this->defined) {
this->min.x = std::min(bb.min.x, this->min.x);
this->min.y = std::min(bb.min.y, this->min.y);
this->max.x = std::max(bb.max.x, this->max.x);
this->max.y = std::max(bb.max.y, this->max.y);
this->min.x() = std::min(bb.min.x(), this->min.x());
this->min.y() = std::min(bb.min.y(), this->min.y());
this->max.x() = std::max(bb.max.x(), this->max.x());
this->max.y() = std::max(bb.max.y(), this->max.y());
} else {
this->min = bb.min;
this->max = bb.max;
@ -123,8 +123,8 @@ template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const PointClass &point)
{
if (this->defined) {
this->min.z = std::min(point.z, this->min.z);
this->max.z = std::max(point.z, this->max.z);
this->min.z() = std::min(point.z(), this->min.z());
this->max.z() = std::max(point.z(), this->max.z());
}
BoundingBoxBase<PointClass>::merge(point);
}
@ -140,11 +140,11 @@ template void BoundingBox3Base<Pointf3>::merge(const Pointf3s &points);
template <class PointClass> void
BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
{
assert(bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y || bb.min.z >= bb.max.z);
assert(bb.defined || bb.min.x() >= bb.max.x() || bb.min.y() >= bb.max.y() || bb.min.z() >= bb.max.z());
if (bb.defined) {
if (this->defined) {
this->min.z = std::min(bb.min.z, this->min.z);
this->max.z = std::max(bb.max.z, this->max.z);
this->min.z() = std::min(bb.min.z(), this->min.z());
this->max.z() = std::max(bb.max.z(), this->max.z());
}
BoundingBoxBase<PointClass>::merge(bb);
}
@ -154,7 +154,7 @@ template void BoundingBox3Base<Pointf3>::merge(const BoundingBox3Base<Pointf3> &
template <class PointClass> PointClass
BoundingBoxBase<PointClass>::size() const
{
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y);
return PointClass(this->max.x() - this->min.x(), this->max.y() - this->min.y());
}
template Point BoundingBoxBase<Point>::size() const;
template Pointf BoundingBoxBase<Pointf>::size() const;
@ -162,15 +162,15 @@ template Pointf BoundingBoxBase<Pointf>::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);
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> double BoundingBoxBase<PointClass>::radius() const
{
assert(this->defined);
double x = this->max.x - this->min.x;
double y = this->max.y - this->min.y;
double x = this->max.x() - this->min.x();
double y = this->max.y() - this->min.y();
return 0.5 * sqrt(x*x+y*y);
}
template double BoundingBoxBase<Point>::radius() const;
@ -178,9 +178,9 @@ template double BoundingBoxBase<Pointf>::radius() const;
template <class PointClass> double BoundingBox3Base<PointClass>::radius() const
{
double x = this->max.x - this->min.x;
double y = this->max.y - this->min.y;
double z = this->max.z - this->min.z;
double x = this->max.x() - this->min.x();
double y = this->max.y() - this->min.y();
double z = this->max.z() - this->min.z();
return 0.5 * sqrt(x*x+y*y+z*z);
}
template double BoundingBox3Base<Pointf3>::radius() const;
@ -206,8 +206,8 @@ template <class PointClass> PointClass
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;
@ -217,9 +217,9 @@ 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;
@ -228,7 +228,7 @@ template <class PointClass> coordf_t
BoundingBox3Base<PointClass>::max_size() const
{
PointClass s = size();
return std::max(s.x, std::max(s.y, s.z));
return std::max(s.x(), std::max(s.y(), s.z()));
}
template coordf_t BoundingBox3Base<Pointf3>::max_size() const;
@ -248,8 +248,8 @@ static inline coord_t _align_to_grid(const coord_t coord, const coord_t spacing)
void BoundingBox::align_to_grid(const coord_t cell_size)
{
if (this->defined) {
min.x = _align_to_grid(min.x, cell_size);
min.y = _align_to_grid(min.y, cell_size);
min.x() = _align_to_grid(min.x(), cell_size);
min.y() = _align_to_grid(min.y(), cell_size);
}
}
@ -257,14 +257,14 @@ BoundingBoxf3 BoundingBoxf3::transformed(const std::vector<float>& matrix) const
{
Eigen::Matrix<float, 3, 8> vertices;
vertices(0, 0) = (float)min.x; vertices(1, 0) = (float)min.y; vertices(2, 0) = (float)min.z;
vertices(0, 1) = (float)max.x; vertices(1, 1) = (float)min.y; vertices(2, 1) = (float)min.z;
vertices(0, 2) = (float)max.x; vertices(1, 2) = (float)max.y; vertices(2, 2) = (float)min.z;
vertices(0, 3) = (float)min.x; vertices(1, 3) = (float)max.y; vertices(2, 3) = (float)min.z;
vertices(0, 4) = (float)min.x; vertices(1, 4) = (float)min.y; vertices(2, 4) = (float)max.z;
vertices(0, 5) = (float)max.x; vertices(1, 5) = (float)min.y; vertices(2, 5) = (float)max.z;
vertices(0, 6) = (float)max.x; vertices(1, 6) = (float)max.y; vertices(2, 6) = (float)max.z;
vertices(0, 7) = (float)min.x; vertices(1, 7) = (float)max.y; vertices(2, 7) = (float)max.z;
vertices(0, 0) = (float)min.x(); vertices(1, 0) = (float)min.y(); vertices(2, 0) = (float)min.z();
vertices(0, 1) = (float)max.x(); vertices(1, 1) = (float)min.y(); vertices(2, 1) = (float)min.z();
vertices(0, 2) = (float)max.x(); vertices(1, 2) = (float)max.y(); vertices(2, 2) = (float)min.z();
vertices(0, 3) = (float)min.x(); vertices(1, 3) = (float)max.y(); vertices(2, 3) = (float)min.z();
vertices(0, 4) = (float)min.x(); vertices(1, 4) = (float)min.y(); vertices(2, 4) = (float)max.z();
vertices(0, 5) = (float)max.x(); vertices(1, 5) = (float)min.y(); vertices(2, 5) = (float)max.z();
vertices(0, 6) = (float)max.x(); vertices(1, 6) = (float)max.y(); vertices(2, 6) = (float)max.z();
vertices(0, 7) = (float)min.x(); vertices(1, 7) = (float)max.y(); vertices(2, 7) = (float)max.z();
Eigen::Transform<float, 3, Eigen::Affine> m;
::memcpy((void*)m.data(), (const void*)matrix.data(), 16 * sizeof(float));