Bugfix: custom seam identification
Bounding boxes of polygons could overlap. Ask the AABB tree for all possible candidates. Might be faster than searching for the closest triangle, that requires traversing the whole depth of the tree every time.
This commit is contained in:
parent
985a4a8bf3
commit
997ee971b4
@ -730,29 +730,26 @@ inline bool is_any_triangle_in_radius(
|
||||
// Traverse the tree and return the index of an entity whose bounding box
|
||||
// contains a given point. Returns size_t(-1) when the point is outside.
|
||||
template<typename TreeType, typename VectorType>
|
||||
size_t get_candidate_idx(const TreeType& tree, const VectorType& v)
|
||||
void get_candidate_idxs(const TreeType& tree, const VectorType& v, std::vector<size_t>& candidates, size_t node_idx = 0)
|
||||
{
|
||||
if (tree.empty() || ! tree.node(0).bbox.contains(v))
|
||||
return size_t(-1);
|
||||
if (tree.empty() || ! tree.node(node_idx).bbox.contains(v))
|
||||
return;
|
||||
|
||||
size_t node_idx = 0;
|
||||
while (true) {
|
||||
decltype(tree.node(node_idx)) node = tree.node(node_idx);
|
||||
static_assert(std::is_reference<decltype(node)>::value,
|
||||
"Nodes shall be addressed by reference.");
|
||||
assert(node.is_valid());
|
||||
assert(node.bbox.contains(v));
|
||||
decltype(tree.node(node_idx)) node = tree.node(node_idx);
|
||||
static_assert(std::is_reference<decltype(node)>::value,
|
||||
"Nodes shall be addressed by reference.");
|
||||
assert(node.is_valid());
|
||||
assert(node.bbox.contains(v));
|
||||
|
||||
if (! node.is_leaf()) {
|
||||
if (tree.left_child(node_idx).bbox.contains(v))
|
||||
node_idx = tree.left_child_idx(node_idx);
|
||||
else if (tree.right_child(node_idx).bbox.contains(v))
|
||||
node_idx = tree.right_child_idx(node_idx);
|
||||
else
|
||||
return size_t(-1);
|
||||
} else
|
||||
return node.idx;
|
||||
}
|
||||
if (! node.is_leaf()) {
|
||||
if (tree.left_child(node_idx).bbox.contains(v))
|
||||
get_candidate_idxs(tree, v, candidates, tree.left_child_idx(node_idx));
|
||||
if (tree.right_child(node_idx).bbox.contains(v))
|
||||
get_candidate_idxs(tree, v, candidates, tree.right_child_idx(node_idx));
|
||||
} else
|
||||
candidates.push_back(node.idx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -569,11 +569,13 @@ void SeamPlacer::get_enforcers_and_blockers(size_t layer_id,
|
||||
auto is_inside = [](const Point& pt,
|
||||
const CustomTrianglesPerLayer& custom_data) -> bool {
|
||||
assert(! custom_data.polys.empty());
|
||||
// Now ask the AABB tree which polygon we should check and check it.
|
||||
size_t candidate = AABBTreeIndirect::get_candidate_idx(custom_data.tree, pt);
|
||||
if (candidate != size_t(-1)
|
||||
&& custom_data.polys[candidate].contains(pt))
|
||||
return true;
|
||||
// Now ask the AABB tree which polygons we should check and check them.
|
||||
std::vector<size_t> candidates;
|
||||
AABBTreeIndirect::get_candidate_idxs(custom_data.tree, pt, candidates);
|
||||
if (! candidates.empty())
|
||||
for (size_t idx : candidates)
|
||||
if (custom_data.polys[idx].contains(pt))
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user