Ported horizontal_projection() to XS
This commit is contained in:
parent
e75dbf37fa
commit
4d5d003ba7
4 changed files with 27 additions and 20 deletions
|
@ -29,24 +29,4 @@ sub bounding_box {
|
|||
return Slic3r::Geometry::BoundingBox->new_from_bb($self->bb3);
|
||||
}
|
||||
|
||||
# this will return *scaled* expolygons, so it is expected to be run
|
||||
# on unscaled meshes
|
||||
sub horizontal_projection {
|
||||
my $self = shift;
|
||||
|
||||
my ($facets, $vertices) = ($self->facets, $self->vertices);
|
||||
|
||||
my @f = ();
|
||||
foreach my $facet (@$facets) {
|
||||
push @f, Slic3r::Polygon->new(
|
||||
map [ map $_ / &Slic3r::SCALING_FACTOR, @{$vertices->[$_]}[X,Y] ], @$facet
|
||||
);
|
||||
}
|
||||
|
||||
$_->make_counter_clockwise for @f; # do this after scaling, as winding order might change while doing that
|
||||
|
||||
# the offset factor was tuned using groovemount.stl
|
||||
return union_ex(offset(\@f, Slic3r::Geometry::scale 0.01), 1);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "TriangleMesh.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
#include <set>
|
||||
|
@ -575,6 +576,28 @@ TriangleMesh::merge(const TriangleMesh* mesh)
|
|||
stl_get_size(&this->stl);
|
||||
}
|
||||
|
||||
/* this will return scaled ExPolygons */
|
||||
void
|
||||
TriangleMesh::horizontal_projection(ExPolygons &retval) const
|
||||
{
|
||||
Polygons pp;
|
||||
pp.reserve(this->stl.stats.number_of_facets);
|
||||
for (int i = 0; i < this->stl.stats.number_of_facets; i++) {
|
||||
stl_facet* facet = &this->stl.facet_start[i];
|
||||
Polygon p;
|
||||
p.points.resize(3);
|
||||
p.points[0] = Point(facet->vertex[0].x / SCALING_FACTOR, facet->vertex[0].y / SCALING_FACTOR);
|
||||
p.points[1] = Point(facet->vertex[1].x / SCALING_FACTOR, facet->vertex[1].y / SCALING_FACTOR);
|
||||
p.points[2] = Point(facet->vertex[2].x / SCALING_FACTOR, facet->vertex[2].y / SCALING_FACTOR);
|
||||
p.make_counter_clockwise(); // do this after scaling, as winding order might change while doing that
|
||||
pp.push_back(p);
|
||||
}
|
||||
|
||||
// the offset factor was tuned using groovemount.stl
|
||||
offset(pp, pp, 0.01 / SCALING_FACTOR);
|
||||
union_(pp, retval, true);
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV*
|
||||
TriangleMesh::to_SV() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <vector>
|
||||
#include "Point.hpp"
|
||||
#include "Polygon.hpp"
|
||||
#include "ExPolygon.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -31,6 +32,7 @@ class TriangleMesh
|
|||
void slice(const std::vector<double> &z, std::vector<Polygons> &layers);
|
||||
TriangleMeshPtrs split() const;
|
||||
void merge(const TriangleMesh* mesh);
|
||||
void horizontal_projection(ExPolygons &retval) const;
|
||||
stl_file stl;
|
||||
bool repaired;
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
void rotate(double angle, Point* center);
|
||||
TriangleMeshPtrs split();
|
||||
void merge(TriangleMesh* mesh);
|
||||
ExPolygons horizontal_projection()
|
||||
%code{% THIS->horizontal_projection(RETVAL); %};
|
||||
%{
|
||||
|
||||
SV*
|
||||
|
|
Loading…
Reference in a new issue