Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // A wrapper around RT-trees for for efficient storing of SUMO's GL-objects and
15 // accessing them ordered by their layer
16 // Note that we only need two layers at this time:
17 // 1 (GLO_LANE, GLO_VEHICLE, GLO_POI)
18 // 2 all the rest
19 // The search order returns layer 2 first because it must be drawn before layer
20 // 1 for alpha blending to work
21 /****************************************************************************/
22 #ifndef LayeredRTree_h
23 #define LayeredRTree_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #include <config.h>
30 
34 #include <utils/geom/Boundary.h>
35 
36 #include "SUMORTree.h"
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
48 class LayeredRTree : public SUMORTree {
49 public:
52  myLayers.push_back(new SUMORTree());
53  myLayers.push_back(new SUMORTree());
54  }
55 
56 
59  for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
60  delete *it;
61  }
62  myLayers.clear();
63  }
64 
65 
71  void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
72  myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);
73  }
74 
75 
81  void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
82  myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);
83  }
84 
93  int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
94  int result = 0;
95  for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
96  result += (*it)->Search(a_min, a_max, c);
97  }
98  return result;
99  }
100 
101 
102 protected:
104  std::vector<SUMORTree*> myLayers;
105 
106 private:
107 
109  inline size_t selectLayer(GUIGlObject* o) {
110  switch (o->getType()) {
111  case GLO_EDGE:
112  case GLO_LANE:
113  case GLO_POI:
114  case GLO_VEHICLE:
115  case GLO_PERSON:
116  return 1;
117  break;
118  default:
119  return 0;
120  }
121  }
122 
123 };
124 
125 
126 #endif
127 
128 /****************************************************************************/
129 
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:180
Boundary.h
GUIGlObject.h
GUIGlObjectTypes.h
LayeredRTree::~LayeredRTree
~LayeredRTree()
Destructor.
Definition: LayeredRTree.h:58
LayeredRTree::myLayers
std::vector< SUMORTree * > myLayers
the layers for drawing
Definition: LayeredRTree.h:104
GLO_PERSON
@ GLO_PERSON
Definition: GUIGlObjectTypes.h:159
GUIVisualizationSettings.h
GLO_VEHICLE
@ GLO_VEHICLE
Definition: GUIGlObjectTypes.h:141
SUMORTree::SUMORTree
SUMORTree()
Constructor.
Definition: SUMORTree.h:71
SUMORTree
A RT-tree for efficient storing of SUMO's GL-objects.
Definition: SUMORTree.h:68
LayeredRTree::LayeredRTree
LayeredRTree()
Constructor.
Definition: LayeredRTree.h:51
LayeredRTree::selectLayer
size_t selectLayer(GUIGlObject *o)
select the appropriate layer for each object
Definition: LayeredRTree.h:109
SUMORTree.h
GLO_EDGE
@ GLO_EDGE
an edge
Definition: GUIGlObjectTypes.h:46
GLO_POI
@ GLO_POI
a poi
Definition: GUIGlObjectTypes.h:106
GLO_LANE
@ GLO_LANE
a lane
Definition: GUIGlObjectTypes.h:48
LayeredRTree::Remove
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:81
GUIGlObject
Definition: GUIGlObject.h:65
LayeredRTree::Insert
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:71
LayeredRTree::Search
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:93
config.h
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
LayeredRTree
A RT-tree for efficient storing of SUMO's GL-objects in layers.
Definition: LayeredRTree.h:48