From 311eda7d420936935663a1f80832ee417fb58268 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 10 Sep 2013 00:09:56 +0200 Subject: [PATCH] Implemented TriangleMesh->clone --- xs/src/TriangleMesh.cpp | 17 ++++++++++++++++- xs/src/TriangleMesh.hpp | 1 + xs/t/01_trianglemesh.t | 7 ++++++- xs/xsp/TriangleMesh.xsp | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index 894e0d77f..6293f570e 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -11,8 +11,23 @@ namespace Slic3r { +TriangleMesh::TriangleMesh(const TriangleMesh &other) + : stl(other.stl), repaired(other.repaired) +{ + this->stl.heads = NULL; + this->stl.tail = NULL; + if (other.stl.facet_start != NULL) + std::copy(other.stl.facet_start, other.stl.facet_start + other.stl.stats.number_of_facets, this->stl.facet_start); + if (other.stl.neighbors_start != NULL) + std::copy(other.stl.neighbors_start, other.stl.neighbors_start + other.stl.stats.number_of_facets, this->stl.neighbors_start); + if (other.stl.v_indices != NULL) + std::copy(other.stl.v_indices, other.stl.v_indices + other.stl.stats.number_of_facets, this->stl.v_indices); + if (other.stl.v_shared != NULL) + std::copy(other.stl.v_shared, other.stl.v_shared + other.stl.stats.shared_vertices, this->stl.v_shared); +} + TriangleMesh::~TriangleMesh() { - stl_close(&stl); + stl_close(&this->stl); } SV* diff --git a/xs/src/TriangleMesh.hpp b/xs/src/TriangleMesh.hpp index e3cda215d..b47f368ed 100644 --- a/xs/src/TriangleMesh.hpp +++ b/xs/src/TriangleMesh.hpp @@ -16,6 +16,7 @@ class TriangleMesh { public: TriangleMesh() : repaired(false) {}; + TriangleMesh(const TriangleMesh &other); ~TriangleMesh(); SV* to_SV(); void ReadSTLFile(char* input_file); diff --git a/xs/t/01_trianglemesh.t b/xs/t/01_trianglemesh.t index 0b42b977f..2324d20fa 100644 --- a/xs/t/01_trianglemesh.t +++ b/xs/t/01_trianglemesh.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 48; +use Test::More tests => 49; is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!', 'hello world'; @@ -32,6 +32,11 @@ my $cube = { $m->scale(2); ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale'; + { + my $m2 = $m->clone; + ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale'; + } + $m->scale_xyz([2,1,1]); ok abs($m->stats->{volume} - 2*40*40*40) < 1E-2, 'scale_xyz'; diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index b527216f7..e042146f4 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -8,6 +8,8 @@ %name{Slic3r::TriangleMesh::XS} class TriangleMesh { TriangleMesh(); ~TriangleMesh(); + TriangleMesh* clone() + %code{% const char* CLASS = "Slic3r::TriangleMesh"; RETVAL = new TriangleMesh(*THIS); %}; void ReadSTLFile(char* input_file); void ReadFromPerl(SV* vertices, SV* facets); void repair();