Adjusted functions so that SLIC3RXS and the perl-less builds can live side-by-side.

This commit is contained in:
Joseph Lenox 2018-07-11 17:13:42 -05:00 committed by Joseph Lenox
parent 2ed48de491
commit 5ff201c53f
8 changed files with 100 additions and 78 deletions

View File

@ -144,8 +144,8 @@ src/libslic3r/SVG.hpp
src/libslic3r/TriangleMesh.cpp src/libslic3r/TriangleMesh.cpp
src/libslic3r/TriangleMesh.hpp src/libslic3r/TriangleMesh.hpp
src/libslic3r/utils.cpp src/libslic3r/utils.cpp
src/libslic3r/Zip/ZipArchive.cpp src/Zip/ZipArchive.cpp
src/libslic3r/Zip/ZipArchive.hpp src/Zip/ZipArchive.hpp
src/miniz/miniz.h src/miniz/miniz.h
src/perlglue.cpp src/perlglue.cpp
src/poly2tri/common/shapes.cc src/poly2tri/common/shapes.cc
@ -166,7 +166,7 @@ src/ppport.h
src/slic3r/GUI/3DScene.cpp src/slic3r/GUI/3DScene.cpp
src/slic3r/GUI/3DScene.hpp src/slic3r/GUI/3DScene.hpp
src/slic3r/GUI/GUI.cpp src/slic3r/GUI/GUI.cpp
src/slic3r/GUI/GUI.hpp src/slic3r/GUI/xsGUI.hpp
src/tiny_obj_loader.h src/tiny_obj_loader.h
src/xsinit.h src/xsinit.h
t/01_trianglemesh.t t/01_trianglemesh.t

View File

@ -1,5 +1,5 @@
#include "../../miniz/miniz.h" #include "miniz/miniz.h"
#include "../Zip/ZipArchive.hpp" #include "Zip/ZipArchive.hpp"
namespace Slic3r { namespace Slic3r {

View File

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "../../miniz/miniz.h" #include "miniz/miniz.h"
namespace Slic3r { namespace Slic3r {

View File

@ -1,3 +1,4 @@
#ifndef SLIC3RXS
#include "Config.hpp" #include "Config.hpp"
#include "Log.hpp" #include "Log.hpp"
@ -35,3 +36,7 @@ new_from_cli(const int& argc, const char* argv[])
} }
} // namespace Slic3r } // namespace Slic3r
#endif // SLIC3RXS

View File

@ -1,6 +1,9 @@
#ifndef SLIC3RXS
#ifndef CONFIG_HPP #ifndef CONFIG_HPP
#define CONFIG_HPP #define CONFIG_HPP
#include <initializer_list> #include <initializer_list>
#include <memory> #include <memory>
@ -33,3 +36,5 @@ public:
} // namespace Slic3r } // namespace Slic3r
#endif // CONFIG_HPP #endif // CONFIG_HPP
#endif // SLIC3RXS

View File

@ -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); 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) TriangleMesh& TriangleMesh::operator= (TriangleMesh other)
{ {
this->swap(other); this->swap(other);
@ -427,6 +373,62 @@ void TriangleMesh::rotate(double angle, const Point& center)
this->translate(+center.x, +center.y, 0); 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 Pointf3
TriangleMesh::center() const { TriangleMesh::center() const {
return this->bounding_box().center(); return this->bounding_box().center();
@ -467,6 +469,28 @@ BoundingBoxf3 TriangleMesh::bb3() const {
return std::move(BoundingBoxf3(min, max)); return std::move(BoundingBoxf3(min, max));
} }
void TriangleMesh::cut(Axis axis, double z, TriangleMesh* upper, TriangleMesh* lower)
{
switch(axis) {
case X:
TriangleMeshSlicer<X>(this).cut(z, upper, lower);
break;
case Y:
TriangleMeshSlicer<Y>(this).cut(z, upper, lower);
break;
case Z:
TriangleMeshSlicer<Z>(this).cut(z, upper, lower);
break;
default:
Slic3r::Log::error("TriangleMesh", "Invalid Axis supplied to cut()");
}
}
#endif // SLIC3RXS
TriangleMeshPtrs TriangleMeshPtrs
TriangleMesh::split() const TriangleMesh::split() const
{ {
@ -582,23 +606,6 @@ TriangleMesh::merge(const TriangleMesh &mesh)
stl_get_size(&this->stl); stl_get_size(&this->stl);
} }
void TriangleMesh::cut(Axis axis, double z, TriangleMesh* upper, TriangleMesh* lower)
{
switch(axis) {
case X:
TriangleMeshSlicer<X>(this).cut(z, upper, lower);
break;
case Y:
TriangleMeshSlicer<Y>(this).cut(z, upper, lower);
break;
case Z:
TriangleMeshSlicer<Z>(this).cut(z, upper, lower);
break;
default:
Slic3r::Log::error("TriangleMesh", "Invalid Axis supplied to cut()");
}
}
/* this will return scaled ExPolygons */ /* this will return scaled ExPolygons */
ExPolygons ExPolygons
TriangleMesh::horizontal_projection() const TriangleMesh::horizontal_projection() const

View File

@ -87,6 +87,8 @@ class TriangleMesh
void require_shared_vertices(); void require_shared_vertices();
void reverse_normals(); 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. /// Return a copy of the vertex array defining this mesh.
Pointf3s vertices(); Pointf3s vertices();
@ -113,6 +115,8 @@ class TriangleMesh
/// Perform a cut of the mesh and put the output in upper and lower /// Perform a cut of the mesh and put the output in upper and lower
void cut(Axis axis, double z, TriangleMesh* upper, TriangleMesh* 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). /// 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); static TriangleMesh make_cube(double x, double y, double z);
@ -127,6 +131,7 @@ class TriangleMesh
/// param[in] fa Facet angle. A smaller angle produces more facets. Default value is 2pi / 360. /// 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)); static TriangleMesh make_sphere(double rho, double fa=(2*PI/360));
stl_file stl; stl_file stl;
/// Whether or not this mesh has been repaired. /// Whether or not this mesh has been repaired.
bool repaired; bool repaired;

View File

@ -2,7 +2,7 @@
%{ %{
#include <xsinit.h> #include <xsinit.h>
#include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/xsGUI.hpp"
%} %}