Caching of cgal data instead of voxel grid

This commit is contained in:
tamasmeszaros 2023-01-02 14:36:34 +01:00
parent 159fc4e28e
commit 39197ecd2d
4 changed files with 15 additions and 50 deletions

View file

@ -315,6 +315,11 @@ bool empty(const CGALMesh &mesh)
return mesh.m.is_empty();
}
CGALMeshPtr clone(const CGALMesh &m)
{
return CGALMeshPtr{new CGALMesh{m}};
}
} // namespace cgal
} // namespace MeshBoolean

View file

@ -28,6 +28,8 @@ struct CGALMesh;
struct CGALMeshDeleter { void operator()(CGALMesh *ptr); };
using CGALMeshPtr = std::unique_ptr<CGALMesh, CGALMeshDeleter>;
CGALMeshPtr clone(const CGALMesh &m);
CGALMeshPtr triangle_mesh_to_cgal(
const std::vector<stl_vertex> &V,
const std::vector<stl_triangle_vertex_indices> &F);

View file

@ -1,5 +1,6 @@
#include "SLAPrint.hpp"
#include "SLAPrintSteps.hpp"
#include "CSGMesh/PerformCSGMeshBooleans.hpp"
#include "Geometry.hpp"
#include "Thread.hpp"
@ -1104,22 +1105,13 @@ void SLAPrint::StatusReporter::operator()(SLAPrint & p,
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;
return h(a) == h(b);
}
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);
if (!part.cgalcache && csg::get_mesh(part)) {
part.cgalcache = csg::get_cgalmesh(static_cast<const csg::CSGPart&>(part));
}
return ret ? clone(*ret) : nullptr;
return part.cgalcache? clone(*part.cgalcache) : nullptr;
}
} // namespace csg

View file

@ -11,6 +11,7 @@
#include "Format/SLAArchiveWriter.hpp"
#include "GCode/ThumbnailData.hpp"
#include "libslic3r/CSGMesh/CSGMesh.hpp"
#include "libslic3r/MeshBoolean.hpp"
#include "libslic3r/OpenVDBUtils.hpp"
#include <boost/functional/hash.hpp>
@ -49,41 +50,6 @@ enum SliceOrigin { soSupport, soModel };
} // 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 {
// Each sla object step can hold a collection of csg operations on the
@ -95,7 +61,7 @@ namespace Slic3r {
struct CSGPartForStep : public csg::CSGPart
{
SLAPrintObjectStep key;
mutable std::unordered_map<csg::VoxelizeParams, VoxelGridPtr> gridcache;
mutable MeshBoolean::cgal::CGALMeshPtr cgalcache;
CSGPartForStep(SLAPrintObjectStep k, CSGPart &&p = {})
: key{k}, CSGPart{std::move(p)}
@ -114,7 +80,7 @@ struct CSGPartForStep : public csg::CSGPart
namespace csg {
VoxelGridPtr get_voxelgrid(const CSGPartForStep &part, VoxelizeParams p);
MeshBoolean::cgal::CGALMeshPtr get_cgalmesh(const CSGPartForStep &part);
} // namespace csg