[2113] | 1 | #include "IntersectionBoundingBoxConverter.h"
|
---|
| 2 | #include "KdTree.h"
|
---|
[2116] | 3 | #include "IntersectableWrapper.h"
|
---|
[2113] | 4 |
|
---|
| 5 |
|
---|
| 6 | namespace GtpVisibilityPreprocessor {
|
---|
| 7 |
|
---|
| 8 | void IntersectionBoundingBoxConverter::FindIntersectingObjects(const AxisAlignedBox3 &box,
|
---|
| 9 | ObjectContainer &objects) const
|
---|
| 10 | {
|
---|
| 11 | vector<KdLeaf *> leaves;
|
---|
| 12 |
|
---|
| 13 | // find intersecting scene nodes to get candidates for intersection
|
---|
| 14 | // note: this function has to be provided by scene manager
|
---|
| 15 | mKdTree->GetBoxIntersections(box, leaves);
|
---|
| 16 |
|
---|
| 17 | vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end();
|
---|
| 18 |
|
---|
| 19 | // loop through the intersected scene nodes
|
---|
| 20 | for (lit = leaves.begin(); lit != lit_end; ++ lit)
|
---|
| 21 | {
|
---|
| 22 | KdLeaf *leaf = *lit;
|
---|
| 23 |
|
---|
| 24 | ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
|
---|
| 25 |
|
---|
| 26 | // find the objects that intersect the box
|
---|
| 27 | for (oit = leaf->mObjects.begin(); oit != leaf->mObjects.end(); ++ oit)
|
---|
| 28 | {
|
---|
| 29 | Intersectable *obj = *oit;
|
---|
| 30 |
|
---|
| 31 | // test for intersection (note: function provided of preprocessor)
|
---|
| 32 | if (Overlap(box, obj->GetBox()))
|
---|
| 33 | {
|
---|
| 34 | objects.push_back(obj);
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | bool IntersectionBoundingBoxConverter::IdentifyObjects(
|
---|
[2544] | 42 | const IndexedBoundingBoxContainer &iboxes,
|
---|
| 43 | ObjectContainer &objects) const
|
---|
[2113] | 44 | {
|
---|
| 45 | GtpVisibilityPreprocessor::IndexedBoundingBoxContainer::
|
---|
| 46 | const_iterator iit, iit_end = iboxes.end();
|
---|
| 47 |
|
---|
| 48 | for (iit = iboxes.begin(); iit != iit_end; ++ iit)
|
---|
| 49 | {
|
---|
| 50 | const AxisAlignedBox3 box = (*iit).second;
|
---|
| 51 |
|
---|
| 52 | ObjectContainer *entryObjects = new ObjectContainer();
|
---|
| 53 |
|
---|
| 54 | // find all objects that intersect the bounding box
|
---|
| 55 | FindIntersectingObjects(box, *entryObjects);
|
---|
| 56 |
|
---|
| 57 | ContainerIntersectable *entry =
|
---|
| 58 | new ContainerIntersectable(entryObjects);
|
---|
| 59 |
|
---|
| 60 | entry->SetId((*iit).first);
|
---|
| 61 |
|
---|
| 62 | objects.push_back(entry);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | return true;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | }
|
---|