WIP: Reworked slicing
1) Slicing code moved to TriangleMeshSlicer.cpp,hpp from TriangleMesh.cpp,hpp 2) Refactored to use as little as possible of admesh.
This commit is contained in:
parent
68d2427a34
commit
308d6b7809
@ -105,6 +105,15 @@ struct OutRec {
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
inline IntPoint IntPoint2d(cInt x, cInt y)
|
||||||
|
{
|
||||||
|
return IntPoint(x, y
|
||||||
|
#ifdef CLIPPERLIB_USE_XYZ
|
||||||
|
, 0
|
||||||
|
#endif // CLIPPERLIB_USE_XYZ
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
inline cInt Round(double val)
|
inline cInt Round(double val)
|
||||||
{
|
{
|
||||||
return static_cast<cInt>((val < 0) ? (val - 0.5) : (val + 0.5));
|
return static_cast<cInt>((val < 0) ? (val - 0.5) : (val + 0.5));
|
||||||
@ -2243,7 +2252,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge)
|
|||||||
while (maxIt != m_Maxima.end() && *maxIt < e->Curr.x())
|
while (maxIt != m_Maxima.end() && *maxIt < e->Curr.x())
|
||||||
{
|
{
|
||||||
if (horzEdge->OutIdx >= 0 && !IsOpen)
|
if (horzEdge->OutIdx >= 0 && !IsOpen)
|
||||||
AddOutPt(horzEdge, IntPoint(*maxIt, horzEdge->Bot.y()));
|
AddOutPt(horzEdge, IntPoint2d(*maxIt, horzEdge->Bot.y()));
|
||||||
++maxIt;
|
++maxIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2252,7 +2261,7 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge)
|
|||||||
while (maxRit != m_Maxima.rend() && *maxRit > e->Curr.x())
|
while (maxRit != m_Maxima.rend() && *maxRit > e->Curr.x())
|
||||||
{
|
{
|
||||||
if (horzEdge->OutIdx >= 0 && !IsOpen)
|
if (horzEdge->OutIdx >= 0 && !IsOpen)
|
||||||
AddOutPt(horzEdge, IntPoint(*maxRit, horzEdge->Bot.y()));
|
AddOutPt(horzEdge, IntPoint2d(*maxRit, horzEdge->Bot.y()));
|
||||||
++maxRit;
|
++maxRit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2297,12 +2306,12 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge)
|
|||||||
|
|
||||||
if(dir == dLeftToRight)
|
if(dir == dLeftToRight)
|
||||||
{
|
{
|
||||||
IntPoint Pt = IntPoint(e->Curr.x(), horzEdge->Curr.y());
|
IntPoint Pt = IntPoint2d(e->Curr.x(), horzEdge->Curr.y());
|
||||||
IntersectEdges(horzEdge, e, Pt);
|
IntersectEdges(horzEdge, e, Pt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IntPoint Pt = IntPoint(e->Curr.x(), horzEdge->Curr.y());
|
IntPoint Pt = IntPoint2d(e->Curr.x(), horzEdge->Curr.y());
|
||||||
IntersectEdges( e, horzEdge, Pt);
|
IntersectEdges( e, horzEdge, Pt);
|
||||||
}
|
}
|
||||||
TEdge* eNext = (dir == dLeftToRight) ? e->NextInAEL : e->PrevInAEL;
|
TEdge* eNext = (dir == dLeftToRight) ? e->NextInAEL : e->PrevInAEL;
|
||||||
@ -3372,14 +3381,14 @@ void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType
|
|||||||
//if this path's lowest pt is lower than all the others then update m_lowest
|
//if this path's lowest pt is lower than all the others then update m_lowest
|
||||||
if (endType != etClosedPolygon) return;
|
if (endType != etClosedPolygon) return;
|
||||||
if (m_lowest.x() < 0)
|
if (m_lowest.x() < 0)
|
||||||
m_lowest = IntPoint(m_polyNodes.ChildCount() - 1, k);
|
m_lowest = IntPoint2d(m_polyNodes.ChildCount() - 1, k);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IntPoint ip = m_polyNodes.Childs[(int)m_lowest.x()]->Contour[(int)m_lowest.y()];
|
IntPoint ip = m_polyNodes.Childs[(int)m_lowest.x()]->Contour[(int)m_lowest.y()];
|
||||||
if (newNode->Contour[k].y() > ip.y() ||
|
if (newNode->Contour[k].y() > ip.y() ||
|
||||||
(newNode->Contour[k].y() == ip.y() &&
|
(newNode->Contour[k].y() == ip.y() &&
|
||||||
newNode->Contour[k].x() < ip.x()))
|
newNode->Contour[k].x() < ip.x()))
|
||||||
m_lowest = IntPoint(m_polyNodes.ChildCount() - 1, k);
|
m_lowest = IntPoint2d(m_polyNodes.ChildCount() - 1, k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -3427,10 +3436,10 @@ void ClipperOffset::Execute(Paths& solution, double delta)
|
|||||||
{
|
{
|
||||||
IntRect r = clpr.GetBounds();
|
IntRect r = clpr.GetBounds();
|
||||||
Path outer(4);
|
Path outer(4);
|
||||||
outer[0] = IntPoint(r.left - 10, r.bottom + 10);
|
outer[0] = IntPoint2d(r.left - 10, r.bottom + 10);
|
||||||
outer[1] = IntPoint(r.right + 10, r.bottom + 10);
|
outer[1] = IntPoint2d(r.right + 10, r.bottom + 10);
|
||||||
outer[2] = IntPoint(r.right + 10, r.top - 10);
|
outer[2] = IntPoint2d(r.right + 10, r.top - 10);
|
||||||
outer[3] = IntPoint(r.left - 10, r.top - 10);
|
outer[3] = IntPoint2d(r.left - 10, r.top - 10);
|
||||||
|
|
||||||
clpr.AddPath(outer, ptSubject, true);
|
clpr.AddPath(outer, ptSubject, true);
|
||||||
clpr.ReverseSolution(true);
|
clpr.ReverseSolution(true);
|
||||||
@ -3457,10 +3466,10 @@ void ClipperOffset::Execute(PolyTree& solution, double delta)
|
|||||||
{
|
{
|
||||||
IntRect r = clpr.GetBounds();
|
IntRect r = clpr.GetBounds();
|
||||||
Path outer(4);
|
Path outer(4);
|
||||||
outer[0] = IntPoint(r.left - 10, r.bottom + 10);
|
outer[0] = IntPoint2d(r.left - 10, r.bottom + 10);
|
||||||
outer[1] = IntPoint(r.right + 10, r.bottom + 10);
|
outer[1] = IntPoint2d(r.right + 10, r.bottom + 10);
|
||||||
outer[2] = IntPoint(r.right + 10, r.top - 10);
|
outer[2] = IntPoint2d(r.right + 10, r.top - 10);
|
||||||
outer[3] = IntPoint(r.left - 10, r.top - 10);
|
outer[3] = IntPoint2d(r.left - 10, r.top - 10);
|
||||||
|
|
||||||
clpr.AddPath(outer, ptSubject, true);
|
clpr.AddPath(outer, ptSubject, true);
|
||||||
clpr.ReverseSolution(true);
|
clpr.ReverseSolution(true);
|
||||||
@ -3536,7 +3545,7 @@ void ClipperOffset::DoOffset(double delta)
|
|||||||
double X = 1.0, Y = 0.0;
|
double X = 1.0, Y = 0.0;
|
||||||
for (cInt j = 1; j <= steps; j++)
|
for (cInt j = 1; j <= steps; j++)
|
||||||
{
|
{
|
||||||
m_destPoly.push_back(IntPoint(
|
m_destPoly.push_back(IntPoint2d(
|
||||||
Round(m_srcPoly[0].x() + X * delta),
|
Round(m_srcPoly[0].x() + X * delta),
|
||||||
Round(m_srcPoly[0].y() + Y * delta)));
|
Round(m_srcPoly[0].y() + Y * delta)));
|
||||||
double X2 = X;
|
double X2 = X;
|
||||||
@ -3549,7 +3558,7 @@ void ClipperOffset::DoOffset(double delta)
|
|||||||
double X = -1.0, Y = -1.0;
|
double X = -1.0, Y = -1.0;
|
||||||
for (int j = 0; j < 4; ++j)
|
for (int j = 0; j < 4; ++j)
|
||||||
{
|
{
|
||||||
m_destPoly.push_back(IntPoint(
|
m_destPoly.push_back(IntPoint2d(
|
||||||
Round(m_srcPoly[0].x() + X * delta),
|
Round(m_srcPoly[0].x() + X * delta),
|
||||||
Round(m_srcPoly[0].y() + Y * delta)));
|
Round(m_srcPoly[0].y() + Y * delta)));
|
||||||
if (X < 0) X = 1;
|
if (X < 0) X = 1;
|
||||||
@ -3604,9 +3613,9 @@ void ClipperOffset::DoOffset(double delta)
|
|||||||
if (node.m_endtype == etOpenButt)
|
if (node.m_endtype == etOpenButt)
|
||||||
{
|
{
|
||||||
int j = len - 1;
|
int j = len - 1;
|
||||||
pt1 = IntPoint(Round(m_srcPoly[j].x() + m_normals[j].x() * delta), Round(m_srcPoly[j].y() + m_normals[j].y() * delta));
|
pt1 = IntPoint2d(Round(m_srcPoly[j].x() + m_normals[j].x() * delta), Round(m_srcPoly[j].y() + m_normals[j].y() * delta));
|
||||||
m_destPoly.push_back(pt1);
|
m_destPoly.push_back(pt1);
|
||||||
pt1 = IntPoint(Round(m_srcPoly[j].x() - m_normals[j].x() * delta), Round(m_srcPoly[j].y() - m_normals[j].y() * delta));
|
pt1 = IntPoint2d(Round(m_srcPoly[j].x() - m_normals[j].x() * delta), Round(m_srcPoly[j].y() - m_normals[j].y() * delta));
|
||||||
m_destPoly.push_back(pt1);
|
m_destPoly.push_back(pt1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3631,9 +3640,9 @@ void ClipperOffset::DoOffset(double delta)
|
|||||||
|
|
||||||
if (node.m_endtype == etOpenButt)
|
if (node.m_endtype == etOpenButt)
|
||||||
{
|
{
|
||||||
pt1 = IntPoint(Round(m_srcPoly[0].x() - m_normals[0].x() * delta), Round(m_srcPoly[0].y() - m_normals[0].y() * delta));
|
pt1 = IntPoint2d(Round(m_srcPoly[0].x() - m_normals[0].x() * delta), Round(m_srcPoly[0].y() - m_normals[0].y() * delta));
|
||||||
m_destPoly.push_back(pt1);
|
m_destPoly.push_back(pt1);
|
||||||
pt1 = IntPoint(Round(m_srcPoly[0].x() + m_normals[0].x() * delta), Round(m_srcPoly[0].y() + m_normals[0].y() * delta));
|
pt1 = IntPoint2d(Round(m_srcPoly[0].x() + m_normals[0].x() * delta), Round(m_srcPoly[0].y() + m_normals[0].y() * delta));
|
||||||
m_destPoly.push_back(pt1);
|
m_destPoly.push_back(pt1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3661,7 +3670,7 @@ void ClipperOffset::OffsetPoint(int j, int& k, JoinType jointype)
|
|||||||
double cosA = (m_normals[k].x() * m_normals[j].x() + m_normals[j].y() * m_normals[k].y() );
|
double cosA = (m_normals[k].x() * m_normals[j].x() + m_normals[j].y() * m_normals[k].y() );
|
||||||
if (cosA > 0) // angle => 0 degrees
|
if (cosA > 0) // angle => 0 degrees
|
||||||
{
|
{
|
||||||
m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + m_normals[k].x() * m_delta),
|
m_destPoly.push_back(IntPoint2d(Round(m_srcPoly[j].x() + m_normals[k].x() * m_delta),
|
||||||
Round(m_srcPoly[j].y() + m_normals[k].y() * m_delta)));
|
Round(m_srcPoly[j].y() + m_normals[k].y() * m_delta)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3672,10 +3681,10 @@ void ClipperOffset::OffsetPoint(int j, int& k, JoinType jointype)
|
|||||||
|
|
||||||
if (m_sinA * m_delta < 0)
|
if (m_sinA * m_delta < 0)
|
||||||
{
|
{
|
||||||
m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + m_normals[k].x() * m_delta),
|
m_destPoly.push_back(IntPoint2d(Round(m_srcPoly[j].x() + m_normals[k].x() * m_delta),
|
||||||
Round(m_srcPoly[j].y() + m_normals[k].y() * m_delta)));
|
Round(m_srcPoly[j].y() + m_normals[k].y() * m_delta)));
|
||||||
m_destPoly.push_back(m_srcPoly[j]);
|
m_destPoly.push_back(m_srcPoly[j]);
|
||||||
m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + m_normals[j].x() * m_delta),
|
m_destPoly.push_back(IntPoint2d(Round(m_srcPoly[j].x() + m_normals[j].x() * m_delta),
|
||||||
Round(m_srcPoly[j].y() + m_normals[j].y() * m_delta)));
|
Round(m_srcPoly[j].y() + m_normals[j].y() * m_delta)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3699,10 +3708,10 @@ void ClipperOffset::DoSquare(int j, int k)
|
|||||||
{
|
{
|
||||||
double dx = std::tan(std::atan2(m_sinA,
|
double dx = std::tan(std::atan2(m_sinA,
|
||||||
m_normals[k].x() * m_normals[j].x() + m_normals[k].y() * m_normals[j].y()) / 4);
|
m_normals[k].x() * m_normals[j].x() + m_normals[k].y() * m_normals[j].y()) / 4);
|
||||||
m_destPoly.push_back(IntPoint(
|
m_destPoly.push_back(IntPoint2d(
|
||||||
Round(m_srcPoly[j].x() + m_delta * (m_normals[k].x() - m_normals[k].y() * dx)),
|
Round(m_srcPoly[j].x() + m_delta * (m_normals[k].x() - m_normals[k].y() * dx)),
|
||||||
Round(m_srcPoly[j].y() + m_delta * (m_normals[k].y() + m_normals[k].x() * dx))));
|
Round(m_srcPoly[j].y() + m_delta * (m_normals[k].y() + m_normals[k].x() * dx))));
|
||||||
m_destPoly.push_back(IntPoint(
|
m_destPoly.push_back(IntPoint2d(
|
||||||
Round(m_srcPoly[j].x() + m_delta * (m_normals[j].x() + m_normals[j].y() * dx)),
|
Round(m_srcPoly[j].x() + m_delta * (m_normals[j].x() + m_normals[j].y() * dx)),
|
||||||
Round(m_srcPoly[j].y() + m_delta * (m_normals[j].y() - m_normals[j].x() * dx))));
|
Round(m_srcPoly[j].y() + m_delta * (m_normals[j].y() - m_normals[j].x() * dx))));
|
||||||
}
|
}
|
||||||
@ -3711,7 +3720,7 @@ void ClipperOffset::DoSquare(int j, int k)
|
|||||||
void ClipperOffset::DoMiter(int j, int k, double r)
|
void ClipperOffset::DoMiter(int j, int k, double r)
|
||||||
{
|
{
|
||||||
double q = m_delta / r;
|
double q = m_delta / r;
|
||||||
m_destPoly.push_back(IntPoint(Round(m_srcPoly[j].x() + (m_normals[k].x() + m_normals[j].x()) * q),
|
m_destPoly.push_back(IntPoint2d(Round(m_srcPoly[j].x() + (m_normals[k].x() + m_normals[j].x()) * q),
|
||||||
Round(m_srcPoly[j].y() + (m_normals[k].y() + m_normals[j].y()) * q)));
|
Round(m_srcPoly[j].y() + (m_normals[k].y() + m_normals[j].y()) * q)));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -3725,14 +3734,14 @@ void ClipperOffset::DoRound(int j, int k)
|
|||||||
double X = m_normals[k].x(), Y = m_normals[k].y(), X2;
|
double X = m_normals[k].x(), Y = m_normals[k].y(), X2;
|
||||||
for (int i = 0; i < steps; ++i)
|
for (int i = 0; i < steps; ++i)
|
||||||
{
|
{
|
||||||
m_destPoly.push_back(IntPoint(
|
m_destPoly.push_back(IntPoint2d(
|
||||||
Round(m_srcPoly[j].x() + X * m_delta),
|
Round(m_srcPoly[j].x() + X * m_delta),
|
||||||
Round(m_srcPoly[j].y() + Y * m_delta)));
|
Round(m_srcPoly[j].y() + Y * m_delta)));
|
||||||
X2 = X;
|
X2 = X;
|
||||||
X = X * m_cos - m_sin * Y;
|
X = X * m_cos - m_sin * Y;
|
||||||
Y = X2 * m_sin + Y * m_cos;
|
Y = X2 * m_sin + Y * m_cos;
|
||||||
}
|
}
|
||||||
m_destPoly.push_back(IntPoint(
|
m_destPoly.push_back(IntPoint2d(
|
||||||
Round(m_srcPoly[j].x() + m_normals[j].x() * m_delta),
|
Round(m_srcPoly[j].x() + m_normals[j].x() * m_delta),
|
||||||
Round(m_srcPoly[j].y() + m_normals[j].y() * m_delta)));
|
Round(m_srcPoly[j].y() + m_normals[j].y() * m_delta)));
|
||||||
}
|
}
|
||||||
@ -4001,7 +4010,7 @@ void Minkowski(const Path& poly, const Path& path,
|
|||||||
Path p;
|
Path p;
|
||||||
p.reserve(polyCnt);
|
p.reserve(polyCnt);
|
||||||
for (size_t j = 0; j < poly.size(); ++j)
|
for (size_t j = 0; j < poly.size(); ++j)
|
||||||
p.push_back(IntPoint(path[i].x() + poly[j].x(), path[i].y() + poly[j].y()));
|
p.push_back(IntPoint2d(path[i].x() + poly[j].x(), path[i].y() + poly[j].y()));
|
||||||
pp.push_back(p);
|
pp.push_back(p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -4010,7 +4019,7 @@ void Minkowski(const Path& poly, const Path& path,
|
|||||||
Path p;
|
Path p;
|
||||||
p.reserve(polyCnt);
|
p.reserve(polyCnt);
|
||||||
for (size_t j = 0; j < poly.size(); ++j)
|
for (size_t j = 0; j < poly.size(); ++j)
|
||||||
p.push_back(IntPoint(path[i].x() - poly[j].x(), path[i].y() - poly[j].y()));
|
p.push_back(IntPoint2d(path[i].x() - poly[j].x(), path[i].y() - poly[j].y()));
|
||||||
pp.push_back(p);
|
pp.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4045,7 +4054,7 @@ void TranslatePath(const Path& input, Path& output, const IntPoint& delta)
|
|||||||
//precondition: input != output
|
//precondition: input != output
|
||||||
output.resize(input.size());
|
output.resize(input.size());
|
||||||
for (size_t i = 0; i < input.size(); ++i)
|
for (size_t i = 0; i < input.size(); ++i)
|
||||||
output[i] = IntPoint(input[i].x() + delta.x(), input[i].y() + delta.y());
|
output[i] = IntPoint2d(input[i].x() + delta.x(), input[i].y() + delta.y());
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -198,6 +198,8 @@ add_library(libslic3r STATIC
|
|||||||
Tesselate.hpp
|
Tesselate.hpp
|
||||||
TriangleMesh.cpp
|
TriangleMesh.cpp
|
||||||
TriangleMesh.hpp
|
TriangleMesh.hpp
|
||||||
|
TriangleMeshSlicer.cpp
|
||||||
|
TriangleMeshSlicer.hpp
|
||||||
TriangulateWall.hpp
|
TriangulateWall.hpp
|
||||||
TriangulateWall.cpp
|
TriangulateWall.cpp
|
||||||
utils.cpp
|
utils.cpp
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "ModelArrange.hpp"
|
#include "ModelArrange.hpp"
|
||||||
#include "Geometry.hpp"
|
#include "Geometry.hpp"
|
||||||
#include "MTUtils.hpp"
|
#include "MTUtils.hpp"
|
||||||
|
#include "TriangleMeshSlicer.hpp"
|
||||||
#include "TriangleSelector.hpp"
|
#include "TriangleSelector.hpp"
|
||||||
|
|
||||||
#include "Format/AMF.hpp"
|
#include "Format/AMF.hpp"
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "Surface.hpp"
|
#include "Surface.hpp"
|
||||||
#include "Slicing.hpp"
|
#include "Slicing.hpp"
|
||||||
#include "Tesselate.hpp"
|
#include "Tesselate.hpp"
|
||||||
|
#include "TriangleMeshSlicer.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "Fill/FillAdaptive.hpp"
|
#include "Fill/FillAdaptive.hpp"
|
||||||
#include "Format/STL.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();});
|
auto callback = TriangleMeshSlicer::throw_on_cancel_callback_type([print](){print->throw_if_canceled();});
|
||||||
// TriangleMeshSlicer needs shared vertices, also this calls the repair() function.
|
// TriangleMeshSlicer needs shared vertices, also this calls the repair() function.
|
||||||
mesh.require_shared_vertices();
|
mesh.require_shared_vertices();
|
||||||
TriangleMeshSlicer mslicer;
|
MeshSlicingParamsExtended params { { mode, slicing_mode_normal_below_layer, mode_below }, float(m_config.slice_closing_radius.value) };
|
||||||
mslicer.init(&mesh, callback);
|
slice_mesh(mesh, z, params, layers, callback);
|
||||||
mslicer.slice(z, mode, slicing_mode_normal_below_layer, mode_below, float(m_config.slice_closing_radius.value), &layers, callback);
|
|
||||||
m_print->throw_if_canceled();
|
m_print->throw_if_canceled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2245,13 +2245,14 @@ std::vector<ExPolygons> PrintObject::slice_volume(const std::vector<float> &z, S
|
|||||||
// apply XY shift
|
// apply XY shift
|
||||||
mesh.translate(- unscale<float>(m_center_offset.x()), - unscale<float>(m_center_offset.y()), 0);
|
mesh.translate(- unscale<float>(m_center_offset.x()), - unscale<float>(m_center_offset.y()), 0);
|
||||||
// perform actual slicing
|
// perform actual slicing
|
||||||
TriangleMeshSlicer mslicer;
|
|
||||||
const Print *print = this->print();
|
const Print *print = this->print();
|
||||||
auto callback = TriangleMeshSlicer::throw_on_cancel_callback_type([print](){print->throw_if_canceled();});
|
auto callback = TriangleMeshSlicer::throw_on_cancel_callback_type([print](){print->throw_if_canceled();});
|
||||||
// TriangleMeshSlicer needs the shared vertices.
|
// TriangleMeshSlicer needs the shared vertices.
|
||||||
mesh.require_shared_vertices();
|
mesh.require_shared_vertices();
|
||||||
mslicer.init(&mesh, callback);
|
MeshSlicingParamsExtended params;
|
||||||
mslicer.slice(z, mode, float(m_config.slice_closing_radius.value), &layers, callback);
|
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();
|
m_print->throw_if_canceled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <libslic3r/OpenVDBUtils.hpp>
|
#include <libslic3r/OpenVDBUtils.hpp>
|
||||||
#include <libslic3r/TriangleMesh.hpp>
|
#include <libslic3r/TriangleMesh.hpp>
|
||||||
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||||
#include <libslic3r/SLA/Hollowing.hpp>
|
#include <libslic3r/SLA/Hollowing.hpp>
|
||||||
#include <libslic3r/SLA/IndexedMesh.hpp>
|
#include <libslic3r/SLA/IndexedMesh.hpp>
|
||||||
#include <libslic3r/ClipperUtils.hpp>
|
#include <libslic3r/ClipperUtils.hpp>
|
||||||
@ -296,10 +297,8 @@ void cut_drainholes(std::vector<ExPolygons> & obj_slices,
|
|||||||
|
|
||||||
mesh.require_shared_vertices();
|
mesh.require_shared_vertices();
|
||||||
|
|
||||||
TriangleMeshSlicer slicer(&mesh);
|
|
||||||
|
|
||||||
std::vector<ExPolygons> hole_slices;
|
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())
|
if (obj_slices.size() != hole_slices.size())
|
||||||
BOOST_LOG_TRIVIAL(warning)
|
BOOST_LOG_TRIVIAL(warning)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <libslic3r/SLA/SpatIndex.hpp>
|
#include <libslic3r/SLA/SpatIndex.hpp>
|
||||||
#include <libslic3r/SLA/BoostAdapter.hpp>
|
#include <libslic3r/SLA/BoostAdapter.hpp>
|
||||||
#include <libslic3r/SLA/Contour3D.hpp>
|
#include <libslic3r/SLA/Contour3D.hpp>
|
||||||
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||||
|
|
||||||
#include "ConcaveHull.hpp"
|
#include "ConcaveHull.hpp"
|
||||||
|
|
||||||
@ -476,10 +477,9 @@ void pad_blueprint(const TriangleMesh & mesh,
|
|||||||
ThrowOnCancel thrfn)
|
ThrowOnCancel thrfn)
|
||||||
{
|
{
|
||||||
if (mesh.empty()) return;
|
if (mesh.empty()) return;
|
||||||
TriangleMeshSlicer slicer(&mesh);
|
|
||||||
|
|
||||||
auto out = reserve_vector<ExPolygons>(heights.size());
|
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;
|
size_t count = 0;
|
||||||
for(auto& o : out) count += o.size();
|
for(auto& o : out) count += o.size();
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <libslic3r/MTUtils.hpp>
|
#include <libslic3r/MTUtils.hpp>
|
||||||
#include <libslic3r/ClipperUtils.hpp>
|
#include <libslic3r/ClipperUtils.hpp>
|
||||||
#include <libslic3r/Model.hpp>
|
#include <libslic3r/Model.hpp>
|
||||||
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||||
|
|
||||||
#include <libnest2d/optimizers/nlopt/genetic.hpp>
|
#include <libnest2d/optimizers/nlopt/genetic.hpp>
|
||||||
#include <libnest2d/optimizers/nlopt/subplex.hpp>
|
#include <libnest2d/optimizers/nlopt/subplex.hpp>
|
||||||
@ -44,9 +45,7 @@ std::vector<ExPolygons> SupportTree::slice(
|
|||||||
|
|
||||||
if (!sup_mesh.empty()) {
|
if (!sup_mesh.empty()) {
|
||||||
slices.emplace_back();
|
slices.emplace_back();
|
||||||
|
slice_mesh(sup_mesh, grid, cr, slices.back(), ctl().cancelfn);
|
||||||
TriangleMeshSlicer sup_slicer(&sup_mesh);
|
|
||||||
sup_slicer.slice(grid, SlicingMode::Regular, cr, &slices.back(), ctl().cancelfn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pad_mesh.empty()) {
|
if (!pad_mesh.empty()) {
|
||||||
@ -59,8 +58,7 @@ std::vector<ExPolygons> SupportTree::slice(
|
|||||||
auto padgrid = reserve_vector<float>(size_t(cap > 0 ? cap : 0));
|
auto padgrid = reserve_vector<float>(size_t(cap > 0 ? cap : 0));
|
||||||
std::copy(grid.begin(), maxzit, std::back_inserter(padgrid));
|
std::copy(grid.begin(), maxzit, std::back_inserter(padgrid));
|
||||||
|
|
||||||
TriangleMeshSlicer pad_slicer(&pad_mesh);
|
slice_mesh(pad_mesh, padgrid, cr, slices.back(), ctl().cancelfn);
|
||||||
pad_slicer.slice(padgrid, SlicingMode::Regular, cr, &slices.back(), ctl().cancelfn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = grid.size();
|
size_t len = grid.size();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <libslic3r/Exception.hpp>
|
#include <libslic3r/Exception.hpp>
|
||||||
#include <libslic3r/SLAPrintSteps.hpp>
|
#include <libslic3r/SLAPrintSteps.hpp>
|
||||||
#include <libslic3r/MeshBoolean.hpp>
|
#include <libslic3r/MeshBoolean.hpp>
|
||||||
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||||
|
|
||||||
// Need the cylinder method for the the drainholes in hollowing step
|
// Need the cylinder method for the the drainholes in hollowing step
|
||||||
#include <libslic3r/SLA/SupportTreeBuilder.hpp>
|
#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<bool> exclude_mask(its.indices.size(), false);
|
||||||
|
|
||||||
std::vector< std::vector<size_t> > neighbor_index =
|
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)
|
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)
|
for(auto it = slindex_it; it != po.m_slice_index.end(); ++it)
|
||||||
po.m_model_height_levels.emplace_back(it->slice_level());
|
po.m_model_height_levels.emplace_back(it->slice_level());
|
||||||
|
|
||||||
TriangleMeshSlicer slicer(&mesh);
|
|
||||||
|
|
||||||
po.m_model_slices.clear();
|
po.m_model_slices.clear();
|
||||||
float closing_r = float(po.config().slice_closing_radius.value);
|
float closing_r = float(po.config().slice_closing_radius.value);
|
||||||
auto thr = [this]() { m_print->throw_if_canceled(); };
|
auto thr = [this]() { m_print->throw_if_canceled(); };
|
||||||
auto &slice_grid = po.m_model_height_levels;
|
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 ?
|
sla::Interior *interior = po.m_hollowing_data ?
|
||||||
po.m_hollowing_data->interior.get() :
|
po.m_hollowing_data->interior.get() :
|
||||||
@ -486,9 +485,8 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
|
|||||||
TriangleMesh interiormesh = sla::get_mesh(*interior);
|
TriangleMesh interiormesh = sla::get_mesh(*interior);
|
||||||
interiormesh.repaired = false;
|
interiormesh.repaired = false;
|
||||||
interiormesh.repair(true);
|
interiormesh.repair(true);
|
||||||
TriangleMeshSlicer interior_slicer(&interiormesh);
|
|
||||||
std::vector<ExPolygons> interior_slices;
|
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(),
|
sla::ccr::for_each(size_t(0), interior_slices.size(),
|
||||||
[&po, &interior_slices] (size_t i) {
|
[&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);
|
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)
|
void SVG::draw(const ExPolygon &expolygon, std::string fill, const float fill_opacity)
|
||||||
{
|
{
|
||||||
this->fill = fill;
|
this->fill = fill;
|
||||||
|
@ -43,7 +43,6 @@ public:
|
|||||||
void draw(const Line &line, std::string stroke = "black", coordf_t stroke_width = 0);
|
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 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 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(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_outline(const ExPolygon &polygon, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,6 @@
|
|||||||
#include <admesh/stl.h>
|
#include <admesh/stl.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/thread.hpp>
|
|
||||||
#include "BoundingBox.hpp"
|
#include "BoundingBox.hpp"
|
||||||
#include "Line.hpp"
|
#include "Line.hpp"
|
||||||
#include "Point.hpp"
|
#include "Point.hpp"
|
||||||
@ -92,160 +91,16 @@ private:
|
|||||||
// Create an index of faces belonging to each vertex. The returned vector can
|
// 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
|
// be indexed with vertex indices and contains a list of face indices for each
|
||||||
// vertex.
|
// vertex.
|
||||||
std::vector< std::vector<size_t> >
|
std::vector<std::vector<size_t>> create_vertex_faces_index(const indexed_triangle_set &its);
|
||||||
create_neighbor_index(const indexed_triangle_set &its);
|
|
||||||
|
|
||||||
enum FacetEdgeType {
|
// Map from a facet edge to a neighbor face index or -1 if no neighbor exists.
|
||||||
// A general case, the cutting plane intersect a face at two different edges.
|
std::vector<int> create_face_neighbors_index(const indexed_triangle_set &its);
|
||||||
feGeneral,
|
std::vector<int> create_face_neighbors_index(const indexed_triangle_set &its, std::function<void()> throw_on_cancel_callback);
|
||||||
// Two vertices are aligned with the cutting plane, the third vertex is below the cutting plane.
|
// Remove degenerate faces, return number of faces removed.
|
||||||
feTop,
|
int its_remove_degenerate_faces(indexed_triangle_set &its, bool shrink_to_fit = true);
|
||||||
// Two vertices are aligned with the cutting plane, the third vertex is above the cutting plane.
|
// Remove vertices, which none of the faces references. Return number of freed vertices.
|
||||||
feBottom,
|
int its_compactify_vertices(indexed_triangle_set &its, bool shrink_to_fit = true);
|
||||||
// All three vertices of a face are aligned with the cutting plane.
|
void its_shrink_to_fit(indexed_triangle_set &its);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
TriangleMesh make_cube(double x, double y, double z);
|
TriangleMesh make_cube(double x, double y, double z);
|
||||||
|
|
||||||
|
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_
|
@ -5,6 +5,8 @@
|
|||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
|
|
||||||
#include "libslic3r/PrintBase.hpp"
|
#include "libslic3r/PrintBase.hpp"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "libslic3r/Tesselate.hpp"
|
#include "libslic3r/Tesselate.hpp"
|
||||||
#include "libslic3r/TriangleMesh.hpp"
|
#include "libslic3r/TriangleMesh.hpp"
|
||||||
|
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||||
#include "libslic3r/ClipperUtils.hpp"
|
#include "libslic3r/ClipperUtils.hpp"
|
||||||
|
|
||||||
#include "slic3r/GUI/Camera.hpp"
|
#include "slic3r/GUI/Camera.hpp"
|
||||||
@ -83,16 +84,17 @@ void MeshClipper::recalculate_triangles()
|
|||||||
// Now do the cutting
|
// Now do the cutting
|
||||||
std::vector<ExPolygons> list_of_expolys;
|
std::vector<ExPolygons> list_of_expolys;
|
||||||
m_tms->set_up_direction(up.cast<float>());
|
m_tms->set_up_direction(up.cast<float>());
|
||||||
m_tms->slice(std::vector<float>{height_mesh}, SlicingMode::Regular, 0.f, &list_of_expolys, [](){});
|
m_tms->slice(std::vector<float>{height_mesh}, MeshSlicingParamsExtended{}, &list_of_expolys);
|
||||||
|
|
||||||
if (m_negative_mesh && !m_negative_mesh->empty()) {
|
if (m_negative_mesh && !m_negative_mesh->empty()) {
|
||||||
TriangleMeshSlicer negative_tms{m_negative_mesh};
|
TriangleMeshSlicer negative_tms{m_negative_mesh};
|
||||||
negative_tms.set_up_direction(up.cast<float>());
|
negative_tms.set_up_direction(up.cast<float>());
|
||||||
|
|
||||||
std::vector<ExPolygons> neg_polys;
|
std::vector<ExPolygons> neg_polys;
|
||||||
negative_tms.slice(std::vector<float>{height_mesh}, SlicingMode::Regular, 0.f, &neg_polys, [](){});
|
negative_tms.slice(std::vector<float>{height_mesh}, MeshSlicingParamsExtended{}, &neg_polys);
|
||||||
list_of_expolys.front() = diff_ex(list_of_expolys.front(), neg_polys.front());
|
list_of_expolys.front() = diff_ex(list_of_expolys.front(), neg_polys.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_triangles2d = triangulate_expolygons_2f(list_of_expolys[0], m_trafo.get_matrix().matrix().determinant() < 0.);
|
m_triangles2d = triangulate_expolygons_2f(list_of_expolys[0], m_trafo.get_matrix().matrix().determinant() < 0.);
|
||||||
|
|
||||||
// Rotate the cut into world coords:
|
// Rotate the cut into world coords:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "libslic3r/Point.hpp"
|
#include "libslic3r/Point.hpp"
|
||||||
#include "libslic3r/Geometry.hpp"
|
#include "libslic3r/Geometry.hpp"
|
||||||
|
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||||
#include "libslic3r/SLA/IndexedMesh.hpp"
|
#include "libslic3r/SLA/IndexedMesh.hpp"
|
||||||
#include "admesh/stl.h"
|
#include "admesh/stl.h"
|
||||||
|
|
||||||
@ -12,9 +13,6 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
class TriangleMesh;
|
|
||||||
class TriangleMeshSlicer;
|
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
struct Camera;
|
struct Camera;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/nowide/convert.hpp>
|
#include <boost/nowide/convert.hpp>
|
||||||
#include <boost/nowide/cstdio.hpp>
|
#include <boost/nowide/cstdio.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
#include "libslic3r/Print.hpp"
|
#include "libslic3r/Print.hpp"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
#include "libslic3r/TriangleMesh.hpp"
|
#include "libslic3r/TriangleMesh.hpp"
|
||||||
|
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||||
#include "libslic3r/Point.hpp"
|
#include "libslic3r/Point.hpp"
|
||||||
#include "libslic3r/Config.hpp"
|
#include "libslic3r/Config.hpp"
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <libslic3r/SVG.hpp>
|
#include <libslic3r/SVG.hpp>
|
||||||
#include <libslic3r/ClipperUtils.hpp>
|
#include <libslic3r/ClipperUtils.hpp>
|
||||||
|
|
||||||
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||||
#include <libslic3r/TriangulateWall.hpp>
|
#include <libslic3r/TriangulateWall.hpp>
|
||||||
#include <libslic3r/Tesselate.hpp>
|
#include <libslic3r/Tesselate.hpp>
|
||||||
#include <libslic3r/SlicesToTriangleMesh.hpp>
|
#include <libslic3r/SlicesToTriangleMesh.hpp>
|
||||||
@ -320,7 +321,7 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
|
|||||||
bb = mesh.bounding_box();
|
bb = mesh.bounding_box();
|
||||||
|
|
||||||
std::vector<ExPolygons> layers;
|
std::vector<ExPolygons> layers;
|
||||||
slice_mesh(mesh, grid(float(bb.min.z()) + lh, float(bb.max.z()), lh), layers, 0.f, []{});
|
slice_mesh(mesh, grid(float(bb.min.z()) + lh, float(bb.max.z()), lh), layers);
|
||||||
|
|
||||||
sla::RasterBase::Resolution res{2560, 1440};
|
sla::RasterBase::Resolution res{2560, 1440};
|
||||||
double disp_w = 120.96;
|
double disp_w = 120.96;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "sla_test_utils.hpp"
|
#include "sla_test_utils.hpp"
|
||||||
|
|
||||||
|
#include <libslic3r/TriangleMeshSlicer.hpp>
|
||||||
#include <libslic3r/SLA/SupportTreeMesher.hpp>
|
#include <libslic3r/SLA/SupportTreeMesher.hpp>
|
||||||
#include <libslic3r/SLA/Concurrency.hpp>
|
#include <libslic3r/SLA/Concurrency.hpp>
|
||||||
|
|
||||||
@ -49,8 +50,6 @@ TEST_CASE("Support point generator should be deterministic if seeded",
|
|||||||
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
autogencfg.head_diameter = float(2 * supportcfg.head_front_radius_mm);
|
||||||
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
sla::SupportPointGenerator point_gen{emesh, autogencfg, [] {}, [](int) {}};
|
||||||
|
|
||||||
TriangleMeshSlicer slicer{&mesh};
|
|
||||||
|
|
||||||
auto bb = mesh.bounding_box();
|
auto bb = mesh.bounding_box();
|
||||||
double zmin = bb.min.z();
|
double zmin = bb.min.z();
|
||||||
double zmax = bb.max.z();
|
double zmax = bb.max.z();
|
||||||
@ -59,7 +58,7 @@ TEST_CASE("Support point generator should be deterministic if seeded",
|
|||||||
|
|
||||||
auto slicegrid = grid(float(gnd), float(zmax), layer_h);
|
auto slicegrid = grid(float(gnd), float(zmax), layer_h);
|
||||||
std::vector<ExPolygons> slices;
|
std::vector<ExPolygons> slices;
|
||||||
slicer.slice(slicegrid, SlicingMode::Regular, CLOSING_RADIUS, &slices, []{});
|
slice_mesh(mesh, slicegrid, CLOSING_RADIUS, slices);
|
||||||
|
|
||||||
point_gen.seed(0);
|
point_gen.seed(0);
|
||||||
point_gen.execute(slices, slicegrid);
|
point_gen.execute(slices, slicegrid);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "sla_test_utils.hpp"
|
#include "sla_test_utils.hpp"
|
||||||
|
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||||
#include "libslic3r/SLA/AGGRaster.hpp"
|
#include "libslic3r/SLA/AGGRaster.hpp"
|
||||||
|
|
||||||
void test_support_model_collision(const std::string &obj_filename,
|
void test_support_model_collision(const std::string &obj_filename,
|
||||||
@ -94,8 +95,6 @@ void test_supports(const std::string &obj_filename,
|
|||||||
mesh.require_shared_vertices();
|
mesh.require_shared_vertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
TriangleMeshSlicer slicer{&mesh};
|
|
||||||
|
|
||||||
auto bb = mesh.bounding_box();
|
auto bb = mesh.bounding_box();
|
||||||
double zmin = bb.min.z();
|
double zmin = bb.min.z();
|
||||||
double zmax = bb.max.z();
|
double zmax = bb.max.z();
|
||||||
@ -103,7 +102,7 @@ void test_supports(const std::string &obj_filename,
|
|||||||
auto layer_h = 0.05f;
|
auto layer_h = 0.05f;
|
||||||
|
|
||||||
out.slicegrid = grid(float(gnd), float(zmax), layer_h);
|
out.slicegrid = grid(float(gnd), float(zmax), layer_h);
|
||||||
slicer.slice(out.slicegrid, SlicingMode::Regular, CLOSING_RADIUS, &out.model_slices, []{});
|
slice_mesh(mesh, out.slicegrid, CLOSING_RADIUS, out.model_slices);
|
||||||
sla::cut_drainholes(out.model_slices, out.slicegrid, CLOSING_RADIUS, drainholes, []{});
|
sla::cut_drainholes(out.model_slices, out.slicegrid, CLOSING_RADIUS, drainholes, []{});
|
||||||
|
|
||||||
// Create the special index-triangle mesh with spatial indexing which
|
// Create the special index-triangle mesh with spatial indexing which
|
||||||
@ -470,7 +469,7 @@ sla::SupportPoints calc_support_pts(
|
|||||||
std::vector<ExPolygons> slices;
|
std::vector<ExPolygons> slices;
|
||||||
auto bb = cast<float>(mesh.bounding_box());
|
auto bb = cast<float>(mesh.bounding_box());
|
||||||
std::vector<float> heights = grid(bb.min.z(), bb.max.z(), 0.1f);
|
std::vector<float> heights = grid(bb.min.z(), bb.max.z(), 0.1f);
|
||||||
slice_mesh(mesh, heights, slices, CLOSING_RADIUS, [] {});
|
slice_mesh(mesh, heights, CLOSING_RADIUS, slices);
|
||||||
|
|
||||||
// Prepare the support point calculator
|
// Prepare the support point calculator
|
||||||
sla::IndexedMesh emesh{mesh};
|
sla::IndexedMesh emesh{mesh};
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
%{
|
%{
|
||||||
#include <xsinit.h>
|
#include <xsinit.h>
|
||||||
#include "libslic3r/TriangleMesh.hpp"
|
#include "libslic3r/TriangleMesh.hpp"
|
||||||
|
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%name{Slic3r::TriangleMesh} class TriangleMesh {
|
%name{Slic3r::TriangleMesh} class TriangleMesh {
|
||||||
@ -181,8 +182,7 @@ TriangleMesh::slice(z)
|
|||||||
std::vector<float> z_f = cast<float>(z);
|
std::vector<float> z_f = cast<float>(z);
|
||||||
|
|
||||||
std::vector<ExPolygons> layers;
|
std::vector<ExPolygons> layers;
|
||||||
TriangleMeshSlicer mslicer(THIS);
|
slice_mesh(*THIS, z_f, 0.049f, layers);
|
||||||
mslicer.slice(z_f, SlicingMode::Regular, 0.049f, &layers, [](){});
|
|
||||||
|
|
||||||
AV* layers_av = newAV();
|
AV* layers_av = newAV();
|
||||||
size_t len = layers.size();
|
size_t len = layers.size();
|
||||||
|
Loading…
Reference in New Issue
Block a user