SUMO - Simulation of Urban MObility
LayeredRTree.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 wrapper around RT-trees for for efficient storing of SUMO's GL-objects and
18 // accessing them ordered by their layer
19 // Note that we only need two layers at this time:
20 // 1 (GLO_LANE, GLO_VEHICLE, GLO_POI)
21 // 2 all the rest
22 // The search order returns layer 2 first because it must be drawn before layer
23 // 1 for alpha blending to work
24 /****************************************************************************/
25 #ifndef LayeredRTree_h
26 #define LayeredRTree_h
27 
28 
29 // ===========================================================================
30 // included modules
31 // ===========================================================================
32 #ifdef _MSC_VER
33 #include <windows_config.h>
34 #else
35 #include <config.h>
36 #endif
37 
41 #include <utils/geom/Boundary.h>
42 
43 #include "SUMORTree.h"
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
55 class LayeredRTree : public SUMORTree {
56 public:
59  myLayers.push_back(new SUMORTree());
60  myLayers.push_back(new SUMORTree());
61  }
62 
63 
66  for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
67  delete *it;
68  }
69  myLayers.clear();
70  }
71 
72 
78  void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
79  myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);
80  }
81 
82 
88  void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
89  myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);
90  }
91 
100  int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
101  int result = 0;
102  for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
103  result += (*it)->Search(a_min, a_max, c);
104  }
105  return result;
106  }
107 
108 
109 protected:
111  std::vector<SUMORTree*> myLayers;
112 
113 private:
114 
116  inline size_t selectLayer(GUIGlObject* o) {
117  switch (o->getType()) {
118  case GLO_EDGE:
119  case GLO_LANE:
120  case GLO_POI:
121  case GLO_VEHICLE:
122  case GLO_PERSON:
123  return 1;
124  break;
125  default:
126  return 0;
127  }
128  }
129 
130 };
131 
132 
133 #endif
134 
135 /****************************************************************************/
136 
LayeredRTree()
Constructor.
Definition: LayeredRTree.h:58
~LayeredRTree()
Destructor.
Definition: LayeredRTree.h:65
a vehicles
int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings &c) const
Find all within search rectangle (searches all layers in order)
Definition: LayeredRTree.h:100
Stores the information about how to visualize structures.
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:73
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
a person
size_t selectLayer(GUIGlObject *o)
select the appropriate layer for each object
Definition: LayeredRTree.h:116
void Remove(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Remove entry (delegate to appropriate layer)
Definition: LayeredRTree.h:88
std::vector< SUMORTree * > myLayers
the layers for drawing
Definition: LayeredRTree.h:111
void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry (delegate to appropriate layer)
Definition: LayeredRTree.h:78
an edge
A RT-tree for efficient storing of SUMO&#39;s GL-objects in layers.
Definition: LayeredRTree.h:55
SUMORTree()
Constructor.
Definition: SUMORTree.h:77