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.dev/sumo
3 // Copyright (C) 2008-2024 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 <config.h>
24 #include <set>
25 #include <foreign/rtree/RTree.h>
26 #include <utils/common/Named.h>
27 
28 
29 // specialized implementation for speedup and avoiding warnings
30 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
31 
32 template<>
33 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
34  ASSERT(a_rect);
35  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
36  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
37  return .78539816f * (extent0 * extent0 + extent1 * extent1);
38 }
39 
40 template<>
41 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
42  ASSERT(a_rectA && a_rectB);
43  Rect newRect;
44  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
45  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
46  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
47  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
48  return newRect;
49 }
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
61 class NamedRTree : private NAMED_RTREE_QUAL {
62 public:
65  }
66 
67 
70  }
71 
72 
79  void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
80  NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
81  }
82 
83 
90  void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
91  NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
92  }
93 
94 
98  void RemoveAll() {
99  NAMED_RTREE_QUAL::RemoveAll();
100  }
101 
102 
112  int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
113  return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
114  }
115 
116 
117 };
#define NAMED_RTREE_QUAL
Definition: NamedRTree.h:30
#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:90
Base class for objects which have an id.
Definition: Named.h:54
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:61
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:90
NamedRTree()
Constructor.
Definition: NamedRTree.h:64
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:79
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:112
void RemoveAll()
Remove all enrties.
Definition: NamedRTree.h:98
~NamedRTree()
Destructor.
Definition: NamedRTree.h:69