Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
LayeredRTree.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// A wrapper around RT-trees for for efficient storing of SUMO's GL-objects and
19// accessing them ordered by their layer
20// Note that we only need two layers at this time:
21// 1 (GLO_LANE, GLO_VEHICLE, GLO_POI)
22// 2 all the rest
23// The search order returns layer 2 first because it must be drawn before layer
24// 1 for alpha blending to work
25/****************************************************************************/
26#pragma once
27#include <config.h>
28
32#include <utils/geom/Boundary.h>
33
34#include "SUMORTree.h"
35
36
37// ===========================================================================
38// class definitions
39// ===========================================================================
46class LayeredRTree : public SUMORTree {
47public:
50 myLayers.push_back(new SUMORTree());
51 myLayers.push_back(new SUMORTree());
52 }
53
54
57 for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
58 delete *it;
59 }
60 myLayers.clear();
61 }
62
63
69 void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
70 myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);
71 }
72
73
79 void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
80 myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);
81 }
82
91 int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
92 int result = 0;
93 for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
94 result += (*it)->Search(a_min, a_max, c);
95 }
96 return result;
97 }
98
99
100protected:
102 std::vector<SUMORTree*> myLayers;
103
104private:
105
107 inline size_t selectLayer(GUIGlObject* o) {
108 switch (o->getType()) {
109 case GLO_EDGE:
110 case GLO_LANE:
111 case GLO_POI:
112 case GLO_VEHICLE:
113 case GLO_PERSON:
114 return 1;
115 break;
116 default:
117 return 0;
118 }
119 }
120
121};
@ GLO_LANE
a lane
@ GLO_EDGE
an edge
@ GLO_VEHICLE
a vehicle
@ GLO_PERSON
a person
@ GLO_POI
poi (over view, geo and lane)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
void Insert(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Insert entry (delegate to appropriate layer).
LayeredRTree()
Constructor.
std::vector< SUMORTree * > myLayers
the layers for drawing
~LayeredRTree()
Destructor.
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).
void Remove(const float a_min[2], const float a_max[2], GUIGlObject *const &a_dataId)
Remove entry (delegate to appropriate layer).
size_t selectLayer(GUIGlObject *o)
select the appropriate layer for each object
SUMORTree()
Constructor.
Definition SUMORTree.h:69