From 5ff201c53f5eb6c7c597446cff394329a7ff4e64 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Wed, 11 Jul 2018 17:13:42 -0500 Subject: [PATCH] Adjusted functions so that SLIC3RXS and the perl-less builds can live side-by-side. --- xs/MANIFEST | 6 +- xs/src/Zip/ZipArchive.cpp | 4 +- xs/src/Zip/ZipArchive.hpp | 2 +- xs/src/libslic3r/Config.cpp | 5 + xs/src/libslic3r/Config.hpp | 5 + xs/src/libslic3r/TriangleMesh.cpp | 149 ++++++++++++++++-------------- xs/src/libslic3r/TriangleMesh.hpp | 5 + xs/xsp/GUI.xsp | 2 +- 8 files changed, 100 insertions(+), 78 deletions(-) diff --git a/xs/MANIFEST b/xs/MANIFEST index 519004743..494ec30c3 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -144,8 +144,8 @@ src/libslic3r/SVG.hpp src/libslic3r/TriangleMesh.cpp src/libslic3r/TriangleMesh.hpp src/libslic3r/utils.cpp -src/libslic3r/Zip/ZipArchive.cpp -src/libslic3r/Zip/ZipArchive.hpp +src/Zip/ZipArchive.cpp +src/Zip/ZipArchive.hpp src/miniz/miniz.h src/perlglue.cpp src/poly2tri/common/shapes.cc @@ -166,7 +166,7 @@ src/ppport.h src/slic3r/GUI/3DScene.cpp src/slic3r/GUI/3DScene.hpp src/slic3r/GUI/GUI.cpp -src/slic3r/GUI/GUI.hpp +src/slic3r/GUI/xsGUI.hpp src/tiny_obj_loader.h src/xsinit.h t/01_trianglemesh.t diff --git a/xs/src/Zip/ZipArchive.cpp b/xs/src/Zip/ZipArchive.cpp index ee45271d3..532b2de61 100644 --- a/xs/src/Zip/ZipArchive.cpp +++ b/xs/src/Zip/ZipArchive.cpp @@ -1,5 +1,5 @@ -#include "../../miniz/miniz.h" -#include "../Zip/ZipArchive.hpp" +#include "miniz/miniz.h" +#include "Zip/ZipArchive.hpp" namespace Slic3r { diff --git a/xs/src/Zip/ZipArchive.hpp b/xs/src/Zip/ZipArchive.hpp index acc913330..1153344fd 100644 --- a/xs/src/Zip/ZipArchive.hpp +++ b/xs/src/Zip/ZipArchive.hpp @@ -6,7 +6,7 @@ #include #include -#include "../../miniz/miniz.h" +#include "miniz/miniz.h" namespace Slic3r { diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 91e68cc40..655f093f9 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -1,3 +1,4 @@ +#ifndef SLIC3RXS #include "Config.hpp" #include "Log.hpp" @@ -35,3 +36,7 @@ new_from_cli(const int& argc, const char* argv[]) } } // namespace Slic3r + + + +#endif // SLIC3RXS diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index f8c5e05a4..cdc57125c 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -1,6 +1,9 @@ +#ifndef SLIC3RXS + #ifndef CONFIG_HPP #define CONFIG_HPP + #include #include @@ -33,3 +36,5 @@ public: } // namespace Slic3r #endif // CONFIG_HPP + +#endif // SLIC3RXS diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index a7561852d..0878046cc 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -93,60 +93,6 @@ TriangleMesh::TriangleMesh(const TriangleMesh &other) std::copy(other.stl.v_shared, other.stl.v_shared + other.stl.stats.shared_vertices, this->stl.v_shared); } } - -Pointf3s TriangleMesh::vertices() -{ - Pointf3s tmp {}; - if (this->repaired) { - if (this->stl.v_shared == nullptr) - stl_generate_shared_vertices(&stl); // build the list of vertices - for (auto i = 0; i < this->stl.stats.shared_vertices; i++) { - const auto& v {this->stl.v_shared[i]}; - tmp.emplace_back(Pointf3(v.x, v.y, v.z)); - } - } else { - Slic3r::Log::warn("TriangleMesh", "vertices() requires repair()"); - } - return std::move(tmp); -} - -Point3s TriangleMesh::facets() -{ - Point3s tmp {}; - if (this->repaired) { - if (this->stl.v_shared == nullptr) - stl_generate_shared_vertices(&stl); // build the list of vertices - for (auto i = 0; i < stl.stats.number_of_facets; i++) { - const auto& v {stl.v_indices[i]}; - tmp.emplace_back(Point3(v.vertex[0], v.vertex[1], v.vertex[2])); - } - } else { - Slic3r::Log::warn("TriangleMesh", "facets() requires repair()"); - } - return std::move(tmp); -} - -Pointf3s TriangleMesh::normals() const -{ - Pointf3s tmp {}; - if (this->repaired) { - for (auto i = 0; i < stl.stats.number_of_facets; i++) { - const auto& n {stl.facet_start[i].normal}; - tmp.emplace_back(Pointf3(n.x, n.y, n.z)); - } - } else { - Slic3r::Log::warn("TriangleMesh", "normals() requires repair()"); - } - return std::move(tmp); -} - -Pointf3 TriangleMesh::size() const -{ - const auto& sz {stl.stats.size}; - return std::move(Pointf3(sz.x, sz.y, sz.z)); -} - - TriangleMesh& TriangleMesh::operator= (TriangleMesh other) { this->swap(other); @@ -427,6 +373,62 @@ void TriangleMesh::rotate(double angle, const Point& center) this->translate(+center.x, +center.y, 0); } +#ifndef SLIC3RXS + +Pointf3s TriangleMesh::vertices() +{ + Pointf3s tmp {}; + if (this->repaired) { + if (this->stl.v_shared == nullptr) + stl_generate_shared_vertices(&stl); // build the list of vertices + for (auto i = 0; i < this->stl.stats.shared_vertices; i++) { + const auto& v {this->stl.v_shared[i]}; + tmp.emplace_back(Pointf3(v.x, v.y, v.z)); + } + } else { + Slic3r::Log::warn("TriangleMesh", "vertices() requires repair()"); + } + return std::move(tmp); +} + +Point3s TriangleMesh::facets() +{ + Point3s tmp {}; + if (this->repaired) { + if (this->stl.v_shared == nullptr) + stl_generate_shared_vertices(&stl); // build the list of vertices + for (auto i = 0; i < stl.stats.number_of_facets; i++) { + const auto& v {stl.v_indices[i]}; + tmp.emplace_back(Point3(v.vertex[0], v.vertex[1], v.vertex[2])); + } + } else { + Slic3r::Log::warn("TriangleMesh", "facets() requires repair()"); + } + return std::move(tmp); +} + +Pointf3s TriangleMesh::normals() const +{ + Pointf3s tmp {}; + if (this->repaired) { + for (auto i = 0; i < stl.stats.number_of_facets; i++) { + const auto& n {stl.facet_start[i].normal}; + tmp.emplace_back(Pointf3(n.x, n.y, n.z)); + } + } else { + Slic3r::Log::warn("TriangleMesh", "normals() requires repair()"); + } + return std::move(tmp); +} + +Pointf3 TriangleMesh::size() const +{ + const auto& sz {stl.stats.size}; + return std::move(Pointf3(sz.x, sz.y, sz.z)); +} + + + Pointf3 TriangleMesh::center() const { return this->bounding_box().center(); @@ -467,6 +469,28 @@ BoundingBoxf3 TriangleMesh::bb3() const { return std::move(BoundingBoxf3(min, max)); } + +void TriangleMesh::cut(Axis axis, double z, TriangleMesh* upper, TriangleMesh* lower) +{ + switch(axis) { + case X: + TriangleMeshSlicer(this).cut(z, upper, lower); + break; + case Y: + TriangleMeshSlicer(this).cut(z, upper, lower); + break; + case Z: + TriangleMeshSlicer(this).cut(z, upper, lower); + break; + default: + Slic3r::Log::error("TriangleMesh", "Invalid Axis supplied to cut()"); + } +} + + + +#endif // SLIC3RXS + TriangleMeshPtrs TriangleMesh::split() const { @@ -582,23 +606,6 @@ TriangleMesh::merge(const TriangleMesh &mesh) stl_get_size(&this->stl); } -void TriangleMesh::cut(Axis axis, double z, TriangleMesh* upper, TriangleMesh* lower) -{ - switch(axis) { - case X: - TriangleMeshSlicer(this).cut(z, upper, lower); - break; - case Y: - TriangleMeshSlicer(this).cut(z, upper, lower); - break; - case Z: - TriangleMeshSlicer(this).cut(z, upper, lower); - break; - default: - Slic3r::Log::error("TriangleMesh", "Invalid Axis supplied to cut()"); - } -} - /* this will return scaled ExPolygons */ ExPolygons TriangleMesh::horizontal_projection() const diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 0d74fe112..cc4ab6d80 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -87,6 +87,8 @@ class TriangleMesh void require_shared_vertices(); void reverse_normals(); +#ifndef SLIC3RXS // Don't build these functions when also building the Perl interface. + /// Return a copy of the vertex array defining this mesh. Pointf3s vertices(); @@ -112,6 +114,8 @@ class TriangleMesh /// Perform a cut of the mesh and put the output in upper and lower void cut(Axis axis, double z, TriangleMesh* upper, TriangleMesh* lower); + +#endif // SLIC3RXS /// Generate a mesh representing a cube with dimensions (x, y, z), with one corner at (0,0,0). static TriangleMesh make_cube(double x, double y, double z); @@ -126,6 +130,7 @@ class TriangleMesh /// param[in] rho Distance from center to the shell of the sphere. /// param[in] fa Facet angle. A smaller angle produces more facets. Default value is 2pi / 360. static TriangleMesh make_sphere(double rho, double fa=(2*PI/360)); + stl_file stl; /// Whether or not this mesh has been repaired. diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp index a422040e1..28f798c5c 100644 --- a/xs/xsp/GUI.xsp +++ b/xs/xsp/GUI.xsp @@ -2,7 +2,7 @@ %{ #include -#include "slic3r/GUI/GUI.hpp" +#include "slic3r/GUI/xsGUI.hpp" %}