OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::AABBTreeLines::detail Namespace Reference

Classes

struct  IndexedLinesDistancer

Functions

template<typename LineType, typename TreeType, typename VectorType, int coordinate>
std::tuple< int, int > coordinate_aligned_ray_hit_count (size_t node_idx, const TreeType &tree, const std::vector< LineType > &lines, const VectorType &ray_origin)
template<typename LineType, typename TreeType, typename VectorType>
std::vector< std::pair< VectorType, size_t > > get_intersections_with_line (size_t node_idx, const TreeType &tree, const std::vector< LineType > &lines, const LineType &line, const typename TreeType::BoundingBox &line_bb)

Function Documentation

◆ coordinate_aligned_ray_hit_count()

template<typename LineType, typename TreeType, typename VectorType, int coordinate>
std::tuple< int, int > Slic3r::AABBTreeLines::detail::coordinate_aligned_ray_hit_count ( size_t node_idx,
const TreeType & tree,
const std::vector< LineType > & lines,
const VectorType & ray_origin )
inline
55 {
56 static constexpr int other_coordinate = (coordinate + 1) % 2;
57 using Scalar = typename LineType::Scalar;
58 using Floating = typename std::conditional<std::is_floating_point<Scalar>::value, Scalar, double>::type;
59 const auto& node = tree.node(node_idx);
60 assert(node.is_valid());
61 if (node.is_leaf()) {
62 const LineType& line = lines[node.idx];
63 if (ray_origin[other_coordinate] < std::min(line.a[other_coordinate], line.b[other_coordinate]) || ray_origin[other_coordinate] >= std::max(line.a[other_coordinate], line.b[other_coordinate])) {
64 // the second inequality is nonsharp for a reason
65 // without it, we may count contour border twice when the lines meet exactly at the spot of intersection. this prevents is
66 return { 0, 0 };
67 }
68
69 Scalar line_max = std::max(line.a[coordinate], line.b[coordinate]);
70 Scalar line_min = std::min(line.a[coordinate], line.b[coordinate]);
71 if (ray_origin[coordinate] > line_max) {
72 return { 1, 0 };
73 } else if (ray_origin[coordinate] < line_min) {
74 return { 0, 1 };
75 } else {
76 // find intersection of ray with line
77 // that is when ( line.a + t * (line.b - line.a) )[other_coordinate] == ray_origin[other_coordinate]
78 // t = ray_origin[oc] - line.a[oc] / (line.b[oc] - line.a[oc]);
79 // then we want to get value of intersection[ coordinate]
80 // val_c = line.a[c] + t * (line.b[c] - line.a[c]);
81 // Note that ray and line may overlap, when (line.b[oc] - line.a[oc]) is zero
82 // In that case, we return negative number
83 Floating distance_oc = line.b[other_coordinate] - line.a[other_coordinate];
84 Floating t = (ray_origin[other_coordinate] - line.a[other_coordinate]) / distance_oc;
85 Floating val_c = line.a[coordinate] + t * (line.b[coordinate] - line.a[coordinate]);
86 if (ray_origin[coordinate] > val_c) {
87 return { 1, 0 };
88 } else if (ray_origin[coordinate] < val_c) {
89 return { 0, 1 };
90 } else { // ray origin is on boundary
91 return { -1, -1 };
92 }
93 }
94 } else {
95 int intersections_above = 0;
96 int intersections_below = 0;
97 size_t left_node_idx = node_idx * 2 + 1;
98 size_t right_node_idx = left_node_idx + 1;
99 const auto& node_left = tree.node(left_node_idx);
100 const auto& node_right = tree.node(right_node_idx);
101 assert(node_left.is_valid());
102 assert(node_right.is_valid());
103
104 if (node_left.bbox.min()[other_coordinate] <= ray_origin[other_coordinate] && node_left.bbox.max()[other_coordinate] >= ray_origin[other_coordinate]) {
105 auto [above, below] = coordinate_aligned_ray_hit_count<LineType, TreeType, VectorType, coordinate>(left_node_idx, tree, lines,
106 ray_origin);
107 if (above < 0 || below < 0)
108 return { -1, -1 };
109 intersections_above += above;
110 intersections_below += below;
111 }
112
113 if (node_right.bbox.min()[other_coordinate] <= ray_origin[other_coordinate] && node_right.bbox.max()[other_coordinate] >= ray_origin[other_coordinate]) {
114 auto [above, below] = coordinate_aligned_ray_hit_count<LineType, TreeType, VectorType, coordinate>(right_node_idx, tree, lines,
115 ray_origin);
116 if (above < 0 || below < 0)
117 return { -1, -1 };
118 intersections_above += above;
119 intersections_below += below;
120 }
121 return { intersections_above, intersections_below };
122 }
123 }
std::tuple< int, int > coordinate_aligned_ray_hit_count(size_t node_idx, const TreeType &tree, const std::vector< LineType > &lines, const VectorType &ray_origin)
Definition AABBTreeLines.hpp:51

References coordinate_aligned_ray_hit_count().

Referenced by coordinate_aligned_ray_hit_count(), and Slic3r::AABBTreeLines::point_outside_closed_contours().

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

◆ get_intersections_with_line()

template<typename LineType, typename TreeType, typename VectorType>
std::vector< std::pair< VectorType, size_t > > Slic3r::AABBTreeLines::detail::get_intersections_with_line ( size_t node_idx,
const TreeType & tree,
const std::vector< LineType > & lines,
const LineType & line,
const typename TreeType::BoundingBox & line_bb )
inline
131 {
132 const auto& node = tree.node(node_idx);
133 assert(node.is_valid());
134 if (node.is_leaf()) {
135 VectorType intersection_pt;
136 if (line_alg::intersection(line, lines[node.idx], &intersection_pt)) {
137 return { std::pair<VectorType, size_t>(intersection_pt, node.idx) };
138 } else {
139 return {};
140 }
141 } else {
142 size_t left_node_idx = node_idx * 2 + 1;
143 size_t right_node_idx = left_node_idx + 1;
144 const auto& node_left = tree.node(left_node_idx);
145 const auto& node_right = tree.node(right_node_idx);
146 assert(node_left.is_valid());
147 assert(node_right.is_valid());
148
149 std::vector<std::pair<VectorType, size_t>> result;
150
151 if (node_left.bbox.intersects(line_bb)) {
152 std::vector<std::pair<VectorType, size_t>> intersections = get_intersections_with_line<LineType, TreeType, VectorType>(left_node_idx, tree, lines, line, line_bb);
153 result.insert(result.end(), intersections.begin(), intersections.end());
154 }
155
156 if (node_right.bbox.intersects(line_bb)) {
157 std::vector<std::pair<VectorType, size_t>> intersections = get_intersections_with_line<LineType, TreeType, VectorType>(right_node_idx, tree, lines, line, line_bb);
158 result.insert(result.end(), intersections.begin(), intersections.end());
159 }
160
161 return result;
162 }
163 }
std::vector< std::pair< VectorType, size_t > > get_intersections_with_line(size_t node_idx, const TreeType &tree, const std::vector< LineType > &lines, const LineType &line, const typename TreeType::BoundingBox &line_bb)
Definition AABBTreeLines.hpp:126
bool intersection(const L &l1, const L &l2, Vec< Dim< L >, Scalar< L > > *intersection_pt)
Definition Line.hpp:126

References get_intersections_with_line(), and Slic3r::line_alg::intersection().

Referenced by get_intersections_with_line(), and Slic3r::AABBTreeLines::get_intersections_with_line().

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