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