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.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

View File

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

View File

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

View File

@ -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

View File

@ -1,6 +1,9 @@
#ifndef SLIC3RXS
#ifndef CONFIG_HPP
#define CONFIG_HPP
#include <initializer_list>
#include <memory>
@ -33,3 +36,5 @@ public:
} // namespace Slic3r
#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);
}
}
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<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
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<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 */
ExPolygons
TriangleMesh::horizontal_projection() const

View File

@ -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.

View File

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