source: GTP/trunk/Lib/Vis/Preprocessing/src/IntersectionBoundingBoxConverter.cpp @ 2113

Revision 2113, 1.7 KB checked in by mattausch, 17 years ago (diff)

warning: debug version

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