Ported ModelObject::rotate() and ModelObject::flip() to XS, as well as axes constants

This commit is contained in:
Alessandro Ranellucci 2015-04-16 21:22:04 +02:00
parent be2f46ca68
commit 5eb3bc52ef
11 changed files with 84 additions and 46 deletions

View File

@ -27,9 +27,6 @@ our @EXPORT_OK = qw(
use constant PI => 4 * atan2(1, 1);
use constant A => 0;
use constant B => 1;
use constant X => 0;
use constant Y => 1;
use constant Z => 2;
use constant X1 => 0;
use constant Y1 => 1;
use constant X2 => 2;

View File

@ -262,37 +262,6 @@ sub add_instance {
}
}
sub rotate {
my ($self, $angle, $axis) = @_;
# we accept angle in radians but mesh currently uses degrees
$angle = rad2deg($angle);
if ($axis == X) {
$_->mesh->rotate_x($angle) for @{$self->volumes};
} elsif ($axis == Y) {
$_->mesh->rotate_y($angle) for @{$self->volumes};
} elsif ($axis == Z) {
$_->mesh->rotate_z($angle) for @{$self->volumes};
}
$self->set_origin_translation(Slic3r::Pointf3->new(0,0,0));
$self->invalidate_bounding_box;
}
sub flip {
my ($self, $axis) = @_;
if ($axis == X) {
$_->mesh->flip_x for @{$self->volumes};
} elsif ($axis == Y) {
$_->mesh->flip_y for @{$self->volumes};
} elsif ($axis == Z) {
$_->mesh->flip_z for @{$self->volumes};
}
$self->set_origin_translation(Slic3r::Pointf3->new(0,0,0));
$self->invalidate_bounding_box;
}
sub mesh_stats {
my $self = shift;

View File

@ -1,4 +1,5 @@
#include "Model.hpp"
#include "Geometry.hpp"
namespace Slic3r {
@ -514,6 +515,29 @@ ModelObject::scale(const Pointf3 &versor)
this->invalidate_bounding_box();
}
void
ModelObject::rotate(float angle, const Axis &axis)
{
// we accept angle in radians but mesh currently uses degrees
angle = Slic3r::Geometry::rad2deg(angle);
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
(*v)->mesh.rotate(angle, axis);
}
this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box();
}
void
ModelObject::flip(const Axis &axis)
{
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
(*v)->mesh.flip(axis);
}
this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box();
}
size_t
ModelObject::materials_count() const
{

View File

@ -129,6 +129,8 @@ class ModelObject
void translate(const Vectorf3 &vector);
void translate(coordf_t x, coordf_t y, coordf_t z);
void scale(const Pointf3 &versor);
void rotate(float angle, const Axis &axis);
void flip(const Axis &axis);
size_t materials_count() const;
size_t facets_count() const;
bool needed_repair() const;

View File

@ -200,40 +200,58 @@ void TriangleMesh::translate(float x, float y, float z)
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::rotate(float angle, const Axis &axis)
{
if (axis == X) {
stl_rotate_x(&(this->stl), angle);
} else if (axis == Y) {
stl_rotate_y(&(this->stl), angle);
} else if (axis == Z) {
stl_rotate_z(&(this->stl), angle);
}
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::rotate_x(float angle)
{
stl_rotate_x(&(this->stl), angle);
stl_invalidate_shared_vertices(&this->stl);
this->rotate(angle, X);
}
void TriangleMesh::rotate_y(float angle)
{
stl_rotate_y(&(this->stl), angle);
stl_invalidate_shared_vertices(&this->stl);
this->rotate(angle, Y);
}
void TriangleMesh::rotate_z(float angle)
{
stl_rotate_z(&(this->stl), angle);
this->rotate(angle, Z);
}
void TriangleMesh::flip(const Axis &axis)
{
if (axis == X) {
stl_mirror_yz(&this->stl);
} else if (axis == Y) {
stl_mirror_xz(&this->stl);
} else if (axis == Z) {
stl_mirror_xy(&this->stl);
}
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::flip_x()
{
stl_mirror_yz(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
this->flip(X);
}
void TriangleMesh::flip_y()
{
stl_mirror_xz(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
this->flip(Y);
}
void TriangleMesh::flip_z()
{
stl_mirror_xy(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
this->flip(Z);
}
void TriangleMesh::align_to_origin()

View File

@ -32,9 +32,11 @@ class TriangleMesh
void scale(float factor);
void scale(const Pointf3 &versor);
void translate(float x, float y, float z);
void rotate(float angle, const Axis &axis);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);
void flip(const Axis &axis);
void flip_x();
void flip_y();
void flip_z();

View File

@ -17,7 +17,12 @@
typedef long coord_t;
typedef double coordf_t;
namespace Slic3r {}
namespace Slic3r {
// TODO: make sure X = 0
enum Axis { X, Y, Z };
}
using namespace Slic3r;
/* Implementation of CONFESS("foo"): */

View File

@ -87,4 +87,16 @@ simplify_polygons(polygons, tolerance)
OUTPUT:
RETVAL
IV
_constant()
ALIAS:
X = X
Y = Y
Z = Z
PROTOTYPE:
CODE:
RETVAL = ix;
OUTPUT: RETVAL
%}

View File

@ -182,6 +182,8 @@ ModelMaterial::attributes()
void translate(double x, double y, double z);
void scale_xyz(Pointf3* versor)
%code{% THIS->scale(*versor); %};
void rotate(float angle, Axis axis);
void flip(Axis axis);
Model* cut(double z)
%code%{

View File

@ -184,6 +184,7 @@ Clone<BridgeDetector> O_OBJECT_SLIC3R_T
GLVertexArray* O_OBJECT_SLIC3R
Axis T_UV
ExtrusionLoopRole T_UV
ExtrusionRole T_UV
FlowRole T_UV

View File

@ -173,6 +173,12 @@
%typemap{SupportLayerPtrs*};
%typemap{Axis}{parsed}{
%cpp_type{Axis};
%precall_code{%
$CVar = (Axis)SvUV($PerlVar);
%};
};
%typemap{SurfaceType}{parsed}{
%cpp_type{SurfaceType};
%precall_code{%