alecjacobson/computer-graphics-bounding-volume-hierarchy

How to check if a subtree is a leaf?

coolKev666 opened this issue · 1 comments

Under section "Distance queries":

  1. In the BFS pseudocode, it specifically asks us to check "if subtree is a leaf" after checking if d_s<d.
    I was thinking of checking the object type by de-referencing the object smart pointer, but that does not seem feasible.
    Are there other ways to do this? If yes, how?

  2. When inserting a distance-subtree pair into the priority queue: Q.insert(d_l, subtree.left)
    If we initialize the priority queue to handle (double, shared_ptr<AABBTree>), but if subtree.left is type (shared_ptr<Object >) - how do we resolve this?

  1. You can use std::dynamic_pointer_cast<B> to convert a shared_ptr<A> to shared_ptr<B>. The call to cast returns false if the cast was not possible. https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast

  2. If you don't want to put Objects into your queue, you can just handle generic objects before they would be inserted into the queue. You'd need to calculate the point distance anyways if you're putting them in the queue.