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 /****************************************************************************/
15 // A wrapper around RT-trees for for efficient storing of SUMO's GL-objects and
16 // accessing them ordered by their layer
17 // Note that we only need two layers at this time:
18 // 1 (GLO_LANE, GLO_VEHICLE, GLO_POI)
19 // 2 all the rest
20 // The search order returns layer 2 first because it must be drawn before layer
21 // 1 for alpha blending to work
22 /****************************************************************************/
23 #ifndef LayeredRTree_h
24 #define LayeredRTree_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #include <config.h>
31 
35 #include <utils/geom/Boundary.h>
36 
37 #include "SUMORTree.h"
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
49 class LayeredRTree : public SUMORTree {
50 public:
53  myLayers.push_back(new SUMORTree());
54  myLayers.push_back(new SUMORTree());
55  }
56 
57 
60  for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
61  delete *it;
62  }
63  myLayers.clear();
64  }
65 
66 
72  void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
73  myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);
74  }
75 
76 
82  void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
83  myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);
84  }
85 
94  int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
95  int result = 0;
96  for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
97  result += (*it)->Search(a_min, a_max, c);
98  }
99  return result;
100  }
101 
102 
103 protected:
105  std::vector<SUMORTree*> myLayers;
106 
107 private:
108 
110  inline size_t selectLayer(GUIGlObject* o) {
111  switch (o->getType()) {
112  case GLO_EDGE:
113  case GLO_LANE:
114  case GLO_POI:
115  case GLO_VEHICLE:
116  case GLO_PERSON:
117  return 1;
118  break;
119  default:
120  return 0;
121  }
122  }
123 
124 };
125 
126 
127 #endif
128 
129 /****************************************************************************/
130 
LayeredRTree()
Constructor.
Definition: LayeredRTree.h:52
~LayeredRTree()
Destructor.
Definition: LayeredRTree.h:59
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:94
Stores the information about how to visualize structures.
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:69
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
size_t selectLayer(GUIGlObject *o)
select the appropriate layer for each object
Definition: LayeredRTree.h:110
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:82
std::vector< SUMORTree * > myLayers
the layers for drawing
Definition: LayeredRTree.h:105
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:72
an edge
A RT-tree for efficient storing of SUMO&#39;s GL-objects in layers.
Definition: LayeredRTree.h:49
SUMORTree()
Constructor.
Definition: SUMORTree.h:72