2013-07-14 14:09:54 +00:00
|
|
|
#ifndef slic3r_Polyline_hpp_
|
|
|
|
#define slic3r_Polyline_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-15 20:57:22 +00:00
|
|
|
#include "Line.hpp"
|
|
|
|
#include "MultiPoint.hpp"
|
2014-11-15 22:06:15 +00:00
|
|
|
#include <string>
|
2016-03-19 14:33:58 +00:00
|
|
|
#include <vector>
|
2013-07-14 14:09:54 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
class Polyline;
|
2016-03-19 14:33:58 +00:00
|
|
|
class ThickPolyline;
|
2013-11-21 16:53:50 +00:00
|
|
|
typedef std::vector<Polyline> Polylines;
|
2016-03-19 14:33:58 +00:00
|
|
|
typedef std::vector<ThickPolyline> ThickPolylines;
|
2013-11-21 16:53:50 +00:00
|
|
|
|
2013-07-15 20:57:22 +00:00
|
|
|
class Polyline : public MultiPoint {
|
2017-01-19 12:43:29 +00:00
|
|
|
public:
|
|
|
|
Polyline() {};
|
|
|
|
Polyline(const Polyline &other) : MultiPoint(other.points) {}
|
|
|
|
Polyline(Polyline &&other) : MultiPoint(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
|
|
|
Polyline(std::initializer_list<Point> list) : MultiPoint(list) {}
|
|
|
|
explicit Polyline(const Point &p1, const Point &p2) { points.reserve(2); points.emplace_back(p1); points.emplace_back(p2); }
|
2018-09-17 13:12:13 +00:00
|
|
|
explicit Polyline(const Points &points) : MultiPoint(points) {}
|
|
|
|
explicit Polyline(Points &&points) : MultiPoint(std::move(points)) {}
|
2017-01-19 12:43:29 +00:00
|
|
|
Polyline& operator=(const Polyline &other) { points = other.points; return *this; }
|
|
|
|
Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; }
|
2018-08-21 19:05:24 +00:00
|
|
|
static Polyline new_scale(const std::vector<Vec2d> &points) {
|
2018-01-30 11:10:12 +00:00
|
|
|
Polyline pl;
|
2018-08-21 18:34:45 +00:00
|
|
|
pl.points.reserve(points.size());
|
2018-08-21 19:05:24 +00:00
|
|
|
for (const Vec2d &pt : points)
|
2018-08-21 18:34:45 +00:00
|
|
|
pl.points.emplace_back(Point::new_scale(pt(0), pt(1)));
|
2018-01-30 11:10:12 +00:00
|
|
|
return pl;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
void append(const Polyline &src)
|
|
|
|
{
|
|
|
|
points.insert(points.end(), src.points.begin(), src.points.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
void append(Polyline &&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.points);
|
2017-01-20 13:39:44 +00:00
|
|
|
} else {
|
|
|
|
this->points.insert(this->points.end(), src.points.begin(), src.points.end());
|
|
|
|
src.points.clear();
|
|
|
|
}
|
2017-01-19 12:43:29 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
operator Polylines() const;
|
2014-11-15 21:41:22 +00:00
|
|
|
operator Line() const;
|
2014-04-24 14:40:10 +00:00
|
|
|
Point last_point() const;
|
|
|
|
Point leftmost_point() const;
|
2016-03-19 14:33:58 +00:00
|
|
|
virtual Lines lines() const;
|
2013-10-27 21:57:25 +00:00
|
|
|
void clip_end(double distance);
|
2013-11-06 18:30:45 +00:00
|
|
|
void clip_start(double distance);
|
2014-03-15 15:53:20 +00:00
|
|
|
void extend_end(double distance);
|
|
|
|
void extend_start(double distance);
|
2015-01-19 17:53:04 +00:00
|
|
|
Points equally_spaced_points(double distance) const;
|
2013-11-22 01:16:10 +00:00
|
|
|
void simplify(double tolerance);
|
2015-01-06 19:52:36 +00:00
|
|
|
template <class T> void simplify_by_visibility(const T &area);
|
2014-05-22 10:28:12 +00:00
|
|
|
void split_at(const Point &point, Polyline* p1, Polyline* p2) const;
|
2014-11-15 22:06:15 +00:00
|
|
|
bool is_straight() const;
|
2013-07-14 14:09:54 +00:00
|
|
|
};
|
|
|
|
|
2016-09-30 13:23:18 +00:00
|
|
|
extern BoundingBox get_extents(const Polyline &polyline);
|
|
|
|
extern BoundingBox get_extents(const Polylines &polylines);
|
|
|
|
|
2017-02-02 15:03:32 +00:00
|
|
|
inline double total_length(const Polylines &polylines) {
|
|
|
|
double total = 0;
|
2018-12-11 15:33:43 +00:00
|
|
|
for (const Polyline &pl : polylines)
|
|
|
|
total += pl.length();
|
2017-02-02 15:03:32 +00:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2016-11-07 21:49:11 +00:00
|
|
|
inline Lines to_lines(const Polyline &poly)
|
|
|
|
{
|
|
|
|
Lines lines;
|
|
|
|
if (poly.points.size() >= 2) {
|
|
|
|
lines.reserve(poly.points.size() - 1);
|
|
|
|
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
|
|
|
lines.push_back(Line(*it, *(it + 1)));
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Lines to_lines(const Polylines &polys)
|
|
|
|
{
|
|
|
|
size_t n_lines = 0;
|
|
|
|
for (size_t i = 0; i < polys.size(); ++ i)
|
|
|
|
if (polys[i].points.size() > 1)
|
|
|
|
n_lines += polys[i].points.size() - 1;
|
|
|
|
Lines lines;
|
|
|
|
lines.reserve(n_lines);
|
|
|
|
for (size_t i = 0; i < polys.size(); ++ i) {
|
|
|
|
const Polyline &poly = polys[i];
|
|
|
|
for (Points::const_iterator it = poly.points.begin(); it != poly.points.end()-1; ++it)
|
|
|
|
lines.push_back(Line(*it, *(it + 1)));
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2017-01-19 12:43:29 +00:00
|
|
|
inline void polylines_append(Polylines &dst, const Polylines &src)
|
|
|
|
{
|
|
|
|
dst.insert(dst.end(), src.begin(), src.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void polylines_append(Polylines &dst, Polylines &&src)
|
|
|
|
{
|
2017-01-20 13:39:44 +00:00
|
|
|
if (dst.empty()) {
|
2017-01-19 12:43:29 +00:00
|
|
|
dst = std::move(src);
|
2017-01-20 13:39:44 +00:00
|
|
|
} else {
|
2017-01-19 12:43:29 +00:00
|
|
|
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
2017-01-20 13:39:44 +00:00
|
|
|
src.clear();
|
|
|
|
}
|
2017-01-19 12:43:29 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 17:23:57 +00:00
|
|
|
bool remove_degenerate(Polylines &polylines);
|
|
|
|
|
2016-03-19 14:33:58 +00:00
|
|
|
class ThickPolyline : public Polyline {
|
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
|
|
|
public:
|
|
|
|
ThickPolyline() : endpoints(std::make_pair(false, false)) {}
|
2016-03-19 14:33:58 +00:00
|
|
|
ThickLines thicklines() 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
|
|
|
void reverse() {
|
|
|
|
Polyline::reverse();
|
|
|
|
std::reverse(this->width.begin(), this->width.end());
|
|
|
|
std::swap(this->endpoints.first, this->endpoints.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<coordf_t> width;
|
|
|
|
std::pair<bool,bool> endpoints;
|
2016-03-19 14:33:58 +00:00
|
|
|
};
|
|
|
|
|
2018-01-08 12:44:10 +00:00
|
|
|
class Polyline3 : public MultiPoint3
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual Lines3 lines() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Polyline3> Polylines3;
|
|
|
|
|
2013-07-14 14:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|