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-2018 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 /****************************************************************************/
17 // A RT-tree for efficient storing of SUMO's Named objects
18 /****************************************************************************/
19 #ifndef NamedRTree_h
20 #define NamedRTree_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <set>
29 #include <foreign/rtree/RTree.h>
30 #include <utils/common/Named.h>
31 
32 
33 // specialized implementation for speedup and avoiding warnings
34 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
35 
36 template<>
37 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
38  ASSERT(a_rect);
39  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
40  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
41  return .78539816f * (extent0 * extent0 + extent1 * extent1);
42 }
43 
44 template<>
45 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
46  ASSERT(a_rectA && a_rectB);
47  Rect newRect;
48  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
49  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
50  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
51  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
52  return newRect;
53 }
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
65 class NamedRTree : private NAMED_RTREE_QUAL {
66 public:
69  }
70 
71 
74  }
75 
76 
83  void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
84  NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
85  }
86 
87 
94  void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
95  NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
96  }
97 
98 
102  void RemoveAll() {
103  NAMED_RTREE_QUAL::RemoveAll();
104  }
105 
106 
116  int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
117  return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
118  }
119 
120 
121 };
122 
123 
124 #endif
125 
126 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:83
NamedRTree()
Constructor.
Definition: NamedRTree.h:68
#define NAMED_RTREE_QUAL
Definition: NamedRTree.h:34
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:65
void RemoveAll()
Remove all enrties.
Definition: NamedRTree.h:102
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:94
#define ASSERT
Definition: RTree.h:12
#define rtree_min(a, b)
Definition: RTree.h:20
#define rtree_max(a, b)
Definition: RTree.h:21
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:116
Base class for objects which have an id.
Definition: Named.h:58
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:94
~NamedRTree()
Destructor.
Definition: NamedRTree.h:73