Impl AABB search
This commit is contained in:
parent
3ac15a7649
commit
999b6f1577
1 changed files with 33 additions and 2 deletions
|
@ -400,10 +400,41 @@ class AABBTree
|
||||||
// if split node: check BB of childs
|
// if split node: check BB of childs
|
||||||
// -> node = child with shorter distance
|
// -> node = child with shorter distance
|
||||||
// if leaf node: iterate through primitives
|
// if leaf node: iterate through primitives
|
||||||
|
|
||||||
|
AABBSplitNode* split_node = dynamic_cast<AABBSplitNode*>(node);
|
||||||
|
AABBLeafNode* leaf_node = dynamic_cast<AABBLeafNode*>(node);
|
||||||
|
|
||||||
|
if (split_node != nullptr) {
|
||||||
|
AABBNode* left_child = split_node->Left();
|
||||||
|
AABBNode* right_child = split_node->Right();
|
||||||
|
|
||||||
|
float left_distance = left_child->GetBounds().SqrDistance(q);
|
||||||
|
float right_distance = right_child->GetBounds().SqrDistance(q);
|
||||||
|
|
||||||
|
if (left_distance < right_distance) {
|
||||||
|
node = left_child;
|
||||||
|
} else {
|
||||||
|
node = right_child;
|
||||||
|
}
|
||||||
|
} else if (leaf_node != nullptr) {
|
||||||
|
ResultEntry best;
|
||||||
|
|
||||||
|
for (auto pit = leaf_node->begin(); pit != leaf_node->end(); ++pit)
|
||||||
|
{
|
||||||
|
float dist = pit->SqrDistance(q);
|
||||||
|
if (dist < best.sqrDistance)
|
||||||
|
{
|
||||||
|
best.sqrDistance = dist;
|
||||||
|
best.prim = &(*pit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
} else {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Task 3.2.1 */
|
//return ClosestPrimitiveLinearSearch(q);
|
||||||
return ClosestPrimitiveLinearSearch(q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//return the closest point position on the closest primitive in the tree with respect to the query point q
|
//return the closest point position on the closest primitive in the tree with respect to the query point q
|
||||||
|
|
Loading…
Reference in a new issue