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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A RT-tree for efficient storing of SUMO's Named objects
21 /****************************************************************************/
22 #pragma once
23 #include <set>
24 #include <foreign/rtree/RTree.h>
25 #include <utils/common/Named.h>
26 
27 
28 // specialized implementation for speedup and avoiding warnings
29 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
30 
31 template<>
32 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
33  ASSERT(a_rect);
34  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
35  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
36  return .78539816f * (extent0 * extent0 + extent1 * extent1);
37 }
38 
39 template<>
40 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
41  ASSERT(a_rectA && a_rectB);
42  Rect newRect;
43  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
44  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
45  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
46  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
47  return newRect;
48 }
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
60 class NamedRTree : private NAMED_RTREE_QUAL {
61 public:
64  }
65 
66 
69  }
70 
71 
78  void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
79  NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
80  }
81 
82 
89  void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
90  NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
91  }
92 
93 
97  void RemoveAll() {
98  NAMED_RTREE_QUAL::RemoveAll();
99  }
100 
101 
111  int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
112  return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
113  }
114 
115 
116 };
#define NAMED_RTREE_QUAL
Definition: NamedRTree.h:29
#define rtree_min(a, b)
Definition: RTree.h:20
#define rtree_max(a, b)
Definition: RTree.h:21
#define ASSERT
Definition: RTree.h:12
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:89
Base class for objects which have an id.
Definition: Named.h:53
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:60
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:89
NamedRTree()
Constructor.
Definition: NamedRTree.h:63
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:78
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:111
void RemoveAll()
Remove all enrties.
Definition: NamedRTree.h:97
~NamedRTree()
Destructor.
Definition: NamedRTree.h:68