00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef BVHStaticBinary_hxx
00019 #define BVHStaticBinary_hxx
00020
00021 #include <simgear/math/SGGeometry.hxx>
00022 #include <simgear/structure/SGSharedPtr.hxx>
00023 #include "BVHStaticNode.hxx"
00024
00025 namespace simgear {
00026
00027 class BVHStaticBinary : public BVHStaticNode {
00028 public:
00029 BVHStaticBinary(unsigned splitAxis, const BVHStaticNode* leftChild,
00030 const BVHStaticNode* rightChild, const SGBoxf& box);
00031 virtual ~BVHStaticBinary();
00032 virtual void accept(BVHVisitor& visitor, const BVHStaticData& data) const;
00033
00034 void traverse(BVHVisitor& visitor, const BVHStaticData& data) const
00035 {
00036 _leftChild->accept(visitor, data);
00037 _rightChild->accept(visitor, data);
00038 }
00039
00040
00041
00042 template<typename T>
00043 void traverse(BVHVisitor& visitor, const BVHStaticData& data,
00044 const SGVec3<T>& pt) const
00045 {
00046 float center = 0.5f*(_boundingBox.getMin()[_splitAxis]
00047 + _boundingBox.getMax()[_splitAxis]);
00048 if (pt[_splitAxis] < center) {
00049 _leftChild->accept(visitor, data);
00050 _rightChild->accept(visitor, data);
00051 } else {
00052 _rightChild->accept(visitor, data);
00053 _leftChild->accept(visitor, data);
00054 }
00055 }
00056
00057 unsigned getSplitAxis() const
00058 { return _splitAxis; }
00059
00060 const BVHStaticNode* getLeftChild() const
00061 { return _leftChild; }
00062 const BVHStaticNode* getRightChild() const
00063 { return _rightChild; }
00064
00065 const SGBoxf& getBoundingBox() const
00066 { return _boundingBox; }
00067
00068 private:
00069
00070 unsigned _splitAxis;
00071 SGSharedPtr<const BVHStaticNode> _leftChild;
00072 SGSharedPtr<const BVHStaticNode> _rightChild;
00073 SGBoxf _boundingBox;
00074 };
00075
00076 }
00077
00078 #endif