Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 : /****************************************************************************/
14 : /// @file LayeredRTree.h
15 : /// @author Jakob Erdmann
16 : /// @date 16.10.2012
17 : ///
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 :
29 : #include <utils/gui/globjects/GUIGlObject.h>
30 : #include <utils/gui/globjects/GUIGlObjectTypes.h>
31 : #include <utils/gui/settings/GUIVisualizationSettings.h>
32 : #include <utils/geom/Boundary.h>
33 :
34 : #include "SUMORTree.h"
35 :
36 :
37 : // ===========================================================================
38 : // class definitions
39 : // ===========================================================================
40 : /** @class LayeredRTree
41 : * @brief A RT-tree for efficient storing of SUMO's GL-objects in layers
42 : *
43 : * This class maintains SUMORTrees for each layer (only 2 at the moment) but
44 : * provides the same interface as SUMORTree
45 : */
46 : class LayeredRTree : public SUMORTree {
47 : public:
48 : /// @brief Constructor
49 7525 : LayeredRTree() {
50 7525 : myLayers.push_back(new SUMORTree());
51 7525 : myLayers.push_back(new SUMORTree());
52 7525 : }
53 :
54 :
55 : /// @brief Destructor
56 7512 : ~LayeredRTree() {
57 22536 : for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
58 15024 : delete *it;
59 : }
60 : myLayers.clear();
61 7512 : }
62 :
63 :
64 : /** @brief Insert entry (delegate to appropriate layer)
65 : * @param a_min Min of bounding rect
66 : * @param a_max Max of bounding rect
67 : * @param a_dataId Positive Id of data. Maybe zero, but negative numbers not allowed.
68 : */
69 409525 : void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
70 523910 : myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);
71 409525 : }
72 :
73 :
74 : /** @brief Remove entry (delegate to appropriate layer)
75 : * @param a_min Min of bounding rect
76 : * @param a_max Max of bounding rect
77 : * @param a_dataId Positive Id of data. Maybe zero, but negative numbers not allowed.
78 : */
79 2396 : void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {
80 4736 : myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);
81 2396 : }
82 :
83 : /** @brief Find all within search rectangle (searches all layers in order)
84 : * @param a_min Min of search bounding rect
85 : * @param a_max Max of search bounding rect
86 : * @param a_searchResult Search result array. Caller should set grow size. Function will reset, not append to array.
87 : * @param a_resultCallback Callback function to return result. Callback should return 'true' to continue searching
88 : * @param a_context User context to pass as parameter to a_resultCallback
89 : * @return Returns the number of entries found
90 : */
91 538498 : int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {
92 : int result = 0;
93 1615486 : for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {
94 1076992 : result += (*it)->Search(a_min, a_max, c);
95 : }
96 538494 : return result;
97 : }
98 :
99 :
100 : protected:
101 : /// @brief the layers for drawing
102 : std::vector<SUMORTree*> myLayers;
103 :
104 : private:
105 :
106 : /// @brief select the appropriate layer for each object
107 : inline size_t selectLayer(GUIGlObject* o) {
108 411921 : 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 116725 : default:
117 116725 : return 0;
118 : }
119 : }
120 :
121 : };
|