SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SUMORTree.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // A RT-tree for efficient storing of SUMO's GL-objects
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef SUMORTree_h
21 #define SUMORTree_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
35 #include <utils/geom/Boundary.h>
37 
38 #include "RTree.h"
39 
40 
41 #define GUI_RTREE_QUAL RTree<GUIGlObject*, GUIGlObject, float, 2, GUIVisualizationSettings>
42 
43 // specialized implementation for speedup and avoiding warnings
44 
45 template<>
46 inline float GUI_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
47  ASSERT(a_rect);
48  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
49  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
50  return .78539816f * (extent0 * extent0 + extent1 * extent1);
51 }
52 
53 template<>
54 inline GUI_RTREE_QUAL::Rect GUI_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
55  ASSERT(a_rectA && a_rectB);
56  Rect newRect;
57  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
58  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
59  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
60  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
61  return newRect;
62 }
63 
64 
65 // ===========================================================================
66 // class definitions
67 // ===========================================================================
74 class SUMORTree : private GUI_RTREE_QUAL, public Boundary
75 {
76 public:
79  }
80 
81 
83  virtual ~SUMORTree() {
84  }
85 
86 
93  virtual void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
95  GUI_RTREE_QUAL::Insert(a_min, a_max, a_dataId);
96  }
97 
98 
105  virtual void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
107  GUI_RTREE_QUAL::Remove(a_min, a_max, a_dataId);
108  }
109 
110 
120  virtual int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
122  return GUI_RTREE_QUAL::Search(a_min, a_max, c);
123  }
124 
125 
132  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
133  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
134  Insert(cmin, cmax, o);
135  }
136 
137 
144  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
145  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
146  Remove(cmin, cmax, o);
147  }
148 
149 
150 protected:
152  mutable MFXMutex myLock;
153 
154 };
155 
156 
157 #endif
158 
159 /****************************************************************************/
160 
MFXMutex myLock
A mutex avoiding parallel change and traversal of the tree.
Definition: SUMORTree.h:152
SUMOReal ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:124
Stores the information about how to visualize structures.
SUMOReal xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:112
void removeAdditionalGLObject(GUIGlObject *o)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:141
virtual void Remove(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Remove entry.
Definition: SUMORTree.h:105
virtual Boundary getCenteringBoundary() const =0
Returns the boundary to which the view shall be centered in order to show the object.
A RT-tree for efficient storing of SUMO's GL-objects.
Definition: SUMORTree.h:74
SUMOReal xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:118
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
#define ASSERT
Definition: RTree.h:12
#define rtree_min(a, b)
Definition: RTree.h:20
#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:129
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
SUMORTree()
Constructor.
Definition: SUMORTree.h:78
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:120
SUMOReal ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:130
virtual void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry.
Definition: SUMORTree.h:93
virtual ~SUMORTree()
Destructor.
Definition: SUMORTree.h:83