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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A RT-tree for efficient storing of SUMO's Named objects
20 /****************************************************************************/
21 #ifndef NamedRTree_h
22 #define NamedRTree_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <set>
35 #include <foreign/rtree/RTree.h>
36 #include <utils/common/Named.h>
37 
38 
39 // specialized implementation for speedup and avoiding warnings
40 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
41 
42 template<>
43 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
44  ASSERT(a_rect);
45  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
46  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
47  return .78539816f * (extent0 * extent0 + extent1 * extent1);
48 }
49 
50 template<>
51 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
52  ASSERT(a_rectA && a_rectB);
53  Rect newRect;
54  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
55  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
56  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
57  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
58  return newRect;
59 }
60 
61 // ===========================================================================
62 // class definitions
63 // ===========================================================================
71 class NamedRTree : private NAMED_RTREE_QUAL {
72 public:
75  }
76 
77 
80  }
81 
82 
89  void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
90  NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
91  }
92 
93 
100  void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
101  NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
102  }
103 
104 
108  void RemoveAll() {
109  NAMED_RTREE_QUAL::RemoveAll();
110  }
111 
112 
122  int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
123  return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
124  }
125 
126 
127 };
128 
129 
130 #endif
131 
132 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:89
NamedRTree()
Constructor.
Definition: NamedRTree.h:74
#define NAMED_RTREE_QUAL
Definition: NamedRTree.h:40
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:71
void RemoveAll()
Remove all enrties.
Definition: NamedRTree.h:108
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:100
#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:122
Base class for objects which have an id.
Definition: Named.h:54
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:90
~NamedRTree()
Destructor.
Definition: NamedRTree.h:79