Cleanup of some method signatures and of XS return types

This commit is contained in:
Alessandro Ranellucci 2015-01-19 18:53:04 +01:00
parent c9cdae1a96
commit 8791f5a493
39 changed files with 252 additions and 339 deletions

View file

@ -89,8 +89,7 @@ BridgeDetector::detect_angle()
{
Polygons pp = this->expolygon;
for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
Lines lines;
p->lines(&lines);
Lines lines = p->lines();
for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line)
angles.push_back(line->direction());
}

View file

@ -167,9 +167,11 @@ ExPolygon::medial_axis(double max_width, double min_width, Polylines* polylines)
Slic3r::Geometry::MedialAxis ma(max_width, min_width);
// populate list of segments for the Voronoi diagram
this->contour.lines(&ma.lines);
for (Polygons::const_iterator hole = this->holes.begin(); hole != this->holes.end(); ++hole)
hole->lines(&ma.lines);
ma.lines = this->contour.lines();
for (Polygons::const_iterator hole = this->holes.begin(); hole != this->holes.end(); ++hole) {
Lines lines = hole->lines();
ma.lines.insert(ma.lines.end(), lines.begin(), lines.end());
}
// compute the Voronoi diagram
ma.build(polylines);
@ -384,10 +386,11 @@ ExPolygon::triangulate_p2t(Polygons* polygons) const
Lines
ExPolygon::lines() const
{
Lines lines;
this->contour.lines(&lines);
for (Polygons::const_iterator h = this->holes.begin(); h != this->holes.end(); ++h)
h->lines(&lines);
Lines lines = this->contour.lines();
for (Polygons::const_iterator h = this->holes.begin(); h != this->holes.end(); ++h) {
Lines hole_lines = h->lines();
lines.insert(lines.end(), hole_lines.begin(), hole_lines.end());
}
return lines;
}

View file

@ -92,13 +92,13 @@ ExPolygonCollection::simplify(double tolerance)
this->expolygons = expp;
}
void
ExPolygonCollection::convex_hull(Polygon* hull) const
Polygon
ExPolygonCollection::convex_hull() const
{
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());
Slic3r::Geometry::convex_hull(pp, hull);
return Slic3r::Geometry::convex_hull(pp);
}
Lines

View file

@ -28,7 +28,7 @@ class ExPolygonCollection
template <class T> bool contains(const T &item) const;
bool contains_b(const Point &point) const;
void simplify(double tolerance);
void convex_hull(Polygon* hull) const;
Polygon convex_hull() const;
Lines lines() const;
};

View file

@ -25,42 +25,45 @@ sort_points (Point a, Point b)
}
/* This implementation is based on Andrew's monotone chain 2D convex hull algorithm */
void
convex_hull(Points points, Polygon* hull)
Polygon
convex_hull(Points points)
{
assert(points.size() >= 3);
// sort input points
std::sort(points.begin(), points.end(), sort_points);
int n = points.size(), k = 0;
hull->points.resize(2*n);
Polygon hull;
hull.points.resize(2*n);
// Build lower hull
for (int i = 0; i < n; i++) {
while (k >= 2 && points[i].ccw(hull->points[k-2], hull->points[k-1]) <= 0) k--;
hull->points[k++] = points[i];
while (k >= 2 && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
hull.points[k++] = points[i];
}
// Build upper hull
for (int i = n-2, t = k+1; i >= 0; i--) {
while (k >= t && points[i].ccw(hull->points[k-2], hull->points[k-1]) <= 0) k--;
hull->points[k++] = points[i];
while (k >= t && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
hull.points[k++] = points[i];
}
hull->points.resize(k);
hull.points.resize(k);
assert( hull->points.front().coincides_with(hull->points.back()) );
hull->points.pop_back();
assert( hull.points.front().coincides_with(hull.points.back()) );
hull.points.pop_back();
return hull;
}
void
convex_hull(const Polygons &polygons, Polygon* hull)
Polygon
convex_hull(const Polygons &polygons)
{
Points pp;
for (Polygons::const_iterator p = polygons.begin(); p != polygons.end(); ++p) {
pp.insert(pp.end(), p->points.begin(), p->points.end());
}
convex_hull(pp, hull);
return convex_hull(pp);
}
/* accepts an arrayref of points and returns a list of indices

View file

@ -11,8 +11,8 @@ using boost::polygon::voronoi_diagram;
namespace Slic3r { namespace Geometry {
void convex_hull(Points points, Polygon* hull);
void convex_hull(const Polygons &polygons, Polygon* hull);
Polygon convex_hull(Points points);
Polygon convex_hull(const Polygons &polygons);
void chained_path(const Points &points, std::vector<Points::size_type> &retval, Point start_near);
void chained_path(const Points &points, std::vector<Points::size_type> &retval);
template<class T> void chained_path_items(Points &points, T &items, T &retval);

View file

@ -64,10 +64,10 @@ Line::length() const
return this->a.distance_to(this->b);
}
Point*
Point
Line::midpoint() const
{
return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
return Point((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
}
void

View file

@ -26,7 +26,7 @@ class Line
void rotate(double angle, const Point &center);
void reverse();
double length() const;
Point* midpoint() const;
Point midpoint() const;
void point_at(double distance, Point* point) const;
Point point_at(double distance) const;
bool intersection_infinite(const Line &other, Point* point) const;

View file

@ -130,8 +130,7 @@ Model::duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance)
ModelObject* object = this->objects.front();
object->clear_instances();
BoundingBoxf3 bb;
object->bounding_box(&bb);
BoundingBoxf3 bb = object->bounding_box();
Sizef3 size = bb.size();
for (unsigned int x_copy = 1; x_copy <= x; ++x_copy) {
@ -174,21 +173,20 @@ Model::add_default_instances()
}
// this returns the bounding box of the *transformed* instances
void
Model::bounding_box(BoundingBoxf3* bb)
BoundingBoxf3
Model::bounding_box() const
{
BoundingBoxf3 bb;
for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) {
BoundingBoxf3 obb;
(*o)->bounding_box(&obb);
bb->merge(obb);
bb.merge((*o)->bounding_box());
}
return bb;
}
void
Model::center_instances_around_point(const Pointf &point)
{
BoundingBoxf3 bb;
this->bounding_box(&bb);
BoundingBoxf3 bb = this->bounding_box();
Sizef3 size = bb.size();
double shift_x = -bb.min.x + point.x - size.x/2;
@ -205,8 +203,7 @@ Model::center_instances_around_point(const Pointf &point)
void
Model::align_instances_to_origin()
{
BoundingBoxf3 bb;
this->bounding_box(&bb);
BoundingBoxf3 bb = this->bounding_box();
Pointf new_center = (Pointf)bb.size();
new_center.translate(-new_center.x/2, -new_center.y/2);
@ -222,25 +219,25 @@ Model::translate(coordf_t x, coordf_t y, coordf_t z)
}
// flattens everything to a single mesh
void
Model::mesh(TriangleMesh* mesh) const
TriangleMesh
Model::mesh() const
{
TriangleMesh mesh;
for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) {
TriangleMesh omesh;
(*o)->mesh(&omesh);
mesh->merge(omesh);
mesh.merge((*o)->mesh());
}
return mesh;
}
// flattens everything to a single mesh
void
Model::raw_mesh(TriangleMesh* mesh) const
TriangleMesh
Model::raw_mesh() const
{
TriangleMesh mesh;
for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) {
TriangleMesh omesh;
(*o)->raw_mesh(&omesh);
mesh->merge(omesh);
mesh.merge((*o)->raw_mesh());
}
return mesh;
}
#ifdef SLIC3RXS
@ -393,11 +390,11 @@ ModelObject::clear_instances()
}
// this returns the bounding box of the *transformed* instances
void
ModelObject::bounding_box(BoundingBoxf3* bb)
BoundingBoxf3
ModelObject::bounding_box()
{
if (!this->_bounding_box_valid) this->update_bounding_box();
*bb = this->_bounding_box;
return this->_bounding_box;
}
void
@ -409,40 +406,40 @@ ModelObject::invalidate_bounding_box()
void
ModelObject::update_bounding_box()
{
TriangleMesh mesh;
this->mesh(&mesh);
mesh.bounding_box(&this->_bounding_box);
this->_bounding_box = this->mesh().bounding_box();
this->_bounding_box_valid = true;
}
// flattens all volumes and instances into a single mesh
void
ModelObject::mesh(TriangleMesh* mesh) const
TriangleMesh
ModelObject::mesh() const
{
TriangleMesh raw_mesh;
this->raw_mesh(&raw_mesh);
TriangleMesh mesh;
TriangleMesh raw_mesh = this->raw_mesh();
for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i) {
TriangleMesh m = raw_mesh;
(*i)->transform_mesh(&m);
mesh->merge(m);
mesh.merge(m);
}
return mesh;
}
void
ModelObject::raw_mesh(TriangleMesh* mesh) const
TriangleMesh
ModelObject::raw_mesh() const
{
TriangleMesh mesh;
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
if ((*v)->modifier) continue;
mesh->merge((*v)->mesh);
mesh.merge((*v)->mesh);
}
return mesh;
}
void
ModelObject::raw_bounding_box(BoundingBoxf3* bb) const
BoundingBoxf3
ModelObject::raw_bounding_box() const
{
BoundingBoxf3 bb;
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
if ((*v)->modifier) continue;
TriangleMesh mesh = (*v)->mesh;
@ -450,22 +447,18 @@ ModelObject::raw_bounding_box(BoundingBoxf3* bb) const
if (this->instances.empty()) CONFESS("Can't call raw_bounding_box() with no instances");
this->instances.front()->transform_mesh(&mesh, true);
BoundingBoxf3 mbb;
mesh.bounding_box(&mbb);
bb->merge(mbb);
bb.merge(mesh.bounding_box());
}
return bb;
}
// this returns the bounding box of the *transformed* given instance
void
ModelObject::instance_bounding_box(size_t instance_idx, BoundingBoxf3* bb) const
BoundingBoxf3
ModelObject::instance_bounding_box(size_t instance_idx) const
{
TriangleMesh mesh;
this->raw_mesh(&mesh);
TriangleMesh mesh = this->raw_mesh();
this->instances[instance_idx]->transform_mesh(&mesh);
mesh.bounding_box(bb);
return mesh.bounding_box();
}
void
@ -473,12 +466,7 @@ ModelObject::center_around_origin()
{
// calculate the displacements needed to
// center this object around the origin
BoundingBoxf3 bb;
{
TriangleMesh mesh;
this->raw_mesh(&mesh);
mesh.bounding_box(&bb);
}
BoundingBoxf3 bb = this->raw_mesh().bounding_box();
// first align to origin on XYZ
Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z);

View file

@ -54,12 +54,12 @@ class Model
// void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
bool has_objects_with_no_instances() const;
bool add_default_instances();
void bounding_box(BoundingBoxf3* bb);
BoundingBoxf3 bounding_box() const;
void center_instances_around_point(const Pointf &point);
void align_instances_to_origin();
void translate(coordf_t x, coordf_t y, coordf_t z);
void mesh(TriangleMesh* mesh) const;
void raw_mesh(TriangleMesh* mesh) const;
TriangleMesh mesh() const;
TriangleMesh raw_mesh() const;
// std::string get_material_name(t_model_material_id material_id);
@ -118,13 +118,13 @@ class ModelObject
void delete_last_instance();
void clear_instances();
void bounding_box(BoundingBoxf3* bb);
BoundingBoxf3 bounding_box();
void invalidate_bounding_box();
void mesh(TriangleMesh* mesh) const;
void raw_mesh(TriangleMesh* mesh) const;
void raw_bounding_box(BoundingBoxf3* bb) const;
void instance_bounding_box(size_t instance_idx, BoundingBoxf3* bb) const;
TriangleMesh mesh() const;
TriangleMesh raw_mesh() const;
BoundingBoxf3 raw_bounding_box() const;
BoundingBoxf3 instance_bounding_box(size_t instance_idx) const;
void center_around_origin();
void translate(const Vectorf3 &vector);
void translate(coordf_t x, coordf_t y, coordf_t z);

View file

@ -82,17 +82,18 @@ MotionPlanner::get_env(size_t island_idx) const
}
}
void
MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyline)
Polyline
MotionPlanner::shortest_path(const Point &from, const Point &to)
{
// lazy generation of configuration space
if (!this->initialized) this->initialize();
// if we have an empty configuration space, return a straight move
if (this->islands.empty()) {
polyline->points.push_back(from);
polyline->points.push_back(to);
return;
Polyline p;
p.points.push_back(from);
p.points.push_back(to);
return p;
}
// Are both points in the same island?
@ -102,9 +103,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
// since both points are in the same island, is a direct move possible?
// if so, we avoid generating the visibility environment
if (island->contains(Line(from, to))) {
polyline->points.push_back(from);
polyline->points.push_back(to);
return;
Polyline p;
p.points.push_back(from);
p.points.push_back(to);
return p;
}
island_idx = island - this->islands.begin();
break;
@ -116,9 +118,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
if (env.expolygons.empty()) {
// if this environment is empty (probably because it's too small), perform straight move
// and avoid running the algorithms on empty dataset
polyline->points.push_back(from);
polyline->points.push_back(to);
return; // bye bye
Polyline p;
p.points.push_back(from);
p.points.push_back(to);
return p; // bye bye
}
// Now check whether points are inside the environment.
@ -137,10 +140,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
// perform actual path search
MotionPlannerGraph* graph = this->init_graph(island_idx);
graph->shortest_path(graph->find_node(inner_from), graph->find_node(inner_to), polyline);
Polyline polyline = graph->shortest_path(graph->find_node(inner_from), graph->find_node(inner_to));
polyline->points.insert(polyline->points.begin(), from);
polyline->points.push_back(to);
polyline.points.insert(polyline.points.begin(), from);
polyline.points.push_back(to);
{
// grow our environment slightly in order for simplify_by_visibility()
@ -149,7 +152,7 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
offset(env, &grown_env.expolygons, +SCALED_EPSILON);
// remove unnecessary vertices
polyline->simplify_by_visibility(grown_env);
polyline.simplify_by_visibility(grown_env);
}
/*
@ -171,6 +174,8 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl
svg.draw(*polyline, "red");
svg.Close();
*/
return polyline;
}
Point
@ -310,11 +315,11 @@ MotionPlannerGraph::find_node(const Point &point) const
return point.nearest_point_index(this->nodes);
}
void
MotionPlannerGraph::shortest_path(size_t from, size_t to, Polyline* polyline)
Polyline
MotionPlannerGraph::shortest_path(size_t from, size_t to)
{
// this prevents a crash in case for some reason we got here with an empty adjacency list
if (this->adjacency_list.empty()) return;
if (this->adjacency_list.empty()) return Polyline();
const weight_t max_weight = std::numeric_limits<weight_t>::infinity();
@ -379,10 +384,12 @@ MotionPlannerGraph::shortest_path(size_t from, size_t to, Polyline* polyline)
}
}
Polyline polyline;
for (node_t vertex = to; vertex != -1; vertex = previous[vertex])
polyline->points.push_back(this->nodes[vertex]);
polyline->points.push_back(this->nodes[from]);
polyline->reverse();
polyline.points.push_back(this->nodes[vertex]);
polyline.points.push_back(this->nodes[from]);
polyline.reverse();
return polyline;
}
#ifdef SLIC3RXS

View file

@ -21,7 +21,7 @@ class MotionPlanner
public:
MotionPlanner(const ExPolygons &islands);
~MotionPlanner();
void shortest_path(const Point &from, const Point &to, Polyline* polyline);
Polyline shortest_path(const Point &from, const Point &to);
size_t islands_count() const;
private:
@ -58,7 +58,7 @@ class MotionPlannerGraph
//std::map<std::pair<size_t,size_t>, double> edges;
void add_edge(size_t from, size_t to, double weight);
size_t find_node(const Point &point) const;
void shortest_path(size_t from, size_t to, Polyline* polyline);
Polyline shortest_path(size_t from, size_t to);
};
}

View file

@ -83,10 +83,10 @@ MultiPoint::has_boundary_point(const Point &point) const
return dist < SCALED_EPSILON;
}
void
MultiPoint::bounding_box(BoundingBox* bb) const
BoundingBox
MultiPoint::bounding_box() const
{
*bb = BoundingBox(this->points);
return BoundingBox(this->points);
}
Points

View file

@ -31,7 +31,7 @@ class MultiPoint
bool is_valid() const;
int find_point(const Point &point) const;
bool has_boundary_point(const Point &point) const;
void bounding_box(BoundingBox* bb) const;
BoundingBox bounding_box() const;
static Points _douglas_peucker(const Points &points, const double tolerance);

View file

@ -14,9 +14,7 @@ Polygon::operator Polygons() const
Polygon::operator Polyline() const
{
Polyline polyline;
this->split_at_first_point(&polyline);
return polyline;
return this->split_at_first_point();
}
Point&
@ -41,55 +39,49 @@ Lines
Polygon::lines() const
{
Lines lines;
this->lines(&lines);
lines.reserve(this->points.size());
for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) {
lines.push_back(Line(*it, *(it + 1)));
}
lines.push_back(Line(this->points.back(), this->points.front()));
return lines;
}
void
Polygon::lines(Lines* lines) const
{
lines->reserve(lines->size() + this->points.size());
for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) {
lines->push_back(Line(*it, *(it + 1)));
}
lines->push_back(Line(this->points.back(), this->points.front()));
}
void
Polygon::split_at_vertex(const Point &point, Polyline* polyline) const
Polyline
Polygon::split_at_vertex(const Point &point) const
{
// find index of point
for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
if (it->coincides_with(point)) {
this->split_at_index(it - this->points.begin(), polyline);
return;
return this->split_at_index(it - this->points.begin());
}
}
CONFESS("Point not found");
return Polyline();
}
void
Polygon::split_at_index(int index, Polyline* polyline) const
{
polyline->points.reserve(this->points.size() + 1);
for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it)
polyline->points.push_back(*it);
for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it)
polyline->points.push_back(*it);
}
void
Polygon::split_at_first_point(Polyline* polyline) const
{
this->split_at_index(0, polyline);
}
void
Polygon::equally_spaced_points(double distance, Points* points) const
Polyline
Polygon::split_at_index(int index) const
{
Polyline polyline;
this->split_at_first_point(&polyline);
polyline.equally_spaced_points(distance, points);
polyline.points.reserve(this->points.size() + 1);
for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it)
polyline.points.push_back(*it);
for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it)
polyline.points.push_back(*it);
return polyline;
}
Polyline
Polygon::split_at_first_point() const
{
return this->split_at_index(0);
}
Points
Polygon::equally_spaced_points(double distance) const
{
return this->split_at_first_point().equally_spaced_points(distance);
}
double
@ -203,8 +195,7 @@ Polygon::centroid() const
double x_temp = 0;
double y_temp = 0;
Polyline polyline;
this->split_at_first_point(&polyline);
Polyline polyline = this->split_at_first_point();
for (Points::const_iterator point = polyline.points.begin(); point != polyline.points.end() - 1; ++point) {
x_temp += (double)( point->x + (point+1)->x ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y );
y_temp += (double)( point->y + (point+1)->y ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y );
@ -227,55 +218,49 @@ Polygon::wkt() const
}
// find all concave vertices (i.e. having an internal angle greater than the supplied angle) */
void
Polygon::concave_points(double angle, Points* points) const
Points
Polygon::concave_points(double angle) const
{
Points points;
angle = 2*PI - angle;
// check whether first point forms a concave angle
if (this->points.front().ccw_angle(this->points.back(), *(this->points.begin()+1)) <= angle)
points->push_back(this->points.front());
points.push_back(this->points.front());
// check whether points 1..(n-1) form concave angles
for (Points::const_iterator p = this->points.begin()+1; p != this->points.end()-1; ++p) {
if (p->ccw_angle(*(p-1), *(p+1)) <= angle) points->push_back(*p);
if (p->ccw_angle(*(p-1), *(p+1)) <= angle) points.push_back(*p);
}
// check whether last point forms a concave angle
if (this->points.back().ccw_angle(*(this->points.end()-2), this->points.front()) <= angle)
points->push_back(this->points.back());
}
void
Polygon::concave_points(Points* points) const
{
this->concave_points(PI, points);
points.push_back(this->points.back());
return points;
}
// find all convex vertices (i.e. having an internal angle smaller than the supplied angle) */
void
Polygon::convex_points(double angle, Points* points) const
Points
Polygon::convex_points(double angle) const
{
Points points;
angle = 2*PI - angle;
// check whether first point forms a convex angle
if (this->points.front().ccw_angle(this->points.back(), *(this->points.begin()+1)) >= angle)
points->push_back(this->points.front());
points.push_back(this->points.front());
// check whether points 1..(n-1) form convex angles
for (Points::const_iterator p = this->points.begin()+1; p != this->points.end()-1; ++p) {
if (p->ccw_angle(*(p-1), *(p+1)) >= angle) points->push_back(*p);
if (p->ccw_angle(*(p-1), *(p+1)) >= angle) points.push_back(*p);
}
// check whether last point forms a convex angle
if (this->points.back().ccw_angle(*(this->points.end()-2), this->points.front()) >= angle)
points->push_back(this->points.back());
}
void
Polygon::convex_points(Points* points) const
{
this->convex_points(PI, points);
points.push_back(this->points.back());
return points;
}
#ifdef SLIC3RXS

View file

@ -24,11 +24,10 @@ class Polygon : public MultiPoint {
explicit Polygon(const Points &points): MultiPoint(points) {};
Point last_point() const;
Lines lines() const;
void lines(Lines* lines) const;
void split_at_vertex(const Point &point, Polyline* polyline) const;
void split_at_index(int index, Polyline* polyline) const;
void split_at_first_point(Polyline* polyline) const;
void equally_spaced_points(double distance, Points* points) const;
Polyline split_at_vertex(const Point &point) const;
Polyline split_at_index(int index) const;
Polyline split_at_first_point() const;
Points equally_spaced_points(double distance) const;
double area() const;
bool is_counter_clockwise() const;
bool is_clockwise() const;
@ -41,10 +40,8 @@ class Polygon : public MultiPoint {
void triangulate_convex(Polygons* polygons) const;
Point centroid() const;
std::string wkt() const;
void concave_points(double angle, Points* points) const;
void concave_points(Points* points) const;
void convex_points(double angle, Points* points) const;
void convex_points(Points* points) const;
Points concave_points(double angle = PI) const;
Points convex_points(double angle = PI) const;
#ifdef SLIC3RXS
void from_SV_check(SV* poly_sv);

View file

@ -98,10 +98,11 @@ Polyline::extend_start(double distance)
/* this method returns a collection of points picked on the polygon contour
so that they are evenly spaced according to the input distance */
void
Polyline::equally_spaced_points(double distance, Points* points) const
Points
Polyline::equally_spaced_points(double distance) const
{
points->push_back(this->first_point());
Points points;
points.push_back(this->first_point());
double len = 0;
for (Points::const_iterator it = this->points.begin() + 1; it != this->points.end(); ++it) {
@ -110,17 +111,18 @@ Polyline::equally_spaced_points(double distance, Points* points) const
if (len < distance) continue;
if (len == distance) {
points->push_back(*it);
points.push_back(*it);
len = 0;
continue;
}
double take = segment_length - (len - distance); // how much we take of this segment
Line segment(*(it-1), *it);
points->push_back(segment.point_at(take));
points.push_back(segment.point_at(take));
it--;
len = -take;
}
return points;
}
void

View file

@ -22,7 +22,7 @@ class Polyline : public MultiPoint {
void clip_start(double distance);
void extend_end(double distance);
void extend_start(double distance);
void equally_spaced_points(double distance, Points* points) const;
Points equally_spaced_points(double distance) const;
void simplify(double tolerance);
template <class T> void simplify_by_visibility(const T &area);
void split_at(const Point &point, Polyline* p1, Polyline* p2) const;

View file

@ -358,8 +358,7 @@ Print::add_model_object(ModelObject* model_object, int idx)
// initialize print object and store it at the given position
PrintObject* o;
{
BoundingBoxf3 bb;
model_object->raw_bounding_box(&bb);
BoundingBoxf3 bb = model_object->raw_bounding_box();
if (idx != -1) {
// replacing existing object
PrintObjectPtrs::iterator old_it = this->objects.begin() + idx;
@ -569,14 +568,13 @@ Print::validate() const
Polygons mesh_convex_hulls;
for (size_t i = 0; i < this->regions.size(); ++i) {
for (std::vector<int>::const_iterator it = object->region_volumes[i].begin(); it != object->region_volumes[i].end(); ++it) {
Polygon hull;
object->model_object()->volumes[*it]->mesh.convex_hull(&hull);
Polygon hull = object->model_object()->volumes[*it]->mesh.convex_hull();
mesh_convex_hulls.push_back(hull);
}
}
// make a single convex hull for all of them
Slic3r::Geometry::convex_hull(mesh_convex_hulls, &convex_hull);
convex_hull = Slic3r::Geometry::convex_hull(mesh_convex_hulls);
}
// apply the same transformations we apply to the actual meshes when slicing them

View file

@ -111,7 +111,7 @@ class PrintObject
bool delete_all_copies();
bool set_copies(const Points &points);
bool reload_model_instances();
void bounding_box(BoundingBox* bb) const;
BoundingBox bounding_box() const;
// adds region_id, too, if necessary
void add_region_volume(int region_id, int volume_id);

View file

@ -110,14 +110,14 @@ PrintObject::reload_model_instances()
return this->set_copies(copies);
}
void
PrintObject::bounding_box(BoundingBox* bb) const
BoundingBox
PrintObject::bounding_box() const
{
// since the object is aligned to origin, bounding box coincides with size
Points pp;
pp.push_back(Point(0,0));
pp.push_back(this->size);
*bb = BoundingBox(pp);
return BoundingBox(pp);
}
void

View file

@ -319,8 +319,8 @@ TriangleMesh::merge(const TriangleMesh &mesh)
}
/* this will return scaled ExPolygons */
void
TriangleMesh::horizontal_projection(ExPolygons &retval) const
ExPolygons
TriangleMesh::horizontal_projection() const
{
Polygons pp;
pp.reserve(this->stl.stats.number_of_facets);
@ -337,11 +337,13 @@ TriangleMesh::horizontal_projection(ExPolygons &retval) const
// the offset factor was tuned using groovemount.stl
offset(pp, &pp, 0.01 / SCALING_FACTOR);
ExPolygons retval;
union_(pp, &retval, true);
return retval;
}
void
TriangleMesh::convex_hull(Polygon* hull)
Polygon
TriangleMesh::convex_hull()
{
this->require_shared_vertices();
Points pp;
@ -350,25 +352,19 @@ TriangleMesh::convex_hull(Polygon* hull)
stl_vertex* v = &this->stl.v_shared[i];
pp.push_back(Point(v->x / SCALING_FACTOR, v->y / SCALING_FACTOR));
}
Slic3r::Geometry::convex_hull(pp, hull);
}
void
TriangleMesh::bounding_box(BoundingBoxf3* bb) const
{
bb->min.x = this->stl.stats.min.x;
bb->min.y = this->stl.stats.min.y;
bb->min.z = this->stl.stats.min.z;
bb->max.x = this->stl.stats.max.x;
bb->max.y = this->stl.stats.max.y;
bb->max.z = this->stl.stats.max.z;
return Slic3r::Geometry::convex_hull(pp);
}
BoundingBoxf3
TriangleMesh::bounding_box() const
{
BoundingBoxf3 bb;
this->bounding_box(&bb);
bb.min.x = this->stl.stats.min.x;
bb.min.y = this->stl.stats.min.y;
bb.min.z = this->stl.stats.min.z;
bb.max.x = this->stl.stats.max.x;
bb.max.y = this->stl.stats.max.y;
bb.max.z = this->stl.stats.max.z;
return bb;
}

View file

@ -42,9 +42,8 @@ class TriangleMesh
void rotate(double angle, Point* center);
TriangleMeshPtrs split() const;
void merge(const TriangleMesh &mesh);
void horizontal_projection(ExPolygons &retval) const;
void convex_hull(Polygon* hull);
void bounding_box(BoundingBoxf3* bb) const;
ExPolygons horizontal_projection() const;
Polygon convex_hull();
BoundingBoxf3 bounding_box() const;
void reset_repair_stats();
bool needed_repair() const;