SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LayeredRTree.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // A wrapper around RT-trees for for efficient storing of SUMO's GL-objects and
8 // accessing them ordered by their layer
9 // Note that we only need two layers at this time:
10 // 1 (GLO_LANE, GLO_VEHICLE, GLO_POI)
11 // 2 all the rest
12 // The search order returns layer 2 first because it must be drawn before layer
13 // 1 for alpha blending to work
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 #ifndef LayeredRTree_h
27 #define LayeredRTree_h
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
42 #include <utils/geom/Boundary.h>
43 
44 #include "SUMORTree.h"
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
56 class LayeredRTree : public SUMORTree {
57 public:
60  myLayers.push_back(new SUMORTree());
61  myLayers.push_back(new SUMORTree());
62  }
63 
64 
67  for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
68  delete *it;
69  }
70  myLayers.clear();
71  }
72 
73 
79  void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
80  myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);
81  }
82 
83 
89  void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
90  myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);
91  }
92 
101  int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
102  int result = 0;
103  for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
104  result += (*it)->Search(a_min, a_max, c);
105  }
106  return result;
107  }
108 
109 
110 protected:
112  std::vector<SUMORTree*> myLayers;
113 
114 private:
115 
117  inline size_t selectLayer(GUIGlObject* o) {
118  switch (o->getType()) {
119  case GLO_EDGE:
120  case GLO_LANE:
121  case GLO_POI:
122  case GLO_VEHICLE:
123  case GLO_PERSON:
124  return 1;
125  break;
126  default:
127  return 0;
128  }
129  }
130 
131 };
132 
133 
134 #endif
135 
136 /****************************************************************************/
137 
LayeredRTree()
Constructor.
Definition: LayeredRTree.h:59
~LayeredRTree()
Destructor.
Definition: LayeredRTree.h:66
a vehicles
Stores the information about how to visualize structures.
A RT-tree for efficient storing of SUMO's GL-objects.
Definition: SUMORTree.h:74
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
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:101
a person
size_t selectLayer(GUIGlObject *o)
select the appropriate layer for each object
Definition: LayeredRTree.h:117
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:89
std::vector< SUMORTree * > myLayers
the layers for drawing
Definition: LayeredRTree.h:112
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:79
an edge
A RT-tree for efficient storing of SUMO's GL-objects in layers.
Definition: LayeredRTree.h:56
SUMORTree()
Constructor.
Definition: SUMORTree.h:78