Skip to content

Commit

Permalink
New TriangleMesh::convex_hull()
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Nov 24, 2013
1 parent a29eeb7 commit 9cf1385
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Slic3r/GUI/Plater.pm
Expand Up @@ -1001,7 +1001,7 @@ sub repaint {

# draw skirt
if (@{$parent->{object_previews}} && $parent->{config}->skirts) {
my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour->pp}, map @{$_->[2]}, @{$parent->{object_previews}} ])});
my $convex_hull = convex_hull([ map @{$_->contour}, map @{$_->[2]}, @{$parent->{object_previews}} ]);
($convex_hull) = @{offset([$convex_hull], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 100, JT_ROUND)};
$dc->SetPen($parent->{skirt_pen});
$dc->SetBrush($parent->{transparent_brush});
Expand Down Expand Up @@ -1289,7 +1289,7 @@ sub _trigger_model_object {

my $mesh = $model_object->mesh;
$mesh->repair;
$self->convex_hull(Slic3r::Geometry::convex_hull($mesh->vertices));
$self->convex_hull($mesh->convex_hull);
$self->facets($mesh->facets_count);
$self->vertices(scalar @{$mesh->vertices});
$self->materials($model_object->materials_count);
Expand Down
14 changes: 14 additions & 0 deletions xs/src/TriangleMesh.cpp
@@ -1,5 +1,6 @@
#include "TriangleMesh.hpp"
#include "ClipperUtils.hpp"
#include "Geometry.hpp"
#include <queue>
#include <deque>
#include <set>
Expand Down Expand Up @@ -598,6 +599,19 @@ TriangleMesh::horizontal_projection(ExPolygons &retval) const
union_(pp, retval, true);
}

void
TriangleMesh::convex_hull(Polygon &hull)
{
if (this->stl.v_shared == NULL) stl_generate_shared_vertices(&(this->stl));
Points pp;
pp.reserve(this->stl.stats.shared_vertices);
for (int i = 0; i < this->stl.stats.shared_vertices; i++) {
stl_vertex* v = this->stl.v_shared;
pp.push_back(Point(v->x / SCALING_FACTOR, v->y / SCALING_FACTOR));
}
Slic3r::Geometry::convex_hull(pp, hull);
}

#ifdef SLIC3RXS
SV*
TriangleMesh::to_SV() {
Expand Down
1 change: 1 addition & 0 deletions xs/src/TriangleMesh.hpp
Expand Up @@ -33,6 +33,7 @@ class TriangleMesh
TriangleMeshPtrs split() const;
void merge(const TriangleMesh* mesh);
void horizontal_projection(ExPolygons &retval) const;
void convex_hull(Polygon &hull);
stl_file stl;
bool repaired;

Expand Down
10 changes: 10 additions & 0 deletions xs/xsp/TriangleMesh.xsp
Expand Up @@ -161,6 +161,16 @@ TriangleMesh::bb3()
OUTPUT:
RETVAL

Polygon*
TriangleMesh::convex_hull()
PREINIT:
const char* CLASS = "Slic3r::Polygon";
CODE:
RETVAL = new Polygon ();
THIS->convex_hull(*RETVAL);
OUTPUT:
RETVAL

%}
};

Expand Down

0 comments on commit 9cf1385

Please sign in to comment.