Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::branchingtree::PointCloud Class Reference

#include <src/libslic3r/BranchingTree/PointCloud.hpp>

+ Collaboration diagram for Slic3r::branchingtree::PointCloud:

Classes

struct  CoordFn
 
struct  ZCompareFn
 

Public Member Functions

bool is_outside_support_cone (const Vec3f &supp, const Vec3f &pt) const
 
 PointCloud (const indexed_triangle_set &M, std::vector< Node > support_leafs, const Properties &props)
 
 PointCloud (std::vector< Node > meshpts, std::vector< Node > bedpts, std::vector< Node > support_leafs, const Properties &props)
 
PtType get_type (size_t node_id) const
 
const Nodeget (size_t node_id) const
 
Nodeget (size_t node_id)
 
const Nodefind (size_t node_id) const
 
Nodefind (size_t node_id)
 
int get_leaf_id (size_t node_id) const
 
size_t get_queue_idx (size_t node_id) const
 
float get_distance (const Vec3f &p, size_t node) const
 
size_t next_junction_id () const
 
size_t insert_junction (const Node &p)
 
const std::vector< Node > & get_junctions () const noexcept
 
const std::vector< Node > & get_bedpoints () const noexcept
 
const std::vector< Node > & get_meshpoints () const noexcept
 
const std::vector< Node > & get_leafs () const noexcept
 
const Propertiesproperties () const noexcept
 
void mark_unreachable (size_t node_id)
 
size_t reachable_count () const
 
template<class Fn >
void foreach_reachable (const Vec3f &pos, Fn &&visitor, size_t k, double min_dist=0.)
 
auto start_queue ()
 

Static Public Attributes

static constexpr auto Unqueued = size_t(-1)
 

Private Types

using PointIndexEl = std::pair< Vec3f, unsigned >
 

Static Private Member Functions

template<class PC >
static auto * get_node (PC &&pc, size_t id)
 

Private Attributes

std::vector< Nodem_leafs
 
std::vector< Nodem_junctions
 
std::vector< Nodem_meshpoints
 
std::vector< Nodem_bedpoints
 
const branchingtree::Propertiesm_props
 
const double cos2bridge_slope
 
const size_t MESHPTS_BEGIN
 
const size_t LEAFS_BEGIN
 
const size_t JUNCTIONS_BEGIN
 
std::vector< bool > m_searchable_indices
 
std::vector< size_t > m_queue_indices
 
size_t m_reachable_cnt
 
boost::geometry::index::rtree< PointIndexEl, boost::geometry::index::rstar< 16, 4 > > m_ktree
 

Detailed Description

Member Typedef Documentation

◆ PointIndexEl

using Slic3r::branchingtree::PointCloud::PointIndexEl = std::pair<Vec3f, unsigned>
private

Constructor & Destructor Documentation

◆ PointCloud() [1/2]

Slic3r::branchingtree::PointCloud::PointCloud ( const indexed_triangle_set M,
std::vector< Node support_leafs,
const Properties props 
)
95 : PointCloud{sample_mesh(M, props.sampling_radius()),
96 sample_bed(props.bed_shape(),
97 props.ground_level(),
98 props.sampling_radius()),
99 std::move(support_leafs), props}
100{}
PointCloud(const indexed_triangle_set &M, std::vector< Node > support_leafs, const Properties &props)
Definition PointCloud.cpp:92
std::vector< Node > sample_bed(const ExPolygons &bed, float z, double radius)
Definition PointCloud.cpp:75
std::vector< Node > sample_mesh(const indexed_triangle_set &its, double radius)
Definition PointCloud.cpp:28

◆ PointCloud() [2/2]

Slic3r::branchingtree::PointCloud::PointCloud ( std::vector< Node meshpts,
std::vector< Node bedpts,
std::vector< Node support_leafs,
const Properties props 
)
106 : m_leafs{std::move(support_leafs)}
107 , m_meshpoints{std::move(meshpts)}
108 , m_bedpoints{std::move(bedpts)}
109 , m_props{props}
110 , cos2bridge_slope{std::cos(props.max_slope()) *
111 std::abs(std::cos(props.max_slope()))}
112 , MESHPTS_BEGIN{m_bedpoints.size()}
118{
119 for (size_t i = 0; i < m_bedpoints.size(); ++i) {
120 m_bedpoints[i].id = int(i);
121 m_ktree.insert({m_bedpoints[i].pos, i});
122 }
123
124 for (size_t i = 0; i < m_meshpoints.size(); ++i) {
125 Node &n = m_meshpoints[i];
126 n.id = int(MESHPTS_BEGIN + i);
127 m_ktree.insert({n.pos, n.id});
128 }
129
130 for (size_t i = 0; i < m_leafs.size(); ++i) {
131 Node &n = m_leafs[i];
132 n.id = int(LEAFS_BEGIN + i);
133 n.left = Node::ID_NONE;
134 n.right = Node::ID_NONE;
135
136 m_ktree.insert({n.pos, n.id});
137 }
138}
const size_t LEAFS_BEGIN
Definition PointCloud.hpp:54
std::vector< size_t > m_queue_indices
Definition PointCloud.hpp:61
std::vector< Node > m_junctions
Definition PointCloud.hpp:49
const double cos2bridge_slope
Definition PointCloud.hpp:53
std::vector< Node > m_leafs
Definition PointCloud.hpp:49
size_t m_reachable_cnt
Definition PointCloud.hpp:63
std::vector< bool > m_searchable_indices
Definition PointCloud.hpp:60
std::vector< Node > m_meshpoints
Definition PointCloud.hpp:49
const branchingtree::Properties & m_props
Definition PointCloud.hpp:51
static constexpr auto Unqueued
Definition PointCloud.hpp:107
const size_t JUNCTIONS_BEGIN
Definition PointCloud.hpp:54
std::vector< Node > m_bedpoints
Definition PointCloud.hpp:49
const size_t MESHPTS_BEGIN
Definition PointCloud.hpp:54
boost::geometry::index::rtree< PointIndexEl, boost::geometry::index::rstar< 16, 4 > > m_ktree
Definition PointCloud.hpp:79
static constexpr int ID_NONE
Definition BranchingTree.hpp:65

References Slic3r::branchingtree::Node::id, Slic3r::branchingtree::Node::ID_NONE, LEAFS_BEGIN, Slic3r::branchingtree::Node::left, m_bedpoints, m_ktree, m_leafs, m_meshpoints, MESHPTS_BEGIN, Slic3r::branchingtree::Node::pos, and Slic3r::branchingtree::Node::right.

Member Function Documentation

◆ find() [1/2]

Node * Slic3r::branchingtree::PointCloud::find ( size_t  node_id)
inline
151{ return get_node(*this, node_id); }
static auto * get_node(PC &&pc, size_t id)
Definition PointCloud.hpp:82

References get_node().

+ Here is the call graph for this function:

◆ find() [2/2]

const Node * Slic3r::branchingtree::PointCloud::find ( size_t  node_id) const
inline
150{ return get_node(*this, node_id); }

References get_node().

+ Here is the call graph for this function:

◆ foreach_reachable()

template<class Fn >
void Slic3r::branchingtree::PointCloud::foreach_reachable ( const Vec3f pos,
Fn &&  visitor,
size_t  k,
double  min_dist = 0. 
)
inline
206 {
207 // Fake output iterator
208 struct Output {
209 const PointCloud *self;
210 Vec3f p;
211 Fn &visitorfn;
212
213 Output& operator *() { return *this; }
214 void operator=(const PointIndexEl &el) {
215 visitorfn(el.second, self->get_distance(p, el.second),
216 (p - el.first).squaredNorm());
217 }
218 Output& operator++() { return *this; }
219 };
220
221 namespace bgi = boost::geometry::index;
222 float brln = 2 * m_props.max_branch_length();
223 BoundingBox3Base<Vec3f> bb{{pos.x() - brln, pos.y() - brln,
224 float(m_props.ground_level() - EPSILON)},
225 {pos.x() + brln, pos.y() + brln,
226 m_ktree.bounds().max_corner().get<Z>()}};
227
228 // Extend upwards to find mergable junctions and support points
229 bb.max.z() = m_ktree.bounds().max_corner().get<Z>();
230
231 auto filter = bgi::satisfies(
232 [this, &pos, min_dist](const PointIndexEl &e) {
233 double D_branching = get_distance(pos, e.second);
234 double D_euql = (pos - e.first).squaredNorm() ;
235 return m_searchable_indices[e.second] &&
236 !std::isinf(D_branching) && D_euql > min_dist;
237 });
238
239 m_ktree.query(bgi::intersects(bb) && filter && bgi::nearest(pos, k),
240 Output{this, pos, visitor});
241 }
float get_distance(const Vec3f &p, size_t node) const
Definition PointCloud.cpp:140
std::pair< Vec3f, unsigned > PointIndexEl
Definition PointCloud.hpp:75
Properties & ground_level(double val) noexcept
Definition BranchingTree.hpp:31
Properties & max_branch_length(double val) noexcept
Definition BranchingTree.hpp:49
static constexpr double EPSILON
Definition libslic3r.h:51
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:14
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49
@ Z
Definition libslic3r.h:100

References EPSILON, get_distance(), Slic3r::branchingtree::Properties::ground_level(), m_ktree, m_props, m_searchable_indices, Slic3r::branchingtree::Properties::max_branch_length(), and Slic3r::Z.

Referenced by Slic3r::branchingtree::build_tree().

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

◆ get() [1/2]

Node & Slic3r::branchingtree::PointCloud::get ( size_t  node_id)
inline
146 {
147 return *get_node(*this, node_id);
148 }

References get_node().

+ Here is the call graph for this function:

◆ get() [2/2]

const Node & Slic3r::branchingtree::PointCloud::get ( size_t  node_id) const
inline
141 {
142 return *get_node(*this, node_id);
143 }

References get_node().

Referenced by Slic3r::sla::BranchingTreeBuilder::build_subtree(), Slic3r::branchingtree::build_tree(), Slic3r::sla::BranchingTreeBuilder::discard_subtree_rescure(), get_distance(), Slic3r::branchingtree::PointCloud::ZCompareFn::operator()(), and Slic3r::branchingtree::PointCloud::CoordFn::operator()().

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

◆ get_bedpoints()

const std::vector< Node > & Slic3r::branchingtree::PointCloud::get_bedpoints ( ) const
inlinenoexcept
185{ return m_bedpoints; }

References m_bedpoints.

◆ get_distance()

float Slic3r::branchingtree::PointCloud::get_distance ( const Vec3f p,
size_t  node 
) const
141{
142 auto t = get_type(node_id);
143 auto ret = std::numeric_limits<float>::infinity();
144 const auto &node = get(node_id);
145
146 switch (t) {
147 case MESH:
148 case BED: {
149 // Points of mesh or bed which are outside of the support cone of
150 // 'pos' must be discarded.
151 if (is_outside_support_cone(p, node.pos))
152 ret = std::numeric_limits<float>::infinity();
153 else
154 ret = (node.pos - p).norm();
155
156 break;
157 }
158 case LEAF:
159 case JUNCTION:{
160 auto mergept = find_merge_pt(p, node.pos, m_props.max_slope());
162
163 if (!mergept || mergept->z() < (m_props.ground_level() + 2 * node.Rmin))
164 ret = std::numeric_limits<float>::infinity();
165 else if (double a = (node.pos - *mergept).squaredNorm(),
166 b = (p - *mergept).squaredNorm();
167 a < maxL2 && b < maxL2)
168 ret = std::sqrt(b);
169
170 break;
171 }
172 case NONE:
173 ;
174 }
175
176 // Setting the ret val to infinity will effectively discard this
177 // connection of nodes. max_branch_length property is used here
178 // to discard node=>node and node=>mesh connections longer than this
179 // property.
180 if (t != BED && ret > m_props.max_branch_length())
181 ret = std::numeric_limits<float>::infinity();
182
183 return ret;
184}
PtType get_type(size_t node_id) const
Definition PointCloud.hpp:128
bool is_outside_support_cone(const Vec3f &supp, const Vec3f &pt) const
Definition PointCloud.hpp:99
const Node & get(size_t node_id) const
Definition PointCloud.hpp:140
Properties & max_slope(double val) noexcept
Definition BranchingTree.hpp:25
@ LEAF
Definition PointCloud.hpp:30
@ NONE
Definition PointCloud.hpp:30
@ BED
Definition PointCloud.hpp:30
@ MESH
Definition PointCloud.hpp:30
@ JUNCTION
Definition PointCloud.hpp:30
std::optional< Vec3f > find_merge_pt(const Vec3f &A, const Vec3f &B, float max_slope)
Definition PointCloud.cpp:10

References Slic3r::branchingtree::BED, Slic3r::branchingtree::find_merge_pt(), get(), get_type(), Slic3r::branchingtree::Properties::ground_level(), is_outside_support_cone(), Slic3r::branchingtree::JUNCTION, Slic3r::branchingtree::LEAF, m_props, Slic3r::branchingtree::Properties::max_branch_length(), Slic3r::branchingtree::Properties::max_slope(), Slic3r::branchingtree::MESH, and Slic3r::branchingtree::NONE.

Referenced by foreach_reachable().

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

◆ get_junctions()

const std::vector< Node > & Slic3r::branchingtree::PointCloud::get_junctions ( ) const
inlinenoexcept
184{ return m_junctions; }

References m_junctions.

◆ get_leaf_id()

int Slic3r::branchingtree::PointCloud::get_leaf_id ( size_t  node_id) const
inline
156 {
157 return node_id >= LEAFS_BEGIN && node_id < JUNCTIONS_BEGIN ?
158 node_id - LEAFS_BEGIN :
160 }

References Slic3r::branchingtree::Node::ID_NONE, JUNCTIONS_BEGIN, and LEAFS_BEGIN.

Referenced by Slic3r::sla::BranchingTreeBuilder::discard_subtree(), and Slic3r::sla::BranchingTreeBuilder::discard_subtree_rescure().

+ Here is the caller graph for this function:

◆ get_leafs()

const std::vector< Node > & Slic3r::branchingtree::PointCloud::get_leafs ( ) const
inlinenoexcept
187{ return m_leafs; }

References m_leafs.

◆ get_meshpoints()

const std::vector< Node > & Slic3r::branchingtree::PointCloud::get_meshpoints ( ) const
inlinenoexcept
186{ return m_meshpoints; }

References m_meshpoints.

◆ get_node()

template<class PC >
static auto * Slic3r::branchingtree::PointCloud::get_node ( PC &&  pc,
size_t  id 
)
inlinestaticprivate
83 {
84 auto *ret = decltype(pc.m_bedpoints.data())(nullptr);
85
86 switch(pc.get_type(id)) {
87 case BED: ret = &pc.m_bedpoints[id]; break;
88 case MESH: ret = &pc.m_meshpoints[id - pc.MESHPTS_BEGIN]; break;
89 case LEAF: ret = &pc.m_leafs [id - pc.LEAFS_BEGIN]; break;
90 case JUNCTION: ret = &pc.m_junctions[id - pc.JUNCTIONS_BEGIN]; break;
91 case NONE: assert(false);
92 }
93
94 return ret;
95 }

References Slic3r::branchingtree::BED, Slic3r::branchingtree::JUNCTION, Slic3r::branchingtree::LEAF, Slic3r::branchingtree::MESH, and Slic3r::branchingtree::NONE.

Referenced by find(), find(), get(), and get().

+ Here is the caller graph for this function:

◆ get_queue_idx()

size_t Slic3r::branchingtree::PointCloud::get_queue_idx ( size_t  node_id) const
inline
162{ return m_queue_indices[node_id]; }

References m_queue_indices.

Referenced by Slic3r::branchingtree::build_tree().

+ Here is the caller graph for this function:

◆ get_type()

PtType Slic3r::branchingtree::PointCloud::get_type ( size_t  node_id) const
inline
129 {
130 PtType ret = NONE;
131
132 if (node_id < MESHPTS_BEGIN && !m_bedpoints.empty()) ret = BED;
133 else if (node_id < LEAFS_BEGIN && !m_meshpoints.empty()) ret = MESH;
134 else if (node_id < JUNCTIONS_BEGIN && !m_leafs.empty()) ret = LEAF;
135 else if (node_id >= JUNCTIONS_BEGIN && !m_junctions.empty()) ret = JUNCTION;
136
137 return ret;
138 }
PtType
Definition PointCloud.hpp:30

References Slic3r::branchingtree::BED, Slic3r::branchingtree::JUNCTION, JUNCTIONS_BEGIN, Slic3r::branchingtree::LEAF, LEAFS_BEGIN, m_bedpoints, m_junctions, m_leafs, m_meshpoints, Slic3r::branchingtree::MESH, MESHPTS_BEGIN, and Slic3r::branchingtree::NONE.

Referenced by Slic3r::branchingtree::build_tree(), and get_distance().

+ Here is the caller graph for this function:

◆ insert_junction()

size_t Slic3r::branchingtree::PointCloud::insert_junction ( const Node p)
inline
172 {
173 size_t new_id = next_junction_id();
174 m_junctions.emplace_back(p);
175 m_junctions.back().id = int(new_id);
176 m_ktree.insert({m_junctions.back().pos, new_id});
177 m_searchable_indices.emplace_back(true);
178 m_queue_indices.emplace_back(Unqueued);
180
181 return new_id;
182 }
size_t next_junction_id() const
Definition PointCloud.hpp:166

References m_junctions, m_ktree, m_queue_indices, m_reachable_cnt, m_searchable_indices, next_junction_id(), and Unqueued.

Referenced by Slic3r::branchingtree::build_tree().

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

◆ is_outside_support_cone()

bool Slic3r::branchingtree::PointCloud::is_outside_support_cone ( const Vec3f supp,
const Vec3f pt 
) const
inline
100 {
101 Vec3d D = (pt - supp).cast<double>();
102 double dot_sq = -D.z() * std::abs(-D.z());
103
104 return dot_sq < D.squaredNorm() * cos2bridge_slope;
105 }
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:52

References cos2bridge_slope.

Referenced by get_distance().

+ Here is the caller graph for this function:

◆ mark_unreachable()

void Slic3r::branchingtree::PointCloud::mark_unreachable ( size_t  node_id)
inline
191 {
192 assert(node_id < m_searchable_indices.size());
193
194 m_searchable_indices[node_id] = false;
195 m_queue_indices[node_id] = Unqueued;
197 }

References m_queue_indices, m_reachable_cnt, m_searchable_indices, and Unqueued.

Referenced by Slic3r::branchingtree::build_tree().

+ Here is the caller graph for this function:

◆ next_junction_id()

size_t Slic3r::branchingtree::PointCloud::next_junction_id ( ) const
inline
167 {
168 return JUNCTIONS_BEGIN + m_junctions.size();
169 }

References JUNCTIONS_BEGIN, and m_junctions.

Referenced by Slic3r::branchingtree::build_tree(), and insert_junction().

+ Here is the caller graph for this function:

◆ properties()

const Properties & Slic3r::branchingtree::PointCloud::properties ( ) const
inlinenoexcept
188{ return m_props; }

References m_props.

Referenced by Slic3r::branchingtree::build_tree().

+ Here is the caller graph for this function:

◆ reachable_count()

size_t Slic3r::branchingtree::PointCloud::reachable_count ( ) const
inline
199{ return m_reachable_cnt; }

References m_reachable_cnt.

◆ start_queue()

auto Slic3r::branchingtree::PointCloud::start_queue ( )
inline
244 {
245 auto ptsqueue = make_mutable_priority_queue<size_t, true>(
246 [this](size_t el, size_t idx) { m_queue_indices[el] = idx; },
247 ZCompareFn{this});
248
249 ptsqueue.reserve(m_leafs.size());
250 size_t iend = LEAFS_BEGIN + m_leafs.size();
251 for (size_t i = LEAFS_BEGIN; i < iend; ++i)
252 ptsqueue.push(i);
253
254 return ptsqueue;
255 }

References LEAFS_BEGIN, m_leafs, and m_queue_indices.

Referenced by Slic3r::branchingtree::build_tree().

+ Here is the caller graph for this function:

Member Data Documentation

◆ cos2bridge_slope

const double Slic3r::branchingtree::PointCloud::cos2bridge_slope
private

Referenced by is_outside_support_cone().

◆ JUNCTIONS_BEGIN

const size_t Slic3r::branchingtree::PointCloud::JUNCTIONS_BEGIN
private

◆ LEAFS_BEGIN

const size_t Slic3r::branchingtree::PointCloud::LEAFS_BEGIN
private

◆ m_bedpoints

std::vector<Node> Slic3r::branchingtree::PointCloud::m_bedpoints
private

Referenced by PointCloud(), get_bedpoints(), and get_type().

◆ m_junctions

std::vector<Node> Slic3r::branchingtree::PointCloud::m_junctions
private

◆ m_ktree

boost::geometry::index:: rtree<PointIndexEl, boost::geometry::index::rstar<16, 4> > Slic3r::branchingtree::PointCloud::m_ktree
private

◆ m_leafs

std::vector<Node> Slic3r::branchingtree::PointCloud::m_leafs
private

◆ m_meshpoints

std::vector<Node> Slic3r::branchingtree::PointCloud::m_meshpoints
private

◆ m_props

const branchingtree::Properties& Slic3r::branchingtree::PointCloud::m_props
private

◆ m_queue_indices

std::vector<size_t> Slic3r::branchingtree::PointCloud::m_queue_indices
private

◆ m_reachable_cnt

size_t Slic3r::branchingtree::PointCloud::m_reachable_cnt
private

◆ m_searchable_indices

std::vector<bool> Slic3r::branchingtree::PointCloud::m_searchable_indices
private

◆ MESHPTS_BEGIN

const size_t Slic3r::branchingtree::PointCloud::MESHPTS_BEGIN
private

Referenced by PointCloud(), and get_type().

◆ Unqueued

constexpr auto Slic3r::branchingtree::PointCloud::Unqueued = size_t(-1)
staticconstexpr

The documentation for this class was generated from the following files: