BoundingBox support for Lines,
BoundingBox constructor will no more throw for empty vector of points. GMP allowed for Vojtech's fork of boost::polygon Voronoi implementation. Added libslic3r tests for boost::polygon Voronoi. All Voronoi issues ever reported on the Internet are captured by the tests. Two issues reported (the two test cases) are real issues which may influence PrusaSlicer negatively, namely https://github.com/boostorg/polygon/issues/43
This commit is contained in:
parent
0599dc4df7
commit
6f92538c20
@ -11,17 +11,6 @@ template BoundingBoxBase<Vec2d>::BoundingBoxBase(const std::vector<Vec2d> &point
|
|||||||
|
|
||||||
template BoundingBox3Base<Vec3d>::BoundingBox3Base(const std::vector<Vec3d> &points);
|
template BoundingBox3Base<Vec3d>::BoundingBox3Base(const std::vector<Vec3d> &points);
|
||||||
|
|
||||||
BoundingBox::BoundingBox(const Lines &lines)
|
|
||||||
{
|
|
||||||
Points points;
|
|
||||||
points.reserve(lines.size());
|
|
||||||
for (const Line &line : lines) {
|
|
||||||
points.emplace_back(line.a);
|
|
||||||
points.emplace_back(line.b);
|
|
||||||
}
|
|
||||||
*this = BoundingBox(points);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoundingBox::polygon(Polygon* polygon) const
|
void BoundingBox::polygon(Polygon* polygon) const
|
||||||
{
|
{
|
||||||
polygon->points.clear();
|
polygon->points.clear();
|
||||||
|
@ -20,17 +20,19 @@ public:
|
|||||||
min(pmin), max(pmax), defined(pmin(0) < pmax(0) && pmin(1) < pmax(1)) {}
|
min(pmin), max(pmax), defined(pmin(0) < pmax(0) && pmin(1) < pmax(1)) {}
|
||||||
BoundingBoxBase(const std::vector<PointClass>& points) : min(PointClass::Zero()), max(PointClass::Zero())
|
BoundingBoxBase(const std::vector<PointClass>& points) : min(PointClass::Zero()), max(PointClass::Zero())
|
||||||
{
|
{
|
||||||
if (points.empty())
|
if (points.empty()) {
|
||||||
throw std::invalid_argument("Empty point set supplied to BoundingBoxBase constructor");
|
this->defined = false;
|
||||||
|
// throw std::invalid_argument("Empty point set supplied to BoundingBoxBase constructor");
|
||||||
typename std::vector<PointClass>::const_iterator it = points.begin();
|
} else {
|
||||||
this->min = *it;
|
typename std::vector<PointClass>::const_iterator it = points.begin();
|
||||||
this->max = *it;
|
this->min = *it;
|
||||||
for (++ it; it != points.end(); ++ it) {
|
this->max = *it;
|
||||||
this->min = this->min.cwiseMin(*it);
|
for (++ it; it != points.end(); ++ it) {
|
||||||
this->max = this->max.cwiseMax(*it);
|
this->min = this->min.cwiseMin(*it);
|
||||||
|
this->max = this->max.cwiseMax(*it);
|
||||||
|
}
|
||||||
|
this->defined = (this->min(0) < this->max(0)) && (this->min(1) < this->max(1));
|
||||||
}
|
}
|
||||||
this->defined = (this->min(0) < this->max(0)) && (this->min(1) < this->max(1));
|
|
||||||
}
|
}
|
||||||
void reset() { this->defined = false; this->min = PointClass::Zero(); this->max = PointClass::Zero(); }
|
void reset() { this->defined = false; this->min = PointClass::Zero(); this->max = PointClass::Zero(); }
|
||||||
void merge(const PointClass &point);
|
void merge(const PointClass &point);
|
||||||
@ -143,7 +145,6 @@ public:
|
|||||||
BoundingBox() : BoundingBoxBase<Point>() {}
|
BoundingBox() : BoundingBoxBase<Point>() {}
|
||||||
BoundingBox(const Point &pmin, const Point &pmax) : BoundingBoxBase<Point>(pmin, pmax) {}
|
BoundingBox(const Point &pmin, const Point &pmax) : BoundingBoxBase<Point>(pmin, pmax) {}
|
||||||
BoundingBox(const Points &points) : BoundingBoxBase<Point>(points) {}
|
BoundingBox(const Points &points) : BoundingBoxBase<Point>(points) {}
|
||||||
BoundingBox(const Lines &lines);
|
|
||||||
|
|
||||||
friend BoundingBox get_extents_rotated(const Points &points, double angle);
|
friend BoundingBox get_extents_rotated(const Points &points, double angle);
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
// Serialization through the Cereal library
|
// Serialization through the Cereal library
|
||||||
#include <cereal/access.hpp>
|
#include <cereal/access.hpp>
|
||||||
|
|
||||||
|
#define BOOST_VORONOI_USE_GMP 1
|
||||||
#include "boost/polygon/voronoi.hpp"
|
#include "boost/polygon/voronoi.hpp"
|
||||||
|
|
||||||
namespace ClipperLib {
|
namespace ClipperLib {
|
||||||
|
@ -125,4 +125,14 @@ Vec3d Linef3::intersect_plane(double z) const
|
|||||||
return Vec3d(this->a(0) + v(0) * t, this->a(1) + v(1) * t, z);
|
return Vec3d(this->a(0) + v(0) * t, this->a(1) + v(1) * t, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoundingBox get_extents(const Lines &lines)
|
||||||
|
{
|
||||||
|
BoundingBox bbox;
|
||||||
|
for (const Line &line : lines) {
|
||||||
|
bbox.merge(line.a);
|
||||||
|
bbox.merge(line.b);
|
||||||
|
}
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,8 @@ public:
|
|||||||
Vec3d b;
|
Vec3d b;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern BoundingBox get_extents(const Lines &lines);
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
// start Boost
|
// start Boost
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <limits> // for numeric_limits
|
#include <limits> // for numeric_limits
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#define BOOST_VORONOI_USE_GMP 1
|
||||||
#include "boost/polygon/voronoi.hpp"
|
#include "boost/polygon/voronoi.hpp"
|
||||||
using boost::polygon::voronoi_builder;
|
using boost::polygon::voronoi_builder;
|
||||||
using boost::polygon::voronoi_diagram;
|
using boost::polygon::voronoi_diagram;
|
||||||
|
@ -12,10 +12,11 @@ add_executable(${_TEST_NAME}_tests
|
|||||||
test_placeholder_parser.cpp
|
test_placeholder_parser.cpp
|
||||||
test_polygon.cpp
|
test_polygon.cpp
|
||||||
test_stl.cpp
|
test_stl.cpp
|
||||||
test_meshsimplify.cpp
|
test_meshsimplify.cpp
|
||||||
test_meshboolean.cpp
|
test_meshboolean.cpp
|
||||||
test_marchingsquares.cpp
|
test_marchingsquares.cpp
|
||||||
test_timeutils.cpp
|
test_timeutils.cpp
|
||||||
|
test_voronoi.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (TARGET OpenVDB::openvdb)
|
if (TARGET OpenVDB::openvdb)
|
||||||
|
1590
tests/libslic3r/test_voronoi.cpp
Normal file
1590
tests/libslic3r/test_voronoi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user