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

Namespaces

namespace  detail
 

Classes

class  LinesDistancer
 

Functions

template<typename LineType >
AABBTreeIndirect::Tree< LineType::Dim, typename LineType::Scalar > build_aabb_tree_over_indexed_lines (const std::vector< LineType > &lines)
 
template<typename LineType , typename TreeType , typename VectorType >
VectorType::Scalar squared_distance_to_indexed_lines (const std::vector< LineType > &lines, const TreeType &tree, const VectorType &point, size_t &hit_idx_out, Eigen::PlainObjectBase< VectorType > &hit_point_out, typename VectorType::Scalar max_sqr_dist=std::numeric_limits< typename VectorType::Scalar >::infinity())
 
template<typename LineType , typename TreeType , typename VectorType >
std::vector< size_t > all_lines_in_radius (const std::vector< LineType > &lines, const TreeType &tree, const VectorType &point, typename VectorType::Scalar max_distance_squared)
 
template<typename LineType , typename TreeType , typename VectorType >
int point_outside_closed_contours (const std::vector< LineType > &lines, const TreeType &tree, const VectorType &point)
 
template<bool sorted, typename VectorType , typename LineType , typename TreeType >
std::vector< std::pair< VectorType, size_t > > get_intersections_with_line (const std::vector< LineType > &lines, const TreeType &tree, const LineType &line)
 

Function Documentation

◆ all_lines_in_radius()

template<typename LineType , typename TreeType , typename VectorType >
std::vector< size_t > Slic3r::AABBTreeLines::all_lines_in_radius ( const std::vector< LineType > &  lines,
const TreeType &  tree,
const VectorType &  point,
typename VectorType::Scalar  max_distance_squared 
)
inline
228{
229 auto distancer = detail::IndexedLinesDistancer<LineType, TreeType, VectorType>{lines, tree, point};
230
231 if (tree.empty()) { return {}; }
232
233 std::vector<size_t> found_lines{};
234 AABBTreeIndirect::detail::indexed_primitives_within_distance_squared_recurisve(distancer, size_t(0), max_distance_squared, found_lines);
235 return found_lines;
236}

References Slic3r::AABBTreeIndirect::detail::indexed_primitives_within_distance_squared_recurisve().

Referenced by Slic3r::AABBTreeLines::LinesDistancer< LineType >::all_lines_in_radius(), priv::collect_close_points(), and Slic3r::Emboss::divide_segments_for_close_point().

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

◆ build_aabb_tree_over_indexed_lines()

template<typename LineType >
AABBTreeIndirect::Tree< LineType::Dim, typename LineType::Scalar > Slic3r::AABBTreeLines::build_aabb_tree_over_indexed_lines ( const std::vector< LineType > &  lines)
inline
169{
171 // using CoordType = typename TreeType::CoordType;
172 using VectorType = typename TreeType::VectorType;
173 using BoundingBox = typename TreeType::BoundingBox;
174
175 struct InputType
176 {
177 size_t idx() const { return m_idx; }
178 const BoundingBox &bbox() const { return m_bbox; }
179 const VectorType &centroid() const { return m_centroid; }
180
181 size_t m_idx;
182 BoundingBox m_bbox;
183 VectorType m_centroid;
184 };
185
186 std::vector<InputType> input;
187 input.reserve(lines.size());
188 for (size_t i = 0; i < lines.size(); ++i) {
189 const LineType &line = lines[i];
190 InputType n;
191 n.m_idx = i;
192 n.m_centroid = (line.a + line.b) * 0.5;
193 n.m_bbox = BoundingBox(line.a, line.a);
194 n.m_bbox.extend(line.b);
195 input.emplace_back(n);
196 }
197
198 TreeType out;
199 out.build(std::move(input));
200 return out;
201}
Definition AABBTreeIndirect.hpp:40
Definition BoundingBox.hpp:181
static int input(void)

References input().

Referenced by Slic3r::AABBTreeLines::LinesDistancer< LineType >::LinesDistancer(), Slic3r::AABBTreeLines::LinesDistancer< LineType >::LinesDistancer(), priv::collect_close_points(), priv::create_search_data(), Slic3r::Emboss::divide_segments_for_close_point(), and Slic3r::FFFTreeSupport::organic_smooth_branches_avoid_collisions().

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

◆ get_intersections_with_line()

template<bool sorted, typename VectorType , typename LineType , typename TreeType >
std::vector< std::pair< VectorType, size_t > > Slic3r::AABBTreeLines::get_intersections_with_line ( const std::vector< LineType > &  lines,
const TreeType &  tree,
const LineType &  line 
)
inline
269{
270 if (tree.empty()) {
271 return {};
272 }
273 auto line_bb = typename TreeType::BoundingBox(line.a, line.a);
274 line_bb.extend(line.b);
275
276 auto intersections = detail::get_intersections_with_line<LineType, TreeType, VectorType>(0, tree, lines, line, line_bb);
277 if (sorted) {
278 using Floating =
279 typename std::conditional<std::is_floating_point<typename LineType::Scalar>::value, typename LineType::Scalar, double>::type;
280
281 std::vector<std::pair<Floating, std::pair<VectorType, size_t>>> points_with_sq_distance{};
282 for (const auto &p : intersections) {
283 points_with_sq_distance.emplace_back((p.first - line.a).template cast<Floating>().squaredNorm(), p);
284 }
285 std::sort(points_with_sq_distance.begin(), points_with_sq_distance.end(),
286 [](const std::pair<Floating, std::pair<VectorType, size_t>> &left,
287 std::pair<Floating, std::pair<VectorType, size_t>> &right) { return left.first < right.first; });
288 for (size_t i = 0; i < points_with_sq_distance.size(); i++) {
289 intersections[i] = points_with_sq_distance[i].second;
290 }
291 }
292
293 return intersections;
294}

◆ point_outside_closed_contours()

template<typename LineType , typename TreeType , typename VectorType >
int Slic3r::AABBTreeLines::point_outside_closed_contours ( const std::vector< LineType > &  lines,
const TreeType &  tree,
const VectorType &  point 
)
inline
241{
242 if (tree.empty()) { return 1; }
243
244 auto [hits_above, hits_below] = detail::coordinate_aligned_ray_hit_count<LineType, TreeType, VectorType, 0>(0, tree, lines, point);
245 if (hits_above < 0 || hits_below < 0) {
246 return 0;
247 } else if (hits_above % 2 == 1 && hits_below % 2 == 1) {
248 return -1;
249 } else if (hits_above % 2 == 0 && hits_below % 2 == 0) {
250 return 1;
251 } else { // this should not happen with closed contours. lets check it in Y direction
252 auto [hits_above, hits_below] = detail::coordinate_aligned_ray_hit_count<LineType, TreeType, VectorType, 1>(0, tree, lines, point);
253 if (hits_above < 0 || hits_below < 0) {
254 return 0;
255 } else if (hits_above % 2 == 1 && hits_below % 2 == 1) {
256 return -1;
257 } else if (hits_above % 2 == 0 && hits_below % 2 == 0) {
258 return 1;
259 } else { // both results were unclear
260 return 0;
261 }
262 }
263}

Referenced by Slic3r::AABBTreeLines::LinesDistancer< LineType >::outside().

+ Here is the caller graph for this function:

◆ squared_distance_to_indexed_lines()

template<typename LineType , typename TreeType , typename VectorType >
VectorType::Scalar Slic3r::AABBTreeLines::squared_distance_to_indexed_lines ( const std::vector< LineType > &  lines,
const TreeType &  tree,
const VectorType &  point,
size_t &  hit_idx_out,
Eigen::PlainObjectBase< VectorType > &  hit_point_out,
typename VectorType::Scalar  max_sqr_dist = std::numeric_limits<typename VectorType::Scalar>::infinity() 
)
inline
214{
215 using Scalar = typename VectorType::Scalar;
216 if (tree.empty()) return Scalar(-1);
217 auto distancer = detail::IndexedLinesDistancer<LineType, TreeType, VectorType>{lines, tree, point};
218 return AABBTreeIndirect::detail::squared_distance_to_indexed_primitives_recursive(distancer, size_t(0), Scalar(0), max_sqr_dist,
219 hit_idx_out, hit_point_out);
220}

References Slic3r::AABBTreeIndirect::detail::squared_distance_to_indexed_primitives_recursive().

Referenced by Slic3r::AABBTreeLines::LinesDistancer< LineType >::distance_from_lines_extra(), priv::find_closest_point_index(), and priv::find_closest_point_pair().

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