AabbTreeData.h
Go to the documentation of this file.
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_AABBTREEDATA_H
17 #define SURGSIM_DATASTRUCTURES_AABBTREEDATA_H
18 
20 
21 #include "SurgSim/Math/Aabb.h"
22 
23 #include <utility>
24 #include <list>
25 #include <memory>
26 
27 namespace SurgSim
28 {
29 namespace DataStructures
30 {
31 
34 class AabbTreeData : public TreeData
35 {
36 public:
37 
38  typedef std::pair<SurgSim::Math::Aabbd, size_t> Item;
39 
41  AabbTreeData();
42 
44  AabbTreeData(const AabbTreeData& data);
45 
47  explicit AabbTreeData(const std::list<Item>& data);
48 
50  explicit AabbTreeData(std::list<Item>&& data);
51 
53  ~AabbTreeData();
54 
55 
59  void add(const SurgSim::Math::Aabbd aabb, size_t id);
60 
62  const SurgSim::Math::Aabbd& getAabb() const;
63 
65  bool isEmpty() const;
66 
68  size_t getSize() const;
69 
75  std::shared_ptr<AabbTreeData> takeLargerElements();
76 
80  bool hasIntersections(const SurgSim::Math::Aabbd& aabb) const;
81 
86  void getIntersections(const SurgSim::Math::Aabbd& aabb, std::list<size_t>* result) const;
87 
88 private:
90  void recalculateAabb();
91 
92  bool isEqual(const TreeData* data) const override;
93 
96 
98  std::list<Item> m_data;
99 };
100 
101 }
102 }
103 
104 #endif
SurgSim::DataStructures::AabbTreeData::hasIntersections
bool hasIntersections(const SurgSim::Math::Aabbd &aabb) const
Check whether there could be any intersections with a given bounding box.
Definition: AabbTreeData.cpp:144
SurgSim::DataStructures::AabbTreeData::m_aabb
SurgSim::Math::Aabbd m_aabb
AABB containg all items.
Definition: AabbTreeData.h:95
SurgSim::DataStructures::AabbTreeData::isEqual
bool isEqual(const TreeData *data) const override
Returns true if the trees are equal; otherwise, returns false.
Definition: AabbTreeData.cpp:46
SurgSim::DataStructures::AabbTreeData::getSize
size_t getSize() const
Definition: AabbTreeData.cpp:91
SurgSim::DataStructures::AabbTreeData::~AabbTreeData
~AabbTreeData()
Destructor.
Definition: AabbTreeData.cpp:41
SurgSim::DataStructures::AabbTreeData::m_data
std::list< Item > m_data
The items that were added to this list.
Definition: AabbTreeData.h:98
TreeData.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::TreeData
Abstract base class for data stored in a Tree.
Definition: TreeData.h:29
SurgSim::DataStructures::AabbTreeData::getAabb
const SurgSim::Math::Aabbd & getAabb() const
Definition: AabbTreeData.cpp:80
SurgSim::Math::Aabbd
Eigen::AlignedBox< double, 3 > Aabbd
Wrapper around the Eigen type.
Definition: Aabb.h:30
SurgSim::DataStructures::AabbTreeData::isEmpty
bool isEmpty() const
Definition: AabbTreeData.cpp:86
SurgSim::DataStructures::AabbTreeData::getIntersections
void getIntersections(const SurgSim::Math::Aabbd &aabb, std::list< size_t > *result) const
Check all items bounding boxes against the one passed as a parameter and append items that overlap to...
Definition: AabbTreeData.cpp:133
SurgSim::DataStructures::AabbTreeData::takeLargerElements
std::shared_ptr< AabbTreeData > takeLargerElements()
Split the current items into two geometric halves, keep the first half and return a pointer to the se...
Definition: AabbTreeData.cpp:96
Aabb.h
SurgSim::DataStructures::AabbTreeData::add
void add(const SurgSim::Math::Aabbd aabb, size_t id)
Add an item to the data.
Definition: AabbTreeData.cpp:74
SurgSim::DataStructures::AabbTreeData::AabbTreeData
AabbTreeData()
Constructor.
Definition: AabbTreeData.cpp:26
SurgSim::DataStructures::AabbTreeData
Internal class to hold a list of AABBs and their respective object ids, it can calculate the elements...
Definition: AabbTreeData.h:34
SurgSim::DataStructures::AabbTreeData::recalculateAabb
void recalculateAabb()
Recalculate the aabb of this class, in case items where updated.
Definition: AabbTreeData.cpp:124
SurgSim::DataStructures::AabbTreeData::Item
std::pair< SurgSim::Math::Aabbd, size_t > Item
Definition: AabbTreeData.h:38