mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-17 06:25:52 +08:00
Caching of cgal data instead of voxel grid
This commit is contained in:
parent
159fc4e28e
commit
39197ecd2d
@ -315,6 +315,11 @@ bool empty(const CGALMesh &mesh)
|
|||||||
return mesh.m.is_empty();
|
return mesh.m.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGALMeshPtr clone(const CGALMesh &m)
|
||||||
|
{
|
||||||
|
return CGALMeshPtr{new CGALMesh{m}};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace cgal
|
} // namespace cgal
|
||||||
|
|
||||||
} // namespace MeshBoolean
|
} // namespace MeshBoolean
|
||||||
|
@ -28,6 +28,8 @@ struct CGALMesh;
|
|||||||
struct CGALMeshDeleter { void operator()(CGALMesh *ptr); };
|
struct CGALMeshDeleter { void operator()(CGALMesh *ptr); };
|
||||||
using CGALMeshPtr = std::unique_ptr<CGALMesh, CGALMeshDeleter>;
|
using CGALMeshPtr = std::unique_ptr<CGALMesh, CGALMeshDeleter>;
|
||||||
|
|
||||||
|
CGALMeshPtr clone(const CGALMesh &m);
|
||||||
|
|
||||||
CGALMeshPtr triangle_mesh_to_cgal(
|
CGALMeshPtr triangle_mesh_to_cgal(
|
||||||
const std::vector<stl_vertex> &V,
|
const std::vector<stl_vertex> &V,
|
||||||
const std::vector<stl_triangle_vertex_indices> &F);
|
const std::vector<stl_triangle_vertex_indices> &F);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "SLAPrint.hpp"
|
#include "SLAPrint.hpp"
|
||||||
#include "SLAPrintSteps.hpp"
|
#include "SLAPrintSteps.hpp"
|
||||||
|
#include "CSGMesh/PerformCSGMeshBooleans.hpp"
|
||||||
|
|
||||||
#include "Geometry.hpp"
|
#include "Geometry.hpp"
|
||||||
#include "Thread.hpp"
|
#include "Thread.hpp"
|
||||||
@ -1104,22 +1105,13 @@ void SLAPrint::StatusReporter::operator()(SLAPrint & p,
|
|||||||
|
|
||||||
namespace csg {
|
namespace csg {
|
||||||
|
|
||||||
inline bool operator==(const VoxelizeParams &a, const VoxelizeParams &b)
|
MeshBoolean::cgal::CGALMeshPtr get_cgalmesh(const CSGPartForStep &part)
|
||||||
{
|
{
|
||||||
std::hash<Slic3r::csg::VoxelizeParams> h;
|
if (!part.cgalcache && csg::get_mesh(part)) {
|
||||||
return h(a) == h(b);
|
part.cgalcache = csg::get_cgalmesh(static_cast<const csg::CSGPart&>(part));
|
||||||
}
|
|
||||||
|
|
||||||
VoxelGridPtr get_voxelgrid(const CSGPartForStep &part, VoxelizeParams p)
|
|
||||||
{
|
|
||||||
VoxelGridPtr &ret = part.gridcache[p];
|
|
||||||
|
|
||||||
if (!ret && csg::get_mesh(part)) {
|
|
||||||
p.trafo(csg::get_transform(part));
|
|
||||||
ret = mesh_to_grid(*csg::get_mesh(part), p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret ? clone(*ret) : nullptr;
|
return part.cgalcache? clone(*part.cgalcache) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace csg
|
} // namespace csg
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "Format/SLAArchiveWriter.hpp"
|
#include "Format/SLAArchiveWriter.hpp"
|
||||||
#include "GCode/ThumbnailData.hpp"
|
#include "GCode/ThumbnailData.hpp"
|
||||||
#include "libslic3r/CSGMesh/CSGMesh.hpp"
|
#include "libslic3r/CSGMesh/CSGMesh.hpp"
|
||||||
|
#include "libslic3r/MeshBoolean.hpp"
|
||||||
#include "libslic3r/OpenVDBUtils.hpp"
|
#include "libslic3r/OpenVDBUtils.hpp"
|
||||||
|
|
||||||
#include <boost/functional/hash.hpp>
|
#include <boost/functional/hash.hpp>
|
||||||
@ -49,41 +50,6 @@ enum SliceOrigin { soSupport, soModel };
|
|||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
namespace std {
|
|
||||||
|
|
||||||
template<> struct hash<Slic3r::csg::VoxelizeParams> {
|
|
||||||
size_t operator() (const Slic3r::csg::VoxelizeParams &p) const {
|
|
||||||
int64_t vs = Slic3r::scaled(p.voxel_scale()) >> 10;
|
|
||||||
int64_t eb = Slic3r::scaled(p.exterior_bandwidth()) >> 10;
|
|
||||||
int64_t ib = Slic3r::scaled(p.interior_bandwidth()) >> 10;
|
|
||||||
|
|
||||||
size_t h = 0;
|
|
||||||
boost::hash_combine(h, vs);
|
|
||||||
boost::hash_combine(h, eb);
|
|
||||||
boost::hash_combine(h, ib);
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<> struct equal_to<Slic3r::csg::VoxelizeParams> {
|
|
||||||
size_t operator() (const Slic3r::csg::VoxelizeParams &p1,
|
|
||||||
const Slic3r::csg::VoxelizeParams &p2) const {
|
|
||||||
|
|
||||||
int64_t vs1 = Slic3r::scaled(p1.voxel_scale()) >> 10;
|
|
||||||
int64_t eb1 = Slic3r::scaled(p1.exterior_bandwidth()) >> 10;
|
|
||||||
int64_t ib1 = Slic3r::scaled(p1.interior_bandwidth()) >> 10;
|
|
||||||
|
|
||||||
int64_t vs2 = Slic3r::scaled(p2.voxel_scale()) >> 10;
|
|
||||||
int64_t eb2 = Slic3r::scaled(p2.exterior_bandwidth()) >> 10;
|
|
||||||
int64_t ib2 = Slic3r::scaled(p2.interior_bandwidth()) >> 10;
|
|
||||||
|
|
||||||
return vs1 == vs2 && eb1 == eb2 && ib1 == ib2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace std
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
// Each sla object step can hold a collection of csg operations on the
|
// Each sla object step can hold a collection of csg operations on the
|
||||||
@ -95,7 +61,7 @@ namespace Slic3r {
|
|||||||
struct CSGPartForStep : public csg::CSGPart
|
struct CSGPartForStep : public csg::CSGPart
|
||||||
{
|
{
|
||||||
SLAPrintObjectStep key;
|
SLAPrintObjectStep key;
|
||||||
mutable std::unordered_map<csg::VoxelizeParams, VoxelGridPtr> gridcache;
|
mutable MeshBoolean::cgal::CGALMeshPtr cgalcache;
|
||||||
|
|
||||||
CSGPartForStep(SLAPrintObjectStep k, CSGPart &&p = {})
|
CSGPartForStep(SLAPrintObjectStep k, CSGPart &&p = {})
|
||||||
: key{k}, CSGPart{std::move(p)}
|
: key{k}, CSGPart{std::move(p)}
|
||||||
@ -114,7 +80,7 @@ struct CSGPartForStep : public csg::CSGPart
|
|||||||
|
|
||||||
namespace csg {
|
namespace csg {
|
||||||
|
|
||||||
VoxelGridPtr get_voxelgrid(const CSGPartForStep &part, VoxelizeParams p);
|
MeshBoolean::cgal::CGALMeshPtr get_cgalmesh(const CSGPartForStep &part);
|
||||||
|
|
||||||
} // namespace csg
|
} // namespace csg
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user