opensurgsim
AabbTree.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DATASTRUCTURES_AABBTREE_H
17 #define SURGSIM_DATASTRUCTURES_AABBTREE_H
18 
19 #include <list>
20 #include <vector>
21 
22 #include "SurgSim/DataStructures/Tree.h"
23 #include "SurgSim/DataStructures/AabbTreeData.h"
24 #include "SurgSim/Math/Aabb.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace DataStructures
30 {
31 
32 class AabbTreeNode;
33 
37 class AabbTree : public Tree
38 {
39 public:
40 
42  AabbTree();
43 
46  explicit AabbTree(size_t maxObjectsPerNode);
47 
49  virtual ~AabbTree();
50 
52  size_t getMaxObjectsPerNode() const;
53 
58  void add(const SurgSim::Math::Aabbd& aabb, size_t objectId);
59 
62  void set(const AabbTreeData::ItemList& items);
63 
66  void set(AabbTreeData::ItemList&& items);
67 
69  const SurgSim::Math::Aabbd& getAabb() const;
70 
72  typedef std::pair<AabbTreeNode*, AabbTreeNode*> TreeNodePairType;
73 
77  std::vector<TreeNodePairType> spatialJoin(const AabbTree& otherTree) const;
78 
83  void spatialJoin(AabbTreeNode* lhsParent, AabbTreeNode* rhsParent,
84  std::vector<TreeNodePairType>* result) const;
85 
86  void updateBounds(const std::vector<Math::Aabbd>& bounds);
87 
88  void updateNodeBounds(const std::vector<Math::Aabbd>& bounds, SurgSim::DataStructures::AabbTreeNode* node);
89 
90 private:
91 
93  size_t m_maxObjectsPerNode;
94 
96  std::shared_ptr<AabbTreeNode> m_typedRoot;
97 };
98 
99 }
100 }
101 
102 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Basic tree structure.
Definition: Tree.h:32
std::pair< AabbTreeNode *, AabbTreeNode * > TreeNodePairType
Type indicating a relationship between two AabbTreeNodes.
Definition: AabbTree.h:72
AabbTree is a tree that is organized by the bounding boxes of the referenced objects, the bounding box used is the Axis Aligned Bounding Box (AABB), with the extents of an AABB describing the min and max of each coordinate for the given object.
Definition: AabbTree.h:37
const SurgSim::Math::Aabbd & getAabb() const
Definition: AabbTree.cpp:69
virtual ~AabbTree()
Destructor.
Definition: AabbTree.cpp:40
size_t getMaxObjectsPerNode() const
Definition: AabbTree.cpp:64
std::vector< TreeNodePairType > spatialJoin(const AabbTree &otherTree) const
Query to find all pairs of intersecting nodes between two aabb r-trees.
Definition: AabbTree.cpp:74
void add(const SurgSim::Math::Aabbd &aabb, size_t objectId)
Add a give object identified by objectId to the tree, this id should be unqiue on the users side...
Definition: AabbTree.cpp:45
AabbTree()
Constructor.
Definition: AabbTree.cpp:26
Node class for the AabbTree, this handles groups of items and subdivision if the number of items gets...
Definition: AabbTreeNode.h:30