Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::csg Namespace Reference

Namespaces

namespace  detail
 
namespace  detail_cgal
 

Classes

struct  CSGPart
 

Typedefs

using VoxelizeParams = MeshToGridParams
 

Enumerations

enum class  CSGType { Union , Difference , Intersection }
 
enum class  CSGStackOp { Push , Continue , Pop }
 
enum  ModelParts { mpartsPositive = 1 , mpartsNegative = 2 , mpartsDrillHoles = 4 , mpartsDoSplits = 8 }
 

Functions

template<class CSGPartT >
CSGType get_operation (const CSGPartT &part)
 
template<class CSGPartT >
CSGStackOp get_stack_operation (const CSGPartT &part)
 
template<class CSGPartT >
const indexed_triangle_setget_mesh (const CSGPartT &part)
 
template<class CSGPartT >
Transform3f get_transform (const CSGPartT &part)
 
template<class It , class OutIt >
void copy_csgrange_shallow (const Range< It > &csgrange, OutIt out)
 
template<class It , class OutIt >
void copy_csgrange_deep (const Range< It > &csgrange, OutIt out)
 
template<class ItA , class ItB >
bool is_same (const Range< ItA > &A, const Range< ItB > &B)
 
template<class OutIt >
void model_to_csgmesh (const ModelObject &mo, const Transform3d &trafo, OutIt out, int parts_to_include=mpartsPositive)
 
template<class CSGPartT >
MeshBoolean::cgal::CGALMeshPtr get_cgalmesh (const CSGPartT &csgpart)
 
template<class It >
void perform_csgmesh_booleans (MeshBoolean::cgal::CGALMeshPtr &cgalm, const Range< It > &csgrange)
 
template<class It , class Visitor >
It check_csgmesh_booleans (const Range< It > &csgrange, Visitor &&vfn)
 
template<class It >
It check_csgmesh_booleans (const Range< It > &csgrange)
 
template<class It >
MeshBoolean::cgal::CGALMeshPtr perform_csgmesh_booleans (const Range< It > &csgparts)
 
template<class ItCSG >
std::vector< ExPolygonsslice_csgmesh_ex (const Range< ItCSG > &csgrange, const std::vector< float > &slicegrid, const MeshSlicingParamsEx &params, const std::function< void()> &throw_on_cancel=[] {})
 
CSGType get_operation (const indexed_triangle_set &part)
 
CSGStackOp get_stack_operation (const indexed_triangle_set &part)
 
const indexed_triangle_setget_mesh (const indexed_triangle_set &part)
 
Transform3f get_transform (const indexed_triangle_set &part)
 
CSGType get_operation (const indexed_triangle_set *const part)
 
CSGStackOp get_stack_operation (const indexed_triangle_set *const part)
 
const indexed_triangle_setget_mesh (const indexed_triangle_set *const part)
 
Transform3f get_transform (const indexed_triangle_set *const part)
 
CSGType get_operation (const TriangleMesh &part)
 
CSGStackOp get_stack_operation (const TriangleMesh &part)
 
const indexed_triangle_setget_mesh (const TriangleMesh &part)
 
Transform3f get_transform (const TriangleMesh &part)
 
CSGType get_operation (const TriangleMesh *const part)
 
CSGStackOp get_stack_operation (const TriangleMesh *const part)
 
const indexed_triangle_setget_mesh (const TriangleMesh *const part)
 
Transform3f get_transform (const TriangleMesh *const part)
 
template<class CSGPartT >
VoxelGridPtr get_voxelgrid (const CSGPartT &csgpart, VoxelizeParams params)
 
template<class It >
VoxelGridPtr voxelize_csgmesh (const Range< It > &csgrange, const VoxelizeParams &params={})
 
MeshBoolean::cgal::CGALMeshPtr get_cgalmesh (const CSGPartForStep &part)
 

Typedef Documentation

◆ VoxelizeParams

Enumeration Type Documentation

◆ CSGStackOp

enum class Slic3r::csg::CSGStackOp
strong
Enumerator
Push 
Continue 
Pop 

◆ CSGType

enum class Slic3r::csg::CSGType
strong
Enumerator
Union 
Difference 
Intersection 
Definition AvoidCrossingPerimeters.cpp:30

◆ ModelParts

Enumerator
mpartsPositive 
mpartsNegative 
mpartsDrillHoles 
mpartsDoSplits 
14 {
15 mpartsPositive = 1, // Include positive parts
16 mpartsNegative = 2, // Include negative parts
17 mpartsDrillHoles = 4, // Include drill holes
18 mpartsDoSplits = 8, // Split each splitable mesh and export as a union of csg parts
19};
@ mpartsDrillHoles
Definition ModelToCSGMesh.hpp:17
@ mpartsDoSplits
Definition ModelToCSGMesh.hpp:18
@ mpartsPositive
Definition ModelToCSGMesh.hpp:15
@ mpartsNegative
Definition ModelToCSGMesh.hpp:16

Function Documentation

◆ check_csgmesh_booleans() [1/2]

template<class It >
It Slic3r::csg::check_csgmesh_booleans ( const Range< It > &  csgrange)
187{
188 return check_csgmesh_booleans(csgrange, [](auto &) {});
189}
It check_csgmesh_booleans(const Range< It > &csgrange, Visitor &&vfn)
Definition PerformCSGMeshBooleans.hpp:136

References check_csgmesh_booleans().

+ Here is the call graph for this function:

◆ check_csgmesh_booleans() [2/2]

template<class It , class Visitor >
It Slic3r::csg::check_csgmesh_booleans ( const Range< It > &  csgrange,
Visitor &&  vfn 
)
137{
138 using namespace detail_cgal;
139
140 std::vector<CGALMeshPtr> cgalmeshes(csgrange.size());
141 auto check_part = [&csgrange, &cgalmeshes](size_t i)
142 {
143 auto it = csgrange.begin();
144 std::advance(it, i);
145 auto &csgpart = *it;
146 auto m = get_cgalmesh(csgpart);
147
148 // mesh can be nullptr if this is a stack push or pull
149 if (!get_mesh(csgpart) && get_stack_operation(csgpart) != CSGStackOp::Continue) {
150 cgalmeshes[i] = MeshBoolean::cgal::triangle_mesh_to_cgal(indexed_triangle_set{});
151 return;
152 }
153
154 try {
155 if (!m || MeshBoolean::cgal::empty(*m))
156 return;
157
158 if (!MeshBoolean::cgal::does_bound_a_volume(*m))
159 return;
160
161 if (MeshBoolean::cgal::does_self_intersect(*m))
162 return;
163 }
164 catch (...) { return; }
165
166 cgalmeshes[i] = std::move(m);
167 };
168 execution::for_each(ex_tbb, size_t(0), csgrange.size(), check_part);
169
170 It ret = csgrange.end();
171 for (size_t i = 0; i < csgrange.size(); ++i) {
172 if (!cgalmeshes[i]) {
173 auto it = csgrange.begin();
174 std::advance(it, i);
175 vfn(it);
176
177 if (ret == csgrange.end())
178 ret = it;
179 }
180 }
181
182 return ret;
183}
It begin() const
Definition libslic3r.h:341
size_t size() const
Definition libslic3r.h:352
It end() const
Definition libslic3r.h:342
const indexed_triangle_set * get_mesh(const CSGPartT &part)
Definition CSGMesh.hpp:54
CSGStackOp get_stack_operation(const CSGPartT &part)
Definition CSGMesh.hpp:47
MeshBoolean::cgal::CGALMeshPtr get_cgalmesh(const CSGPartT &csgpart)
Definition PerformCSGMeshBooleans.hpp:18
Definition stl.h:157

References Slic3r::Range< It >::begin(), Continue, Slic3r::MeshBoolean::cgal::does_bound_a_volume(), Slic3r::MeshBoolean::cgal::does_self_intersect(), Slic3r::MeshBoolean::cgal::empty(), Slic3r::Range< It >::end(), Slic3r::ex_tbb, Slic3r::execution::for_each(), get_cgalmesh(), get_mesh(), get_stack_operation(), Slic3r::Range< It >::size(), and Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal().

Referenced by check_csgmesh_booleans(), Slic3r::GUI::Plater::export_stl_obj(), and Slic3r::SLAPrint::Steps::generate_preview().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copy_csgrange_deep()

template<class It , class OutIt >
void Slic3r::csg::copy_csgrange_deep ( const Range< It > &  csgrange,
OutIt  out 
)
38{
39 for (const auto &part : csgrange) {
40
41 CSGPart cpy{{}, get_operation(part), get_transform(part)};
42
43 if (auto meshptr = get_mesh(part)) {
44 cpy.its_ptr = std::make_unique<const indexed_triangle_set>(*meshptr);
45 }
46
47 cpy.stack_operation = get_stack_operation(part);
48
49 *out = std::move(cpy);
50 ++out;
51 }
52}
Definition CSGMesh.hpp:68

References get_mesh(), get_operation(), get_stack_operation(), and get_transform().

Referenced by Slic3r::GUI::MeshClipper::set_mesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copy_csgrange_shallow()

template<class It , class OutIt >
void Slic3r::csg::copy_csgrange_shallow ( const Range< It > &  csgrange,
OutIt  out 
)
13{
14 for (const auto &part : csgrange) {
15 CSGPart cpy{{},
16 get_operation(part),
17 get_transform(part)};
18
19 cpy.stack_operation = get_stack_operation(part);
20
21 if constexpr (std::is_convertible_v<decltype(part), const CSGPart&>) {
22 if (auto shptr = part.its_ptr.get_shared_cpy()) {
23 cpy.its_ptr = shptr;
24 }
25 }
26
27 if (!cpy.its_ptr)
28 cpy.its_ptr = AnyPtr<const indexed_triangle_set>{get_mesh(part)};
29
30 *out = std::move(cpy);
31 ++out;
32 }
33}

References get_mesh(), get_operation(), get_stack_operation(), and get_transform().

Referenced by Slic3r::SLAPrintObject::get_parts_to_slice(), and Slic3r::GUI::MeshClipper::set_mesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_cgalmesh() [1/2]

MeshBoolean::cgal::CGALMeshPtr Slic3r::csg::get_cgalmesh ( const CSGPartForStep part)
1181{
1182 if (!part.cgalcache && csg::get_mesh(part)) {
1183 part.cgalcache = csg::get_cgalmesh(static_cast<const csg::CSGPart&>(part));
1184 }
1185
1186 return part.cgalcache? clone(*part.cgalcache) : nullptr;
1187}
MeshBoolean::cgal::CGALMeshPtr cgalcache
Definition SLAPrint.hpp:64

References Slic3r::CSGPartForStep::cgalcache, and get_cgalmesh().

+ Here is the call graph for this function:

◆ get_cgalmesh() [2/2]

template<class CSGPartT >
MeshBoolean::cgal::CGALMeshPtr Slic3r::csg::get_cgalmesh ( const CSGPartT &  csgpart)
19{
20 const indexed_triangle_set *its = csg::get_mesh(csgpart);
22
23 if (!its)
24 its = &dummy;
25
27
28 indexed_triangle_set m = *its;
29 its_transform(m, get_transform(csgpart), true);
30
31 try {
32 ret = MeshBoolean::cgal::triangle_mesh_to_cgal(m);
33 } catch (...) {
34 // errors are ignored, simply return null
35 ret = nullptr;
36 }
37
38 return ret;
39}
std::unique_ptr< CGALMesh, CGALMeshDeleter > CGALMeshPtr
Definition MeshBoolean.hpp:29
Transform3f get_transform(const CSGPartT &part)
Definition CSGMesh.hpp:62
void its_transform(indexed_triangle_set &its, T *trafo3x4)
Definition stl.h:266

References get_mesh(), get_transform(), its_transform(), and Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal().

Referenced by check_csgmesh_booleans(), and get_cgalmesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_mesh() [1/5]

template<class CSGPartT >
const indexed_triangle_set * Slic3r::csg::get_mesh ( const CSGPartT &  part)
55{
56 return part.its_ptr.get();
57}

Referenced by check_csgmesh_booleans(), copy_csgrange_deep(), copy_csgrange_shallow(), Slic3r::csgmesh_merge_positive_parts(), Slic3r::csgmesh_positive_bb(), Slic3r::sla::csgmesh_positive_maxvolume(), get_cgalmesh(), get_voxelgrid(), and is_same().

+ Here is the caller graph for this function:

◆ get_mesh() [2/5]

const indexed_triangle_set * Slic3r::csg::get_mesh ( const indexed_triangle_set part)
inline
24{
25 return &part;
26}

◆ get_mesh() [3/5]

const indexed_triangle_set * Slic3r::csg::get_mesh ( const indexed_triangle_set *const  part)
inline
44{
45 return part;
46}

◆ get_mesh() [4/5]

const indexed_triangle_set * Slic3r::csg::get_mesh ( const TriangleMesh part)
inline
64{
65 return &part.its;
66}
indexed_triangle_set its
Definition TriangleMesh.hpp:155

References Slic3r::TriangleMesh::its.

◆ get_mesh() [5/5]

const indexed_triangle_set * Slic3r::csg::get_mesh ( const TriangleMesh *const  part)
inline
84{
85 return &part->its;
86}

References Slic3r::TriangleMesh::its.

◆ get_operation() [1/5]

template<class CSGPartT >
CSGType Slic3r::csg::get_operation ( const CSGPartT &  part)
42{
43 return part.operation;
44}

Referenced by copy_csgrange_deep(), copy_csgrange_shallow(), Slic3r::csgmesh_merge_positive_parts(), Slic3r::csgmesh_positive_bb(), Slic3r::sla::csgmesh_positive_maxvolume(), is_same(), perform_csgmesh_booleans(), and Slic3r::SLAPrint::Steps::slice_model().

+ Here is the caller graph for this function:

◆ get_operation() [2/5]

CSGType Slic3r::csg::get_operation ( const indexed_triangle_set part)
inline
14{
15 return CSGType::Union;
16}

References Union.

◆ get_operation() [3/5]

CSGType Slic3r::csg::get_operation ( const indexed_triangle_set *const  part)
inline
34{
35 return CSGType::Union;
36}

References Union.

◆ get_operation() [4/5]

CSGType Slic3r::csg::get_operation ( const TriangleMesh part)
inline
54{
55 return CSGType::Union;
56}

References Union.

◆ get_operation() [5/5]

CSGType Slic3r::csg::get_operation ( const TriangleMesh *const  part)
inline
74{
75 return CSGType::Union;
76}

References Union.

◆ get_stack_operation() [1/5]

template<class CSGPartT >
CSGStackOp Slic3r::csg::get_stack_operation ( const CSGPartT &  part)
48{
49 return part.stack_operation;
50}

Referenced by check_csgmesh_booleans(), copy_csgrange_deep(), copy_csgrange_shallow(), Slic3r::csgmesh_positive_bb(), Slic3r::sla::csgmesh_positive_maxvolume(), is_same(), and perform_csgmesh_booleans().

+ Here is the caller graph for this function:

◆ get_stack_operation() [2/5]

CSGStackOp Slic3r::csg::get_stack_operation ( const indexed_triangle_set part)
inline
19{
20 return CSGStackOp::Continue;
21}

References Continue.

◆ get_stack_operation() [3/5]

CSGStackOp Slic3r::csg::get_stack_operation ( const indexed_triangle_set *const  part)
inline
39{
40 return CSGStackOp::Continue;
41}

References Continue.

◆ get_stack_operation() [4/5]

CSGStackOp Slic3r::csg::get_stack_operation ( const TriangleMesh part)
inline
59{
60 return CSGStackOp::Continue;
61}

References Continue.

◆ get_stack_operation() [5/5]

CSGStackOp Slic3r::csg::get_stack_operation ( const TriangleMesh *const  part)
inline
79{
80 return CSGStackOp::Continue;
81}

References Continue.

◆ get_transform() [1/5]

template<class CSGPartT >
Transform3f Slic3r::csg::get_transform ( const CSGPartT &  part)
63{
64 return part.trafo;
65}

Referenced by copy_csgrange_deep(), copy_csgrange_shallow(), Slic3r::csgmesh_merge_positive_parts(), Slic3r::csgmesh_positive_bb(), get_cgalmesh(), get_voxelgrid(), and is_same().

+ Here is the caller graph for this function:

◆ get_transform() [2/5]

Transform3f Slic3r::csg::get_transform ( const indexed_triangle_set part)
inline
29{
30 return Transform3f::Identity();
31}

References Eigen::Transform< float, 3, Eigen::Affine, Eigen::DontAlign >::Identity().

+ Here is the call graph for this function:

◆ get_transform() [3/5]

Transform3f Slic3r::csg::get_transform ( const indexed_triangle_set *const  part)
inline
49{
50 return Transform3f::Identity();
51}

References Eigen::Transform< float, 3, Eigen::Affine, Eigen::DontAlign >::Identity().

+ Here is the call graph for this function:

◆ get_transform() [4/5]

Transform3f Slic3r::csg::get_transform ( const TriangleMesh part)
inline
69{
70 return Transform3f::Identity();
71}

References Eigen::Transform< float, 3, Eigen::Affine, Eigen::DontAlign >::Identity().

+ Here is the call graph for this function:

◆ get_transform() [5/5]

Transform3f Slic3r::csg::get_transform ( const TriangleMesh *const  part)
inline
89{
90 return Transform3f::Identity();
91}

References Eigen::Transform< float, 3, Eigen::Affine, Eigen::DontAlign >::Identity().

+ Here is the call graph for this function:

◆ get_voxelgrid()

template<class CSGPartT >
VoxelGridPtr Slic3r::csg::get_voxelgrid ( const CSGPartT &  csgpart,
VoxelizeParams  params 
)
19{
20 const indexed_triangle_set *its = csg::get_mesh(csgpart);
21 VoxelGridPtr ret;
22
23 params.trafo(params.trafo() * csg::get_transform(csgpart));
24
25 if (its)
26 ret = mesh_to_grid(*its, params);
27
28 return ret;
29}
MeshToGridParams & trafo(const Transform3f &v)
Definition OpenVDBUtils.hpp:35
VoxelGridPtr mesh_to_grid(const indexed_triangle_set &mesh, const MeshToGridParams &params)
Definition OpenVDBUtils.cpp:87
std::unique_ptr< VoxelGrid, VoxelGridDeleter > VoxelGridPtr
Definition OpenVDBUtils.hpp:10

References get_mesh(), get_transform(), Slic3r::mesh_to_grid(), and Slic3r::MeshToGridParams::trafo().

+ Here is the call graph for this function:

◆ is_same()

template<class ItA , class ItB >
bool Slic3r::csg::is_same ( const Range< ItA > &  A,
const Range< ItB > &  B 
)
56{
57 bool ret = true;
58
59 size_t s = A.size();
60
61 if (B.size() != s)
62 ret = false;
63
64 size_t i = 0;
65 auto itA = A.begin();
66 auto itB = B.begin();
67 for (; ret && i < s; ++itA, ++itB, ++i) {
68 ret = ret &&
69 get_mesh(*itA) == get_mesh(*itB) &&
70 get_operation(*itA) == get_operation(*itB) &&
73 }
74
75 return ret;
76}
EIGEN_DEVICE_FUNC bool isApprox(const Transform &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Transform.h:647
CSGType get_operation(const CSGPartT &part)
Definition CSGMesh.hpp:41

References Slic3r::Range< It >::begin(), get_mesh(), get_operation(), get_stack_operation(), get_transform(), Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::isApprox(), and Slic3r::Range< It >::size().

Referenced by Slic3r::GUI::MeshClipper::set_mesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ model_to_csgmesh()

template<class OutIt >
void Slic3r::csg::model_to_csgmesh ( const ModelObject mo,
const Transform3d trafo,
OutIt  out,
int  parts_to_include = mpartsPositive 
)
28{
29 bool do_positives = parts_to_include & mpartsPositive;
30 bool do_negatives = parts_to_include & mpartsNegative;
31 bool do_drillholes = parts_to_include & mpartsDrillHoles;
32 bool do_splits = parts_to_include & mpartsDoSplits;
33
34 for (const ModelVolume *vol : mo.volumes) {
35 if (vol && vol->mesh_ptr() &&
36 ((do_positives && vol->is_model_part()) ||
37 (do_negatives && vol->is_negative_volume()))) {
38
39 if (do_splits && its_is_splittable(vol->mesh().its)) {
40 CSGPart part_begin{{}, vol->is_model_part() ? CSGType::Union : CSGType::Difference};
41 part_begin.stack_operation = CSGStackOp::Push;
42 *out = std::move(part_begin);
43 ++out;
44
45 its_split(vol->mesh().its, SplitOutputFn{[&out, &vol, &trafo](indexed_triangle_set &&its) {
46 if (its.empty())
47 return;
48
49 CSGPart part{std::make_unique<indexed_triangle_set>(std::move(its)),
50 CSGType::Union,
51 (trafo * vol->get_matrix()).cast<float>()};
52
53 *out = std::move(part);
54 ++out;
55 }});
56
57 CSGPart part_end{{}};
58 part_end.stack_operation = CSGStackOp::Pop;
59 *out = std::move(part_end);
60 ++out;
61 } else {
62 CSGPart part{&(vol->mesh().its),
63 vol->is_model_part() ? CSGType::Union : CSGType::Difference,
64 (trafo * vol->get_matrix()).cast<float>()};
65
66 *out = std::move(part);
67 ++out;
68 }
69 }
70 }
71
72 if (do_drillholes) {
73 sla::DrainHoles drainholes = sla::transformed_drainhole_points(mo, trafo);
74
75 for (const sla::DrainHole &dhole : drainholes) {
76 CSGPart part{std::make_unique<const indexed_triangle_set>(
77 dhole.to_mesh()),
78 CSGType::Difference};
79
80 *out = std::move(part);
81 ++out;
82 }
83 }
84}
Definition Model.hpp:753
bool its_is_splittable(const Its &m)
Definition MeshSplitImpl.hpp:188
CSGStackOp stack_operation
Definition CSGMesh.hpp:72

References Difference, Slic3r::its_is_splittable(), Slic3r::its_split(), mpartsDoSplits, mpartsDrillHoles, mpartsNegative, mpartsPositive, Pop, Push, Slic3r::csg::CSGPart::stack_operation, Union, and Slic3r::ModelObject::volumes.

Referenced by Slic3r::SLAPrint::Steps::drill_holes(), Slic3r::GUI::Plater::export_stl_obj(), and Slic3r::SLAPrint::Steps::mesh_assembly().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ perform_csgmesh_booleans() [1/2]

template<class It >
MeshBoolean::cgal::CGALMeshPtr Slic3r::csg::perform_csgmesh_booleans ( const Range< It > &  csgparts)
193{
194 auto ret = MeshBoolean::cgal::triangle_mesh_to_cgal(indexed_triangle_set{});
195 if (ret)
196 perform_csgmesh_booleans(ret, csgparts);
197
198 return ret;
199}

References perform_csgmesh_booleans(), and Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal().

+ Here is the call graph for this function:

◆ perform_csgmesh_booleans() [2/2]

template<class It >
void Slic3r::csg::perform_csgmesh_booleans ( MeshBoolean::cgal::CGALMeshPtr cgalm,
const Range< It > &  csgrange 
)
89{
92 using namespace detail_cgal;
93
94 struct Frame {
95 CSGType op; CGALMeshPtr cgalptr;
96 explicit Frame(CSGType csgop = CSGType::Union)
97 : op{csgop}
98 , cgalptr{MeshBoolean::cgal::triangle_mesh_to_cgal(indexed_triangle_set{})}
99 {}
100 };
101
102 std::stack opstack{std::vector<Frame>{}};
103
104 opstack.push(Frame{});
105
106 std::vector<CGALMeshPtr> cgalmeshes = get_cgalptrs(ex_tbb, csgrange);
107
108 size_t csgidx = 0;
109 for (auto &csgpart : csgrange) {
110
111 auto op = get_operation(csgpart);
112 CGALMeshPtr &cgalptr = cgalmeshes[csgidx++];
113
114 if (get_stack_operation(csgpart) == CSGStackOp::Push) {
115 opstack.push(Frame{op});
116 op = CSGType::Union;
117 }
118
119 Frame *top = &opstack.top();
120
121 perform_csg(get_operation(csgpart), top->cgalptr, cgalptr);
122
123 if (get_stack_operation(csgpart) == CSGStackOp::Pop) {
124 CGALMeshPtr src = std::move(top->cgalptr);
125 auto popop = opstack.top().op;
126 opstack.pop();
127 CGALMeshPtr &dst = opstack.top().cgalptr;
128 perform_csg(popop, dst, src);
129 }
130 }
131
132 cgalm = std::move(opstack.top().cgalptr);
133}
Definition MeshBoolean.cpp:102
void perform_csg(CSGType op, CGALMeshPtr &dst, CGALMeshPtr &src)
Definition PerformCSGMeshBooleans.hpp:45
std::vector< CGALMeshPtr > get_cgalptrs(Ex policy, const Range< It > &csgrange)
Definition PerformCSGMeshBooleans.hpp:69
CSGType
Definition CSGMesh.hpp:20

References Slic3r::ex_tbb, get_operation(), get_stack_operation(), Pop, Push, and Union.

Referenced by Slic3r::GUI::Plater::export_stl_obj(), Slic3r::SLAPrint::Steps::generate_preview(), and perform_csgmesh_booleans().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ slice_csgmesh_ex()

template<class ItCSG >
std::vector< ExPolygons > Slic3r::csg::slice_csgmesh_ex ( const Range< ItCSG > &  csgrange,
const std::vector< float > &  slicegrid,
const MeshSlicingParamsEx params,
const std::function< void()> &  throw_on_cancel = [] {} 
)
53 {})
54{
55 using namespace detail;
56
57 struct Frame { CSGType op; std::vector<ExPolygons> slices; };
58
59 std::stack opstack{std::vector<Frame>{}};
60
61 MeshSlicingParamsEx params_cpy = params;
62 auto trafo = params.trafo;
63 auto nonempty_indices = reserve_vector<size_t>(slicegrid.size());
64
65 opstack.push({CSGType::Union, std::vector<ExPolygons>(slicegrid.size())});
66
67 for (const auto &csgpart : csgrange) {
68 const indexed_triangle_set *its = csg::get_mesh(csgpart);
69
70 auto op = get_operation(csgpart);
71
72 if (get_stack_operation(csgpart) == CSGStackOp::Push) {
73 opstack.push({op, std::vector<ExPolygons>(slicegrid.size())});
74 op = CSGType::Union;
75 }
76
77 Frame *top = &opstack.top();
78
79 if (its) {
80 params_cpy.trafo = trafo * csg::get_transform(csgpart).template cast<double>();
81 std::vector<ExPolygons> slices = slice_mesh_ex(*its,
82 slicegrid, params_cpy,
83 throw_on_cancel);
84
85 assert(slices.size() == slicegrid.size());
86
87 collect_nonempty_indices(op, slicegrid, slices, nonempty_indices);
88
89 execution::for_each(
90 ex_tbb, nonempty_indices.begin(), nonempty_indices.end(),
91 [op, &slices, &top](size_t i) {
92 merge_slices(op, i, top->slices, slices);
93 }, execution::max_concurrency(ex_tbb));
94 }
95
96 if (get_stack_operation(csgpart) == CSGStackOp::Pop) {
97 std::vector<ExPolygons> popslices = std::move(top->slices);
98 auto popop = opstack.top().op;
99 opstack.pop();
100 std::vector<ExPolygons> &prev_slices = opstack.top().slices;
101
102 collect_nonempty_indices(popop, slicegrid, popslices, nonempty_indices);
103
104 execution::for_each(
105 ex_tbb, nonempty_indices.begin(), nonempty_indices.end(),
106 [&popslices, &prev_slices, popop](size_t i) {
107 merge_slices(popop, i, prev_slices, popslices);
108 }, execution::max_concurrency(ex_tbb));
109 }
110 }
111
112 std::vector<ExPolygons> ret = std::move(opstack.top().slices);
113
114 // TODO: verify if this part can be omitted or not.
115 execution::for_each(ex_tbb, ret.begin(), ret.end(), [](ExPolygons &slice) {
116 auto it = std::remove_if(slice.begin(), slice.end(), [](const ExPolygon &p){
117 return p.area() < double(SCALED_EPSILON) * double(SCALED_EPSILON);
118 });
119
120 // Hopefully, ExPolygons are moved, not copied to new positions
121 // and that is cheap for expolygons
122 slice.erase(it, slice.end());
123 slice = union_ex(slice);
124 }, execution::max_concurrency(ex_tbb));
125
126 return ret;
127}
void collect_nonempty_indices(csg::CSGType op, const std::vector< float > &slicegrid, const std::vector< ExPolygons > &slices, std::vector< size_t > &indices)
Definition SliceCSGMesh.hpp:34
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, ClipperLib::PolyFillType fill_type)
Definition ClipperUtils.cpp:774
std::vector< ExPolygons > slice_mesh_ex(const indexed_triangle_set &mesh, const std::vector< float > &zs, const MeshSlicingParamsEx &params, std::function< void()> throw_on_cancel)
Definition TriangleMeshSlicer.cpp:1908
IGL_INLINE void slice(const Eigen::SparseMatrix< TX > &X, const Eigen::Matrix< int, Eigen::Dynamic, 1 > &R, const Eigen::Matrix< int, Eigen::Dynamic, 1 > &C, Eigen::SparseMatrix< TY > &Y)
Definition slice.cpp:15
Transform3d trafo
Definition TriangleMeshSlicer.hpp:35

Referenced by Slic3r::GUI::MeshClipper::recalculate_triangles().

+ Here is the caller graph for this function:

◆ voxelize_csgmesh()

template<class It >
VoxelGridPtr Slic3r::csg::voxelize_csgmesh ( const Range< It > &  csgrange,
const VoxelizeParams params = {} 
)
59 {})
60{
61 using namespace detail;
62
63 VoxelGridPtr ret;
64
65 std::vector<VoxelGridPtr> grids (csgrange.size());
66
67 execution::for_each(ex_tbb, size_t(0), csgrange.size(), [&](size_t csgidx) {
68 if (params.statusfn() && params.statusfn()(-1))
69 return;
70
71 auto it = csgrange.begin();
72 std::advance(it, csgidx);
73 auto &csgpart = *it;
74 grids[csgidx] = get_voxelgrid(csgpart, params);
75 }, execution::max_concurrency(ex_tbb));
76
77 size_t csgidx = 0;
78 struct Frame { CSGType op = CSGType::Union; VoxelGridPtr grid; };
79 std::stack opstack{std::vector<Frame>{}};
80
81 opstack.push({CSGType::Union, mesh_to_grid({}, params)});
82
83 for (auto &csgpart : csgrange) {
84 if (params.statusfn() && params.statusfn()(-1))
85 break;
86
87 auto &partgrid = grids[csgidx++];
88
89 auto op = get_operation(csgpart);
90
91 if (get_stack_operation(csgpart) == CSGStackOp::Push) {
92 opstack.push({op, mesh_to_grid({}, params)});
93 op = CSGType::Union;
94 }
95
96 Frame *top = &opstack.top();
97
98 perform_csg(get_operation(csgpart), top->grid, partgrid);
99
100 if (get_stack_operation(csgpart) == CSGStackOp::Pop) {
101 VoxelGridPtr popgrid = std::move(top->grid);
102 auto popop = opstack.top().op;
103 opstack.pop();
104 VoxelGridPtr &grid = opstack.top().grid;
105 perform_csg(popop, grid, popgrid);
106 }
107 }
108
109 ret = std::move(opstack.top().grid);
110
111 return ret;
112}
MeshToGridParams & statusfn(std::function< bool(int)> fn)
Definition OpenVDBUtils.hpp:39
IGL_INLINE void grid(const Eigen::MatrixBase< Derivedres > &res, Eigen::PlainObjectBase< DerivedGV > &GV)
Definition grid.cpp:13

Referenced by Slic3r::SLAPrint::Steps::generate_preview_vdb().

+ Here is the caller graph for this function: