2013-07-16 19:04:14 +00:00
|
|
|
#include "ExPolygonCollection.hpp"
|
New BuildVolume class was created, which detects build volume type (rectangular,
circular, convex, concave) and performs efficient collision detection agains these build
volumes. As of now, collision detection is performed against a convex
hull of a concave build volume for efficency.
GCodeProcessor::Result renamed out of GCodeProcessor to GCodeProcessorResult,
so it could be forward declared.
Plater newly exports BuildVolume, not Bed3D. Bed3D is a rendering class,
while BuildVolume is a purely geometric class.
Reduced usage of global wxGetApp, the Bed3D is passed as a parameter
to View3D/Preview/GLCanvas.
Convex hull code was extracted from Geometry.cpp/hpp to Geometry/ConvexHulll.cpp,hpp.
New test inside_convex_polygon().
New efficent point inside polygon test: Decompose convex hull
to bottom / top parts and use the decomposition to detect point inside
a convex polygon in O(log n). decompose_convex_polygon_top_bottom(),
inside_convex_polygon().
New Circle constructing functions: circle_ransac() and circle_taubin_newton().
New polygon_is_convex() test with unit tests.
2021-11-16 09:15:51 +00:00
|
|
|
#include "Geometry/ConvexHull.hpp"
|
2021-11-16 15:08:16 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2013-07-16 19:04:14 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2015-01-06 19:52:36 +00:00
|
|
|
ExPolygonCollection::ExPolygonCollection(const ExPolygon &expolygon)
|
|
|
|
{
|
|
|
|
this->expolygons.push_back(expolygon);
|
|
|
|
}
|
|
|
|
|
2014-05-13 18:06:01 +00:00
|
|
|
ExPolygonCollection::operator Points() const
|
|
|
|
{
|
|
|
|
Points points;
|
2019-10-04 14:50:01 +00:00
|
|
|
Polygons pp = (Polygons)*this;
|
2014-05-13 18:06:01 +00:00
|
|
|
for (Polygons::const_iterator poly = pp.begin(); poly != pp.end(); ++poly) {
|
|
|
|
for (Points::const_iterator point = poly->points.begin(); point != poly->points.end(); ++point)
|
|
|
|
points.push_back(*point);
|
|
|
|
}
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
ExPolygonCollection::operator Polygons() const
|
|
|
|
{
|
|
|
|
Polygons polygons;
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
polygons.push_back(it->contour);
|
|
|
|
for (Polygons::const_iterator ith = it->holes.begin(); ith != it->holes.end(); ++ith) {
|
|
|
|
polygons.push_back(*ith);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return polygons;
|
|
|
|
}
|
|
|
|
|
2014-05-13 18:06:01 +00:00
|
|
|
ExPolygonCollection::operator ExPolygons&()
|
|
|
|
{
|
|
|
|
return this->expolygons;
|
|
|
|
}
|
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
void
|
|
|
|
ExPolygonCollection::scale(double factor)
|
|
|
|
{
|
2013-08-08 00:10:34 +00:00
|
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
|
|
(*it).scale(factor);
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ExPolygonCollection::translate(double x, double y)
|
|
|
|
{
|
2013-08-08 00:10:34 +00:00
|
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
|
|
(*it).translate(x, y);
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-24 11:43:24 +00:00
|
|
|
ExPolygonCollection::rotate(double angle, const Point ¢er)
|
2013-07-16 19:04:14 +00:00
|
|
|
{
|
2013-08-08 00:10:34 +00:00
|
|
|
for (ExPolygons::iterator it = expolygons.begin(); it != expolygons.end(); ++it) {
|
|
|
|
(*it).rotate(angle, center);
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-23 19:14:13 +00:00
|
|
|
template <class T>
|
2018-09-17 13:12:13 +00:00
|
|
|
bool ExPolygonCollection::contains(const T &item) const
|
2013-11-21 16:53:50 +00:00
|
|
|
{
|
2018-09-17 13:12:13 +00:00
|
|
|
for (const ExPolygon &poly : this->expolygons)
|
|
|
|
if (poly.contains(item))
|
|
|
|
return true;
|
2014-11-23 19:03:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-23 19:14:13 +00:00
|
|
|
template bool ExPolygonCollection::contains<Point>(const Point &item) const;
|
|
|
|
template bool ExPolygonCollection::contains<Line>(const Line &item) const;
|
|
|
|
template bool ExPolygonCollection::contains<Polyline>(const Polyline &item) const;
|
2014-11-23 19:03:16 +00:00
|
|
|
|
2015-01-06 19:52:36 +00:00
|
|
|
bool
|
|
|
|
ExPolygonCollection::contains_b(const Point &point) const
|
|
|
|
{
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
if (it->contains_b(point)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-21 19:25:24 +00:00
|
|
|
void
|
|
|
|
ExPolygonCollection::simplify(double tolerance)
|
|
|
|
{
|
2013-11-22 01:16:10 +00:00
|
|
|
ExPolygons expp;
|
2013-11-21 19:25:24 +00:00
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
2015-12-21 13:46:35 +00:00
|
|
|
it->simplify(tolerance, &expp);
|
2013-11-21 19:25:24 +00:00
|
|
|
}
|
2013-11-22 01:16:10 +00:00
|
|
|
this->expolygons = expp;
|
2013-11-21 19:25:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 17:53:04 +00:00
|
|
|
Polygon
|
|
|
|
ExPolygonCollection::convex_hull() const
|
2013-12-12 19:19:33 +00:00
|
|
|
{
|
|
|
|
Points pp;
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it)
|
|
|
|
pp.insert(pp.end(), it->contour.points.begin(), it->contour.points.end());
|
2015-01-19 17:53:04 +00:00
|
|
|
return Slic3r::Geometry::convex_hull(pp);
|
2013-12-12 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:52:36 +00:00
|
|
|
Lines
|
|
|
|
ExPolygonCollection::lines() const
|
|
|
|
{
|
|
|
|
Lines lines;
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
|
|
|
|
Lines ex_lines = it->lines();
|
|
|
|
lines.insert(lines.end(), ex_lines.begin(), ex_lines.end());
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2015-02-27 20:55:02 +00:00
|
|
|
Polygons
|
|
|
|
ExPolygonCollection::contours() const
|
|
|
|
{
|
|
|
|
Polygons contours;
|
2016-11-08 08:59:25 +00:00
|
|
|
contours.reserve(this->expolygons.size());
|
|
|
|
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it)
|
2015-02-27 20:55:02 +00:00
|
|
|
contours.push_back(it->contour);
|
|
|
|
return contours;
|
|
|
|
}
|
|
|
|
|
2015-10-26 22:23:03 +00:00
|
|
|
void
|
|
|
|
ExPolygonCollection::append(const ExPolygons &expp)
|
|
|
|
{
|
|
|
|
this->expolygons.insert(this->expolygons.end(), expp.begin(), expp.end());
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
BoundingBox get_extents(const ExPolygonCollection &expolygon)
|
|
|
|
{
|
|
|
|
return get_extents(expolygon.expolygons);
|
|
|
|
}
|
|
|
|
|
2013-07-16 19:04:14 +00:00
|
|
|
}
|