mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 14:44:19 -06:00
Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_sequential_limits
This commit is contained in:
commit
221c054e4f
27 changed files with 1856 additions and 1602 deletions
|
@ -198,6 +198,8 @@ add_library(libslic3r STATIC
|
|||
Tesselate.hpp
|
||||
TriangleMesh.cpp
|
||||
TriangleMesh.hpp
|
||||
TriangleMeshSlicer.cpp
|
||||
TriangleMeshSlicer.hpp
|
||||
TriangulateWall.hpp
|
||||
TriangulateWall.cpp
|
||||
utils.cpp
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "ModelArrange.hpp"
|
||||
#include "Geometry.hpp"
|
||||
#include "MTUtils.hpp"
|
||||
#include "TriangleMeshSlicer.hpp"
|
||||
#include "TriangleSelector.hpp"
|
||||
|
||||
#include "Format/AMF.hpp"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "Surface.hpp"
|
||||
#include "Slicing.hpp"
|
||||
#include "Tesselate.hpp"
|
||||
#include "TriangleMeshSlicer.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Fill/FillAdaptive.hpp"
|
||||
#include "Format/STL.hpp"
|
||||
|
@ -2221,9 +2222,8 @@ std::vector<ExPolygons> PrintObject::slice_volumes(
|
|||
auto callback = TriangleMeshSlicer::throw_on_cancel_callback_type([print](){print->throw_if_canceled();});
|
||||
// TriangleMeshSlicer needs shared vertices, also this calls the repair() function.
|
||||
mesh.require_shared_vertices();
|
||||
TriangleMeshSlicer mslicer;
|
||||
mslicer.init(&mesh, callback);
|
||||
mslicer.slice(z, mode, slicing_mode_normal_below_layer, mode_below, float(m_config.slice_closing_radius.value), &layers, callback);
|
||||
MeshSlicingParamsExtended params { { mode, slicing_mode_normal_below_layer, mode_below }, float(m_config.slice_closing_radius.value) };
|
||||
slice_mesh(mesh, z, params, layers, callback);
|
||||
m_print->throw_if_canceled();
|
||||
}
|
||||
}
|
||||
|
@ -2245,13 +2245,14 @@ std::vector<ExPolygons> PrintObject::slice_volume(const std::vector<float> &z, S
|
|||
// apply XY shift
|
||||
mesh.translate(- unscale<float>(m_center_offset.x()), - unscale<float>(m_center_offset.y()), 0);
|
||||
// perform actual slicing
|
||||
TriangleMeshSlicer mslicer;
|
||||
const Print *print = this->print();
|
||||
auto callback = TriangleMeshSlicer::throw_on_cancel_callback_type([print](){print->throw_if_canceled();});
|
||||
// TriangleMeshSlicer needs the shared vertices.
|
||||
mesh.require_shared_vertices();
|
||||
mslicer.init(&mesh, callback);
|
||||
mslicer.slice(z, mode, float(m_config.slice_closing_radius.value), &layers, callback);
|
||||
MeshSlicingParamsExtended params;
|
||||
params.mode = mode;
|
||||
params.closing_radius = float(m_config.slice_closing_radius.value);
|
||||
slice_mesh(mesh, z, params, layers, callback);
|
||||
m_print->throw_if_canceled();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <libslic3r/OpenVDBUtils.hpp>
|
||||
#include <libslic3r/TriangleMesh.hpp>
|
||||
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||
#include <libslic3r/SLA/Hollowing.hpp>
|
||||
#include <libslic3r/SLA/IndexedMesh.hpp>
|
||||
#include <libslic3r/ClipperUtils.hpp>
|
||||
|
@ -296,10 +297,8 @@ void cut_drainholes(std::vector<ExPolygons> & obj_slices,
|
|||
|
||||
mesh.require_shared_vertices();
|
||||
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
|
||||
std::vector<ExPolygons> hole_slices;
|
||||
slicer.slice(slicegrid, SlicingMode::Regular, closing_radius, &hole_slices, thr);
|
||||
slice_mesh(mesh, slicegrid, closing_radius, hole_slices, thr);
|
||||
|
||||
if (obj_slices.size() != hole_slices.size())
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <libslic3r/SLA/SpatIndex.hpp>
|
||||
#include <libslic3r/SLA/BoostAdapter.hpp>
|
||||
#include <libslic3r/SLA/Contour3D.hpp>
|
||||
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||
|
||||
#include "ConcaveHull.hpp"
|
||||
|
||||
|
@ -476,10 +477,9 @@ void pad_blueprint(const TriangleMesh & mesh,
|
|||
ThrowOnCancel thrfn)
|
||||
{
|
||||
if (mesh.empty()) return;
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
|
||||
auto out = reserve_vector<ExPolygons>(heights.size());
|
||||
slicer.slice(heights, SlicingMode::Regular, 0.f, &out, thrfn);
|
||||
slice_mesh(mesh, heights, out, thrfn);
|
||||
|
||||
size_t count = 0;
|
||||
for(auto& o : out) count += o.size();
|
||||
|
|
|
@ -72,7 +72,8 @@ public:
|
|||
size_t width_px = 0;
|
||||
size_t height_px = 0;
|
||||
|
||||
Resolution(size_t w = 0, size_t h = 0) : width_px(w), height_px(h) {}
|
||||
Resolution() = default;
|
||||
Resolution(size_t w, size_t h) : width_px(w), height_px(h) {}
|
||||
size_t pixels() const { return width_px * height_px; }
|
||||
};
|
||||
|
||||
|
@ -81,7 +82,8 @@ public:
|
|||
double w_mm = 1.;
|
||||
double h_mm = 1.;
|
||||
|
||||
PixelDim(double px_width_mm = 0.0, double px_height_mm = 0.0)
|
||||
PixelDim() = default;
|
||||
PixelDim(double px_width_mm, double px_height_mm)
|
||||
: w_mm(px_width_mm), h_mm(px_height_mm)
|
||||
{}
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <libslic3r/MTUtils.hpp>
|
||||
#include <libslic3r/ClipperUtils.hpp>
|
||||
#include <libslic3r/Model.hpp>
|
||||
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||
|
||||
#include <libnest2d/optimizers/nlopt/genetic.hpp>
|
||||
#include <libnest2d/optimizers/nlopt/subplex.hpp>
|
||||
|
@ -44,9 +45,7 @@ std::vector<ExPolygons> SupportTree::slice(
|
|||
|
||||
if (!sup_mesh.empty()) {
|
||||
slices.emplace_back();
|
||||
|
||||
TriangleMeshSlicer sup_slicer(&sup_mesh);
|
||||
sup_slicer.slice(grid, SlicingMode::Regular, cr, &slices.back(), ctl().cancelfn);
|
||||
slice_mesh(sup_mesh, grid, cr, slices.back(), ctl().cancelfn);
|
||||
}
|
||||
|
||||
if (!pad_mesh.empty()) {
|
||||
|
@ -59,8 +58,7 @@ std::vector<ExPolygons> SupportTree::slice(
|
|||
auto padgrid = reserve_vector<float>(size_t(cap > 0 ? cap : 0));
|
||||
std::copy(grid.begin(), maxzit, std::back_inserter(padgrid));
|
||||
|
||||
TriangleMeshSlicer pad_slicer(&pad_mesh);
|
||||
pad_slicer.slice(padgrid, SlicingMode::Regular, cr, &slices.back(), ctl().cancelfn);
|
||||
slice_mesh(pad_mesh, padgrid, cr, slices.back(), ctl().cancelfn);
|
||||
}
|
||||
|
||||
size_t len = grid.size();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <libslic3r/Exception.hpp>
|
||||
#include <libslic3r/SLAPrintSteps.hpp>
|
||||
#include <libslic3r/MeshBoolean.hpp>
|
||||
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||
|
||||
// Need the cylinder method for the the drainholes in hollowing step
|
||||
#include <libslic3r/SLA/SupportTreeBuilder.hpp>
|
||||
|
@ -198,7 +199,7 @@ static std::vector<bool> create_exclude_mask(
|
|||
std::vector<bool> exclude_mask(its.indices.size(), false);
|
||||
|
||||
std::vector< std::vector<size_t> > neighbor_index =
|
||||
create_neighbor_index(its);
|
||||
create_vertex_faces_index(its);
|
||||
|
||||
auto exclude_neighbors = [&neighbor_index, &exclude_mask](const Vec3i &face)
|
||||
{
|
||||
|
@ -470,13 +471,11 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
|
|||
for(auto it = slindex_it; it != po.m_slice_index.end(); ++it)
|
||||
po.m_model_height_levels.emplace_back(it->slice_level());
|
||||
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
|
||||
po.m_model_slices.clear();
|
||||
float closing_r = float(po.config().slice_closing_radius.value);
|
||||
auto thr = [this]() { m_print->throw_if_canceled(); };
|
||||
auto &slice_grid = po.m_model_height_levels;
|
||||
slicer.slice(slice_grid, SlicingMode::Regular, closing_r, &po.m_model_slices, thr);
|
||||
slice_mesh(mesh, slice_grid, closing_r, po.m_model_slices, thr);
|
||||
|
||||
sla::Interior *interior = po.m_hollowing_data ?
|
||||
po.m_hollowing_data->interior.get() :
|
||||
|
@ -486,9 +485,8 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
|
|||
TriangleMesh interiormesh = sla::get_mesh(*interior);
|
||||
interiormesh.repaired = false;
|
||||
interiormesh.repair(true);
|
||||
TriangleMeshSlicer interior_slicer(&interiormesh);
|
||||
std::vector<ExPolygons> interior_slices;
|
||||
interior_slicer.slice(slice_grid, SlicingMode::Regular, closing_r, &interior_slices, thr);
|
||||
slice_mesh(interiormesh, slice_grid, closing_r, interior_slices, thr);
|
||||
|
||||
sla::ccr::for_each(size_t(0), interior_slices.size(),
|
||||
[&po, &interior_slices] (size_t i) {
|
||||
|
|
|
@ -83,12 +83,6 @@ void SVG::draw(const Lines &lines, std::string stroke, coordf_t stroke_width)
|
|||
this->draw(l, stroke, stroke_width);
|
||||
}
|
||||
|
||||
void SVG::draw(const IntersectionLines &lines, std::string stroke)
|
||||
{
|
||||
for (const IntersectionLine &il : lines)
|
||||
this->draw((Line)il, stroke);
|
||||
}
|
||||
|
||||
void SVG::draw(const ExPolygon &expolygon, std::string fill, const float fill_opacity)
|
||||
{
|
||||
this->fill = fill;
|
||||
|
|
|
@ -43,8 +43,7 @@ public:
|
|||
void draw(const Line &line, std::string stroke = "black", coordf_t stroke_width = 0);
|
||||
void draw(const ThickLine &line, const std::string &fill, const std::string &stroke, coordf_t stroke_width = 0);
|
||||
void draw(const Lines &lines, std::string stroke = "black", coordf_t stroke_width = 0);
|
||||
void draw(const IntersectionLines &lines, std::string stroke = "black");
|
||||
|
||||
|
||||
void draw(const ExPolygon &expolygon, std::string fill = "grey", const float fill_opacity=1.f);
|
||||
void draw_outline(const ExPolygon &polygon, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
|
||||
void draw(const ExPolygons &expolygons, std::string fill = "grey", const float fill_opacity=1.f);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,6 @@
|
|||
#include <admesh/stl.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <boost/thread.hpp>
|
||||
#include "BoundingBox.hpp"
|
||||
#include "Line.hpp"
|
||||
#include "Point.hpp"
|
||||
|
@ -24,7 +23,7 @@ public:
|
|||
TriangleMesh() : repaired(false) {}
|
||||
TriangleMesh(const Pointf3s &points, const std::vector<Vec3i> &facets);
|
||||
explicit TriangleMesh(const indexed_triangle_set &M);
|
||||
void clear() { this->stl.clear(); this->its.clear(); this->repaired = false; }
|
||||
void clear() { this->stl.clear(); this->its.clear(); this->repaired = false; }
|
||||
bool ReadSTLFile(const char* input_file) { return stl_open(&stl, input_file); }
|
||||
bool write_ascii(const char* output_file) { return stl_write_ascii(&this->stl, output_file, ""); }
|
||||
bool write_binary(const char* output_file) { return stl_write_binary(&this->stl, output_file, ""); }
|
||||
|
@ -47,7 +46,7 @@ public:
|
|||
void mirror_y() { this->mirror(Y); }
|
||||
void mirror_z() { this->mirror(Z); }
|
||||
void transform(const Transform3d& t, bool fix_left_handed = false);
|
||||
void transform(const Matrix3d& t, bool fix_left_handed = false);
|
||||
void transform(const Matrix3d& t, bool fix_left_handed = false);
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
TriangleMeshPtrs split() const;
|
||||
|
@ -62,7 +61,7 @@ public:
|
|||
// Return the size of the mesh in coordinates.
|
||||
Vec3d size() const { return stl.stats.size.cast<double>(); }
|
||||
/// Return the center of the related bounding box.
|
||||
Vec3d center() const { return this->bounding_box().center(); }
|
||||
Vec3d center() const { return this->bounding_box().center(); }
|
||||
// Returns the convex hull of this TriangleMesh
|
||||
TriangleMesh convex_hull_3d() const;
|
||||
// Slice this mesh at the provided Z levels and return the vector
|
||||
|
@ -78,8 +77,8 @@ public:
|
|||
size_t memsize() const;
|
||||
// Release optional data from the mesh if the object is on the Undo / Redo stack only. Returns the amount of memory released.
|
||||
size_t release_optional();
|
||||
// Restore optional data possibly released by release_optional().
|
||||
void restore_optional();
|
||||
// Restore optional data possibly released by release_optional().
|
||||
void restore_optional();
|
||||
|
||||
stl_file stl;
|
||||
indexed_triangle_set its;
|
||||
|
@ -92,160 +91,16 @@ private:
|
|||
// Create an index of faces belonging to each vertex. The returned vector can
|
||||
// be indexed with vertex indices and contains a list of face indices for each
|
||||
// vertex.
|
||||
std::vector< std::vector<size_t> >
|
||||
create_neighbor_index(const indexed_triangle_set &its);
|
||||
std::vector<std::vector<size_t>> create_vertex_faces_index(const indexed_triangle_set &its);
|
||||
|
||||
enum FacetEdgeType {
|
||||
// A general case, the cutting plane intersect a face at two different edges.
|
||||
feGeneral,
|
||||
// Two vertices are aligned with the cutting plane, the third vertex is below the cutting plane.
|
||||
feTop,
|
||||
// Two vertices are aligned with the cutting plane, the third vertex is above the cutting plane.
|
||||
feBottom,
|
||||
// All three vertices of a face are aligned with the cutting plane.
|
||||
feHorizontal
|
||||
};
|
||||
|
||||
class IntersectionReference
|
||||
{
|
||||
public:
|
||||
IntersectionReference() : point_id(-1), edge_id(-1) {}
|
||||
IntersectionReference(int point_id, int edge_id) : point_id(point_id), edge_id(edge_id) {}
|
||||
// Where is this intersection point located? On mesh vertex or mesh edge?
|
||||
// Only one of the following will be set, the other will remain set to -1.
|
||||
// Index of the mesh vertex.
|
||||
int point_id;
|
||||
// Index of the mesh edge.
|
||||
int edge_id;
|
||||
};
|
||||
|
||||
class IntersectionPoint : public Point, public IntersectionReference
|
||||
{
|
||||
public:
|
||||
IntersectionPoint() {}
|
||||
IntersectionPoint(int point_id, int edge_id, const Point &pt) : IntersectionReference(point_id, edge_id), Point(pt) {}
|
||||
IntersectionPoint(const IntersectionReference &ir, const Point &pt) : IntersectionReference(ir), Point(pt) {}
|
||||
// Inherits coord_t x, y
|
||||
};
|
||||
|
||||
class IntersectionLine : public Line
|
||||
{
|
||||
public:
|
||||
IntersectionLine() : a_id(-1), b_id(-1), edge_a_id(-1), edge_b_id(-1), edge_type(feGeneral), flags(0) {}
|
||||
|
||||
bool skip() const { return (this->flags & SKIP) != 0; }
|
||||
void set_skip() { this->flags |= SKIP; }
|
||||
|
||||
bool is_seed_candidate() const { return (this->flags & NO_SEED) == 0 && ! this->skip(); }
|
||||
void set_no_seed(bool set) { if (set) this->flags |= NO_SEED; else this->flags &= ~NO_SEED; }
|
||||
|
||||
// Inherits Point a, b
|
||||
// For each line end point, either {a,b}_id or {a,b}edge_a_id is set, the other is left to -1.
|
||||
// Vertex indices of the line end points.
|
||||
int a_id;
|
||||
int b_id;
|
||||
// Source mesh edges of the line end points.
|
||||
int edge_a_id;
|
||||
int edge_b_id;
|
||||
// feGeneral, feTop, feBottom, feHorizontal
|
||||
FacetEdgeType edge_type;
|
||||
// Used by TriangleMeshSlicer::slice() to skip duplicate edges.
|
||||
enum {
|
||||
// Triangle edge added, because it has no neighbor.
|
||||
EDGE0_NO_NEIGHBOR = 0x001,
|
||||
EDGE1_NO_NEIGHBOR = 0x002,
|
||||
EDGE2_NO_NEIGHBOR = 0x004,
|
||||
// Triangle edge added, because it makes a fold with another horizontal edge.
|
||||
EDGE0_FOLD = 0x010,
|
||||
EDGE1_FOLD = 0x020,
|
||||
EDGE2_FOLD = 0x040,
|
||||
// The edge cannot be a seed of a greedy loop extraction (folds are not safe to become seeds).
|
||||
NO_SEED = 0x100,
|
||||
SKIP = 0x200,
|
||||
};
|
||||
uint32_t flags;
|
||||
};
|
||||
typedef std::vector<IntersectionLine> IntersectionLines;
|
||||
typedef std::vector<IntersectionLine*> IntersectionLinePtrs;
|
||||
|
||||
enum class SlicingMode : uint32_t {
|
||||
// Regular slicing, maintain all contours and their orientation.
|
||||
Regular,
|
||||
// Maintain all contours, orient all contours CCW, therefore all holes are being closed.
|
||||
Positive,
|
||||
// Orient all contours CCW and keep only the contour with the largest area.
|
||||
// This mode is useful for slicing complex objects in vase mode.
|
||||
PositiveLargestContour,
|
||||
};
|
||||
|
||||
class TriangleMeshSlicer
|
||||
{
|
||||
public:
|
||||
typedef std::function<void()> throw_on_cancel_callback_type;
|
||||
TriangleMeshSlicer() : mesh(nullptr) {}
|
||||
TriangleMeshSlicer(const TriangleMesh* mesh) { this->init(mesh, [](){}); }
|
||||
void init(const TriangleMesh *mesh, throw_on_cancel_callback_type throw_on_cancel);
|
||||
void slice(
|
||||
const std::vector<float> &z, SlicingMode mode, size_t alternate_mode_first_n_layers, SlicingMode alternate_mode,
|
||||
std::vector<Polygons>* layers, throw_on_cancel_callback_type throw_on_cancel) const;
|
||||
void slice(const std::vector<float> &z, SlicingMode mode, std::vector<Polygons>* layers, throw_on_cancel_callback_type throw_on_cancel) const
|
||||
{ return this->slice(z, mode, 0, mode, layers, throw_on_cancel); }
|
||||
void slice(
|
||||
const std::vector<float> &z, SlicingMode mode, size_t alternate_mode_first_n_layers, SlicingMode alternate_mode, const float closing_radius,
|
||||
std::vector<ExPolygons>* layers, throw_on_cancel_callback_type throw_on_cancel) const;
|
||||
void slice(const std::vector<float> &z, SlicingMode mode, const float closing_radius,
|
||||
std::vector<ExPolygons>* layers, throw_on_cancel_callback_type throw_on_cancel) const
|
||||
{ this->slice(z, mode, 0, mode, closing_radius, layers, throw_on_cancel); }
|
||||
enum FacetSliceType {
|
||||
NoSlice = 0,
|
||||
Slicing = 1,
|
||||
Cutting = 2
|
||||
};
|
||||
FacetSliceType slice_facet(float slice_z, const stl_facet &facet, const int facet_idx,
|
||||
const float min_z, const float max_z, IntersectionLine *line_out) const;
|
||||
void cut(float z, TriangleMesh* upper, TriangleMesh* lower) const;
|
||||
void set_up_direction(const Vec3f& up);
|
||||
|
||||
private:
|
||||
const TriangleMesh *mesh;
|
||||
// Map from a facet to an edge index.
|
||||
std::vector<int> facets_edges;
|
||||
// Scaled copy of this->mesh->stl.v_shared
|
||||
std::vector<stl_vertex> v_scaled_shared;
|
||||
// Quaternion that will be used to rotate every facet before the slicing
|
||||
Eigen::Quaternion<float, Eigen::DontAlign> m_quaternion;
|
||||
// Whether or not the above quaterion should be used
|
||||
bool m_use_quaternion = false;
|
||||
|
||||
void _slice_do(size_t facet_idx, std::vector<IntersectionLines>* lines, boost::mutex* lines_mutex, const std::vector<float> &z) const;
|
||||
void make_loops(std::vector<IntersectionLine> &lines, Polygons* loops) const;
|
||||
void make_expolygons(const Polygons &loops, const float closing_radius, ExPolygons* slices) const;
|
||||
void make_expolygons_simple(std::vector<IntersectionLine> &lines, ExPolygons* slices) const;
|
||||
void make_expolygons(std::vector<IntersectionLine> &lines, const float closing_radius, ExPolygons* slices) const;
|
||||
};
|
||||
|
||||
inline void slice_mesh(
|
||||
const TriangleMesh & mesh,
|
||||
const std::vector<float> & z,
|
||||
std::vector<Polygons> & layers,
|
||||
TriangleMeshSlicer::throw_on_cancel_callback_type thr = nullptr)
|
||||
{
|
||||
if (mesh.empty()) return;
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
slicer.slice(z, SlicingMode::Regular, &layers, thr);
|
||||
}
|
||||
|
||||
inline void slice_mesh(
|
||||
const TriangleMesh & mesh,
|
||||
const std::vector<float> & z,
|
||||
std::vector<ExPolygons> & layers,
|
||||
float closing_radius,
|
||||
TriangleMeshSlicer::throw_on_cancel_callback_type thr = nullptr)
|
||||
{
|
||||
if (mesh.empty()) return;
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
slicer.slice(z, SlicingMode::Regular, closing_radius, &layers, thr);
|
||||
}
|
||||
// Map from a facet edge to a neighbor face index or -1 if no neighbor exists.
|
||||
std::vector<int> create_face_neighbors_index(const indexed_triangle_set &its);
|
||||
std::vector<int> create_face_neighbors_index(const indexed_triangle_set &its, std::function<void()> throw_on_cancel_callback);
|
||||
// Remove degenerate faces, return number of faces removed.
|
||||
int its_remove_degenerate_faces(indexed_triangle_set &its, bool shrink_to_fit = true);
|
||||
// Remove vertices, which none of the faces references. Return number of freed vertices.
|
||||
int its_compactify_vertices(indexed_triangle_set &its, bool shrink_to_fit = true);
|
||||
void its_shrink_to_fit(indexed_triangle_set &its);
|
||||
|
||||
TriangleMesh make_cube(double x, double y, double z);
|
||||
|
||||
|
@ -259,21 +114,21 @@ TriangleMesh make_sphere(double rho, double fa=(2*PI/360));
|
|||
// Serialization through the Cereal library
|
||||
#include <cereal/access.hpp>
|
||||
namespace cereal {
|
||||
template <class Archive> struct specialize<Archive, Slic3r::TriangleMesh, cereal::specialization::non_member_load_save> {};
|
||||
template<class Archive> void load(Archive &archive, Slic3r::TriangleMesh &mesh) {
|
||||
template <class Archive> struct specialize<Archive, Slic3r::TriangleMesh, cereal::specialization::non_member_load_save> {};
|
||||
template<class Archive> void load(Archive &archive, Slic3r::TriangleMesh &mesh) {
|
||||
stl_file &stl = mesh.stl;
|
||||
stl.stats.type = inmemory;
|
||||
archive(stl.stats.number_of_facets, stl.stats.original_num_facets);
|
||||
archive(stl.stats.number_of_facets, stl.stats.original_num_facets);
|
||||
stl_allocate(&stl);
|
||||
archive.loadBinary((char*)stl.facet_start.data(), stl.facet_start.size() * 50);
|
||||
archive.loadBinary((char*)stl.facet_start.data(), stl.facet_start.size() * 50);
|
||||
stl_get_size(&stl);
|
||||
mesh.repair();
|
||||
}
|
||||
template<class Archive> void save(Archive &archive, const Slic3r::TriangleMesh &mesh) {
|
||||
const stl_file& stl = mesh.stl;
|
||||
archive(stl.stats.number_of_facets, stl.stats.original_num_facets);
|
||||
archive.saveBinary((char*)stl.facet_start.data(), stl.facet_start.size() * 50);
|
||||
}
|
||||
}
|
||||
template<class Archive> void save(Archive &archive, const Slic3r::TriangleMesh &mesh) {
|
||||
const stl_file& stl = mesh.stl;
|
||||
archive(stl.stats.number_of_facets, stl.stats.original_num_facets);
|
||||
archive.saveBinary((char*)stl.facet_start.data(), stl.facet_start.size() * 50);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
1363
src/libslic3r/TriangleMeshSlicer.cpp
Normal file
1363
src/libslic3r/TriangleMeshSlicer.cpp
Normal file
File diff suppressed because it is too large
Load diff
141
src/libslic3r/TriangleMeshSlicer.hpp
Normal file
141
src/libslic3r/TriangleMeshSlicer.hpp
Normal file
|
@ -0,0 +1,141 @@
|
|||
#ifndef slic3r_TriangleMeshSlicer_hpp_
|
||||
#define slic3r_TriangleMeshSlicer_hpp_
|
||||
|
||||
#include "libslic3r.h"
|
||||
#include <admesh/stl.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <boost/thread.hpp>
|
||||
#include "BoundingBox.hpp"
|
||||
#include "Line.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "Polygon.hpp"
|
||||
#include "ExPolygon.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class TriangleMesh;
|
||||
|
||||
enum class SlicingMode : uint32_t {
|
||||
// Regular slicing, maintain all contours and their orientation.
|
||||
Regular,
|
||||
// Maintain all contours, orient all contours CCW, therefore all holes are being closed.
|
||||
Positive,
|
||||
// Orient all contours CCW and keep only the contour with the largest area.
|
||||
// This mode is useful for slicing complex objects in vase mode.
|
||||
PositiveLargestContour,
|
||||
};
|
||||
|
||||
struct MeshSlicingParams
|
||||
{
|
||||
SlicingMode mode { SlicingMode::Regular };
|
||||
// For vase mode: below this layer a different slicing mode will be used to produce a single contour.
|
||||
// 0 = ignore.
|
||||
size_t slicing_mode_normal_below_layer { 0 };
|
||||
// Mode to apply below slicing_mode_normal_below_layer. Ignored if slicing_mode_nromal_below_layer == 0.
|
||||
SlicingMode mode_below { SlicingMode::Regular };
|
||||
};
|
||||
|
||||
struct MeshSlicingParamsExtended : public MeshSlicingParams
|
||||
{
|
||||
// Morphological closing operation when creating output expolygons.
|
||||
float closing_radius { 0 };
|
||||
// Positive offset applied when creating output expolygons.
|
||||
float extra_offset { 0 };
|
||||
// Resolution for contour simplification.
|
||||
// 0 = don't simplify.
|
||||
double resolution { 0 };
|
||||
// Transformation of the object owning the ModelVolume.
|
||||
// Transform3d object_trafo;
|
||||
};
|
||||
|
||||
class TriangleMeshSlicer
|
||||
{
|
||||
public:
|
||||
using throw_on_cancel_callback_type = std::function<void()>;
|
||||
TriangleMeshSlicer() = default;
|
||||
TriangleMeshSlicer(const TriangleMesh *mesh) { this->init(mesh, []{}); }
|
||||
TriangleMeshSlicer(const indexed_triangle_set *its) { this->init(its, []{}); }
|
||||
void init(const TriangleMesh *mesh, throw_on_cancel_callback_type throw_on_cancel);
|
||||
void init(const indexed_triangle_set *its, throw_on_cancel_callback_type);
|
||||
|
||||
void slice(
|
||||
const std::vector<float> &z,
|
||||
const MeshSlicingParams ¶ms,
|
||||
std::vector<Polygons> *layers,
|
||||
throw_on_cancel_callback_type throw_on_cancel = []{}) const;
|
||||
|
||||
void slice(
|
||||
// Where to slice.
|
||||
const std::vector<float> &z,
|
||||
const MeshSlicingParamsExtended ¶ms,
|
||||
std::vector<ExPolygons> *layers,
|
||||
throw_on_cancel_callback_type throw_on_cancel = []{}) const;
|
||||
|
||||
void cut(float z, indexed_triangle_set *upper, indexed_triangle_set *lower) const;
|
||||
void cut(float z, TriangleMesh* upper, TriangleMesh* lower) const;
|
||||
|
||||
void set_up_direction(const Vec3f& up);
|
||||
|
||||
private:
|
||||
const indexed_triangle_set *m_its { nullptr };
|
||||
// const TriangleMesh *mesh { nullptr };
|
||||
// Map from a facet to an edge index.
|
||||
std::vector<int> facets_edges;
|
||||
// Scaled copy of this->mesh->stl.v_shared
|
||||
std::vector<stl_vertex> v_scaled_shared;
|
||||
// Quaternion that will be used to rotate every facet before the slicing
|
||||
Eigen::Quaternion<float, Eigen::DontAlign> m_quaternion;
|
||||
// Whether or not the above quaterion should be used
|
||||
bool m_use_quaternion = false;
|
||||
};
|
||||
|
||||
inline void slice_mesh(
|
||||
const TriangleMesh &mesh,
|
||||
const std::vector<float> &z,
|
||||
std::vector<Polygons> &layers,
|
||||
TriangleMeshSlicer::throw_on_cancel_callback_type thr = []{})
|
||||
{
|
||||
if (! mesh.empty()) {
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
slicer.slice(z, MeshSlicingParams{}, &layers, thr);
|
||||
}
|
||||
}
|
||||
|
||||
inline void slice_mesh(
|
||||
const TriangleMesh &mesh,
|
||||
const std::vector<float> &z,
|
||||
const MeshSlicingParamsExtended ¶ms,
|
||||
std::vector<ExPolygons> &layers,
|
||||
TriangleMeshSlicer::throw_on_cancel_callback_type thr = []{})
|
||||
{
|
||||
if (! mesh.empty()) {
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
slicer.slice(z, params, &layers, thr);
|
||||
}
|
||||
}
|
||||
|
||||
inline void slice_mesh(
|
||||
const TriangleMesh &mesh,
|
||||
const std::vector<float> &z,
|
||||
float closing_radius,
|
||||
std::vector<ExPolygons> &layers,
|
||||
TriangleMeshSlicer::throw_on_cancel_callback_type thr = []{})
|
||||
{
|
||||
MeshSlicingParamsExtended params;
|
||||
params.closing_radius = closing_radius;
|
||||
slice_mesh(mesh, z, params, layers);
|
||||
}
|
||||
|
||||
inline void slice_mesh(
|
||||
const TriangleMesh &mesh,
|
||||
const std::vector<float> &z,
|
||||
std::vector<ExPolygons> &layers,
|
||||
TriangleMeshSlicer::throw_on_cancel_callback_type thr = []{})
|
||||
{
|
||||
slice_mesh(mesh, z, MeshSlicingParamsExtended{}, layers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // slic3r_TriangleMeshSlicer_hpp_
|
Loading…
Add table
Add a link
Reference in a new issue