SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NamedRTree.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A RT-tree for efficient storing of SUMO's Named objects
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2008-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NamedRTree_h
23 #define NamedRTree_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <set>
36 #include <foreign/rtree/RTree.h>
37 #include <utils/common/Named.h>
38 
39 
40 // specialized implementation for speedup and avoiding warnings
41 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
42 
43 template<>
44 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
45  ASSERT(a_rect);
46  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
47  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
48  return .78539816f * (extent0 * extent0 + extent1 * extent1);
49 }
50 
51 template<>
52 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
53  ASSERT(a_rectA && a_rectB);
54  Rect newRect;
55  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
56  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
57  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
58  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
59  return newRect;
60 }
61 
62 // ===========================================================================
63 // class definitions
64 // ===========================================================================
72 class NamedRTree : private NAMED_RTREE_QUAL {
73 public:
76  }
77 
78 
81  }
82 
83 
90  void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
91  NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
92  }
93 
94 
101  void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
102  NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
103  }
104 
105 
109  void RemoveAll() {
110  NAMED_RTREE_QUAL::RemoveAll();
111  }
112 
113 
123  int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
124  return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
125  }
126 
127 
128 };
129 
130 
131 #endif
132 
133 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:90
NamedRTree()
Constructor.
Definition: NamedRTree.h:75
A RT-tree for efficient storing of SUMO's Named objects.
Definition: NamedRTree.h:72
void RemoveAll()
Remove all enrties.
Definition: NamedRTree.h:109
void Remove(const float a_min[2], const float a_max[2], Named *const &a_data)
Remove entry.
Definition: NamedRTree.h:101
#define ASSERT
Definition: RTree.h:12
#define rtree_min(a, b)
Definition: RTree.h:20
#define rtree_max(a, b)
Definition: RTree.h:21
Base class for objects which have an id.
Definition: Named.h:45
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:92
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:123
~NamedRTree()
Destructor.
Definition: NamedRTree.h:80