diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2015-04-16 22:22:04 +0300 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2015-04-16 22:22:04 +0300 |
commit | 5eb3bc52efa807c0439dba1ec0971fc37850d51e (patch) | |
tree | e14d9c7d1c513c7a878f75369d5eb5145a337468 /xs | |
parent | be2f46ca68b4a8a471a82439ad3dfd8a3d4adbb9 (diff) |
Ported ModelObject::rotate() and ModelObject::flip() to XS, as well as axes constants
Diffstat (limited to 'xs')
-rw-r--r-- | xs/src/libslic3r/Model.cpp | 24 | ||||
-rw-r--r-- | xs/src/libslic3r/Model.hpp | 2 | ||||
-rw-r--r-- | xs/src/libslic3r/TriangleMesh.cpp | 40 | ||||
-rw-r--r-- | xs/src/libslic3r/TriangleMesh.hpp | 2 | ||||
-rw-r--r-- | xs/src/libslic3r/libslic3r.h | 7 | ||||
-rw-r--r-- | xs/xsp/Geometry.xsp | 12 | ||||
-rw-r--r-- | xs/xsp/Model.xsp | 2 | ||||
-rw-r--r-- | xs/xsp/my.map | 1 | ||||
-rw-r--r-- | xs/xsp/typemap.xspt | 6 |
9 files changed, 84 insertions, 12 deletions
diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index d03a2916c..6fafe9bf0 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -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 { diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 2ec7c5b08..edce23d9c 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -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; diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index b25df7e0e..e8c8ef781 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -200,40 +200,58 @@ void TriangleMesh::translate(float x, float y, float z) stl_invalidate_shared_vertices(&this->stl); } -void TriangleMesh::rotate_x(float angle) +void TriangleMesh::rotate(float angle, const Axis &axis) { - stl_rotate_x(&(this->stl), angle); + 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) +{ + 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() diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 43ac68419..ff12e8427 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -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(); diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 25d3c7f48..45c42c7f9 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -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"): */ diff --git a/xs/xsp/Geometry.xsp b/xs/xsp/Geometry.xsp index 0df74a4bd..98d5bcdd5 100644 --- a/xs/xsp/Geometry.xsp +++ b/xs/xsp/Geometry.xsp @@ -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 + %} + diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 9870d7dd5..cf9b974f4 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -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%{ diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 37a4594d2..da9d3adc7 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -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 diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 6d3f92998..afc256d13 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -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{% |