SUMO - Simulation of Urban MObility
SUMORTree.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
17 // A RT-tree for efficient storing of SUMO's GL-objects
18 /****************************************************************************/
19 #ifndef SUMORTree_h
20 #define SUMORTree_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
34 #include <utils/geom/Boundary.h>
36 
37 #include "RTree.h"
38 
39 
40 #define GUI_RTREE_QUAL RTree<GUIGlObject*, GUIGlObject, float, 2, GUIVisualizationSettings>
41 
42 // specialized implementation for speedup and avoiding warnings
43 
44 template<>
45 inline float GUI_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
46  ASSERT(a_rect);
47  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
48  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
49  return .78539816f * (extent0 * extent0 + extent1 * extent1);
50 }
51 
52 template<>
53 inline GUI_RTREE_QUAL::Rect GUI_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
54  ASSERT(a_rectA && a_rectB);
55  Rect newRect;
56  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
57  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
58  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
59  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
60  return newRect;
61 }
62 
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
73 class SUMORTree : private GUI_RTREE_QUAL, public Boundary
74 {
75 public:
78  }
79 
80 
82  virtual ~SUMORTree() {
83  }
84 
85 
92  virtual void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
94  GUI_RTREE_QUAL::Insert(a_min, a_max, a_dataId);
95  }
96 
97 
104  virtual void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
106  GUI_RTREE_QUAL::Remove(a_min, a_max, a_dataId);
107  }
108 
109 
119  virtual int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
121  return GUI_RTREE_QUAL::Search(a_min, a_max, c);
122  }
123 
124 
131  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
132  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
133  Insert(cmin, cmax, o);
134  }
135 
136 
143  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
144  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
145  Remove(cmin, cmax, o);
146  }
147 
148 
149 protected:
151  mutable MFXMutex myLock;
152 
153 };
154 
155 
156 #endif
157 
158 /****************************************************************************/
159 
MFXMutex myLock
A mutex avoiding parallel change and traversal of the tree.
Definition: SUMORTree.h:151
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:137
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:131
Stores the information about how to visualize structures.
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:140
virtual void Remove(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Remove entry.
Definition: SUMORTree.h:104
virtual Boundary getCenteringBoundary() const =0
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:73
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
#define ASSERT
Definition: RTree.h:12
#define rtree_min(a, b)
Definition: RTree.h:20
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:125
#define rtree_max(a, b)
Definition: RTree.h:21
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:128
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:70
SUMORTree()
Constructor.
Definition: SUMORTree.h:77
#define GUI_RTREE_QUAL
Definition: SUMORTree.h:40
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:143
virtual void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry.
Definition: SUMORTree.h:92
virtual int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings &c) const
Find all within search rectangle.
Definition: SUMORTree.h:119
virtual ~SUMORTree()
Destructor.
Definition: SUMORTree.h:82