2013-07-15 20:57:22 +00:00
|
|
|
#ifndef slic3r_MultiPoint_hpp_
|
|
|
|
#define slic3r_MultiPoint_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-15 20:57:22 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2014-05-22 17:34:49 +00:00
|
|
|
#include "Line.hpp"
|
|
|
|
#include "Point.hpp"
|
2013-07-15 20:57:22 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2014-05-22 17:34:49 +00:00
|
|
|
class BoundingBox;
|
2018-01-08 12:44:10 +00:00
|
|
|
class BoundingBox3;
|
2014-05-22 17:34:49 +00:00
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
class MultiPoint
|
|
|
|
{
|
2017-06-08 09:02:29 +00:00
|
|
|
public:
|
2013-07-15 20:57:22 +00:00
|
|
|
Points points;
|
2014-05-22 17:34:49 +00:00
|
|
|
|
|
|
|
operator Points() const;
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
MultiPoint() {}
|
2017-01-19 12:43:29 +00:00
|
|
|
MultiPoint(const MultiPoint &other) : points(other.points) {}
|
|
|
|
MultiPoint(MultiPoint &&other) : points(std::move(other.points)) {}
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
MultiPoint(std::initializer_list<Point> list) : points(list) {}
|
|
|
|
explicit MultiPoint(const Points &_points) : points(_points) {}
|
2017-01-19 12:43:29 +00:00
|
|
|
MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; }
|
|
|
|
MultiPoint& operator=(MultiPoint &&other) { points = std::move(other.points); return *this; }
|
2013-07-15 20:57:22 +00:00
|
|
|
void scale(double factor);
|
2018-09-24 13:54:09 +00:00
|
|
|
void scale(double factor_x, double factor_y);
|
2013-07-15 20:57:22 +00:00
|
|
|
void translate(double x, double y);
|
2014-11-09 14:27:34 +00:00
|
|
|
void translate(const Point &vector);
|
2017-06-08 12:02:37 +00:00
|
|
|
void rotate(double angle) { this->rotate(cos(angle), sin(angle)); }
|
|
|
|
void rotate(double cos_angle, double sin_angle);
|
2014-04-24 11:43:24 +00:00
|
|
|
void rotate(double angle, const Point ¢er);
|
2013-07-15 20:57:22 +00:00
|
|
|
void reverse();
|
2014-04-24 14:40:10 +00:00
|
|
|
Point first_point() const;
|
2019-09-27 16:17:21 +00:00
|
|
|
virtual const Point& last_point() const = 0;
|
2013-10-27 21:57:25 +00:00
|
|
|
virtual Lines lines() const = 0;
|
2018-09-17 13:12:13 +00:00
|
|
|
size_t size() const { return points.size(); }
|
|
|
|
bool empty() const { return points.empty(); }
|
2013-10-27 21:57:25 +00:00
|
|
|
double length() const;
|
2018-09-17 13:12:13 +00:00
|
|
|
bool is_valid() const { return this->points.size() >= 2; }
|
2016-09-13 07:46:41 +00:00
|
|
|
|
2017-06-08 09:02:29 +00:00
|
|
|
int find_point(const Point &point) const;
|
2015-01-06 19:52:36 +00:00
|
|
|
bool has_boundary_point(const Point &point) const;
|
2017-06-08 09:02:29 +00:00
|
|
|
int closest_point_index(const Point &point) const {
|
|
|
|
int idx = -1;
|
|
|
|
if (! this->points.empty()) {
|
|
|
|
idx = 0;
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
double dist_min = (point - this->points.front()).cast<double>().norm();
|
2017-06-08 09:02:29 +00:00
|
|
|
for (int i = 1; i < int(this->points.size()); ++ i) {
|
Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
2018-08-17 12:14:24 +00:00
|
|
|
double d = (this->points[i] - point).cast<double>().norm();
|
2017-06-08 09:02:29 +00:00
|
|
|
if (d < dist_min) {
|
|
|
|
dist_min = d;
|
|
|
|
idx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
const Point* closest_point(const Point &point) const { return this->points.empty() ? nullptr : &this->points[this->closest_point_index(point)]; }
|
2015-01-19 17:53:04 +00:00
|
|
|
BoundingBox bounding_box() const;
|
2016-04-15 16:01:08 +00:00
|
|
|
// Return true if there are exact duplicates.
|
|
|
|
bool has_duplicate_points() const;
|
|
|
|
// Remove exact duplicates, return true if any duplicate has been removed.
|
|
|
|
bool remove_duplicate_points();
|
2017-01-19 12:43:29 +00:00
|
|
|
void append(const Point &point) { this->points.push_back(point); }
|
|
|
|
void append(const Points &src) { this->append(src.begin(), src.end()); }
|
|
|
|
void append(const Points::const_iterator &begin, const Points::const_iterator &end) { this->points.insert(this->points.end(), begin, end); }
|
|
|
|
void append(Points &&src)
|
|
|
|
{
|
2017-01-20 13:39:44 +00:00
|
|
|
if (this->points.empty()) {
|
2017-01-19 12:43:29 +00:00
|
|
|
this->points = std::move(src);
|
2017-01-20 13:39:44 +00:00
|
|
|
} else {
|
|
|
|
this->points.insert(this->points.end(), src.begin(), src.end());
|
|
|
|
src.clear();
|
|
|
|
}
|
2017-01-19 12:43:29 +00:00
|
|
|
}
|
|
|
|
|
2016-03-19 14:33:58 +00:00
|
|
|
bool intersection(const Line& line, Point* intersection) const;
|
2017-06-08 09:02:29 +00:00
|
|
|
bool first_intersection(const Line& line, Point* intersection) const;
|
2014-05-22 17:34:49 +00:00
|
|
|
|
2013-11-22 15:01:50 +00:00
|
|
|
static Points _douglas_peucker(const Points &points, const double tolerance);
|
2018-12-05 15:11:00 +00:00
|
|
|
static Points visivalingam(const Points& pts, const double& tolerance);
|
2013-07-15 20:57:22 +00:00
|
|
|
};
|
|
|
|
|
2018-01-08 12:44:10 +00:00
|
|
|
class MultiPoint3
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Points3 points;
|
|
|
|
|
2018-08-21 20:14:47 +00:00
|
|
|
void append(const Vec3crd& point) { this->points.push_back(point); }
|
2018-01-08 12:44:10 +00:00
|
|
|
|
|
|
|
void translate(double x, double y);
|
|
|
|
void translate(const Point& vector);
|
|
|
|
virtual Lines3 lines() const = 0;
|
|
|
|
double length() const;
|
|
|
|
bool is_valid() const { return this->points.size() >= 2; }
|
|
|
|
|
|
|
|
BoundingBox3 bounding_box() const;
|
|
|
|
|
|
|
|
// Remove exact duplicates, return true if any duplicate has been removed.
|
|
|
|
bool remove_duplicate_points();
|
|
|
|
};
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
extern BoundingBox get_extents(const MultiPoint &mp);
|
2016-11-07 21:49:11 +00:00
|
|
|
extern BoundingBox get_extents_rotated(const std::vector<Point> &points, double angle);
|
|
|
|
extern BoundingBox get_extents_rotated(const MultiPoint &mp, double angle);
|
2016-09-13 11:30:00 +00:00
|
|
|
|
2018-12-11 15:33:43 +00:00
|
|
|
inline double length(const Points &pts) {
|
|
|
|
double total = 0;
|
|
|
|
if (! pts.empty()) {
|
|
|
|
auto it = pts.begin();
|
|
|
|
for (auto it_prev = it ++; it != pts.end(); ++ it, ++ it_prev)
|
|
|
|
total += (*it - *it_prev).cast<double>().norm();
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double area(const Points &polygon) {
|
|
|
|
double area = 0.;
|
|
|
|
for (size_t i = 0, j = polygon.size() - 1; i < polygon.size(); j = i ++)
|
|
|
|
area += double(polygon[i](0) + polygon[j](0)) * double(polygon[i](1) - polygon[j](1));
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
} // namespace Slic3r
|
2013-07-15 20:57:22 +00:00
|
|
|
|
|
|
|
#endif
|