Eclipse SUMO - Simulation of Urban MObility
NamedRTree.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A RT-tree for efficient storing of SUMO's Named objects
17 /****************************************************************************/
18 #ifndef NamedRTree_h
19 #define NamedRTree_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 
26 #include <set>
27 #include <foreign/rtree/RTree.h>
28 #include <utils/common/Named.h>
29 
30 
31 // specialized implementation for speedup and avoiding warnings
32 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
33 
34 template<>
35 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
36  ASSERT(a_rect);
37  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
38  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
39  return .78539816f * (extent0 * extent0 + extent1 * extent1);
40 }
41 
42 template<>
43 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
44  ASSERT(a_rectA && a_rectB);
45  Rect newRect;
46  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
47  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
48  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
49  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
50  return newRect;
51 }
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
63 class NamedRTree : private NAMED_RTREE_QUAL {
64 public:
67  }
68 
69 
72  }
73 
74 
81  void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
82  NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
83  }
84 
85 
92  void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
93  NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
94  }
95 
96 
100  void RemoveAll() {
101  NAMED_RTREE_QUAL::RemoveAll();
102  }
103 
104 
114  int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
115  return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
116  }
117 
118 
119 };
120 
121 
122 #endif
123 
124 /****************************************************************************/
Named
Base class for objects which have an id.
Definition: Named.h:56
NamedRTree::Remove
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:92
Named::StoringVisitor
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:92
NAMED_RTREE_QUAL
#define NAMED_RTREE_QUAL
Definition: NamedRTree.h:32
rtree_min
#define rtree_min(a, b)
Definition: RTree.h:20
RTree.h
NamedRTree::Insert
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:81
Named.h
rtree_max
#define rtree_max(a, b)
Definition: RTree.h:21
ASSERT
#define ASSERT
Definition: RTree.h:12
NamedRTree::~NamedRTree
~NamedRTree()
Destructor.
Definition: NamedRTree.h:71
NamedRTree
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:63
NamedRTree::NamedRTree
NamedRTree()
Constructor.
Definition: NamedRTree.h:66
NamedRTree::RemoveAll
void RemoveAll()
Remove all enrties.
Definition: NamedRTree.h:100
NamedRTree::Search
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
Definition: NamedRTree.h:114