1 // Copyright (C) 2008 - 2009 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef BVHSubTreeCollector_hxx
19 #define BVHSubTreeCollector_hxx
21 #include <simgear/math/SGGeometry.hxx>
23 #include "BVHVisitor.hxx"
24 #include "BVHNode.hxx"
25 #include "BVHGroup.hxx"
26 #include "BVHStaticNode.hxx"
30 /// Visitor to subcollect parts of an existing bounding volume tree.
31 /// Given a sphere, it takes those sub parts of the tree that intersect the
32 /// sphere. Transform nodes of any kind are preserved to be able to ask for
33 /// intersections a different times. The subcollected tree is kept as small as
34 /// possible as it does avoid having groups with single childs.
35 /// Also the BVHStaticGeometry parts are seached for subtrees that are outside
38 class BVHSubTreeCollector : public BVHVisitor {
40 typedef std::vector<SGSharedPtr<BVHNode> > NodeList;
42 BVHSubTreeCollector(const SGSphered& sphere = SGSphered());
43 virtual ~BVHSubTreeCollector();
45 virtual void apply(BVHGroup&);
46 virtual void apply(BVHPageNode&);
47 virtual void apply(BVHTransform&);
48 virtual void apply(BVHMotionTransform&);
49 virtual void apply(BVHLineGeometry&);
50 virtual void apply(BVHStaticGeometry&);
52 virtual void apply(const BVHStaticBinary&, const BVHStaticData&);
53 virtual void apply(const BVHStaticTriangle&, const BVHStaticData&);
55 void setSphere(const SGSphered& sphere)
57 const SGSphered& getSphere() const
60 bool haveChildren() const
61 { return !_nodeList.empty(); }
63 void addNode(BVHNode* node);
65 void pushNodeList(NodeList& parentNodeList)
66 { _nodeList.swap(parentNodeList); }
67 void popNodeList(NodeList& parentNodeList, BVHGroup* transform);
68 void popNodeList(NodeList& parentNodeList);
70 SGSharedPtr<BVHNode> getNode() const;
74 SGSharedPtr<const BVHStaticNode> _staticNode;