/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file LayeredRTree.h14/// @author Jakob Erdmann15/// @date 16.10.201216///17// A wrapper around RT-trees for for efficient storing of SUMO's GL-objects and18// accessing them ordered by their layer19// Note that we only need two layers at this time:20// 1 (GLO_LANE, GLO_VEHICLE, GLO_POI)21// 2 all the rest22// The search order returns layer 2 first because it must be drawn before layer23// 1 for alpha blending to work24/****************************************************************************/25#pragma once26#include <config.h>2728#include <utils/gui/globjects/GUIGlObject.h>29#include <utils/gui/globjects/GUIGlObjectTypes.h>30#include <utils/gui/settings/GUIVisualizationSettings.h>31#include <utils/geom/Boundary.h>3233#include "SUMORTree.h"343536// ===========================================================================37// class definitions38// ===========================================================================39/** @class LayeredRTree40* @brief A RT-tree for efficient storing of SUMO's GL-objects in layers41*42* This class maintains SUMORTrees for each layer (only 2 at the moment) but43* provides the same interface as SUMORTree44*/45class LayeredRTree : public SUMORTree {46public:47/// @brief Constructor48LayeredRTree() {49myLayers.push_back(new SUMORTree());50myLayers.push_back(new SUMORTree());51}525354/// @brief Destructor55~LayeredRTree() {56for (std::vector<SUMORTree*>::iterator it = myLayers.begin(); it != myLayers.end(); ++it) {57delete *it;58}59myLayers.clear();60}616263/** @brief Insert entry (delegate to appropriate layer)64* @param a_min Min of bounding rect65* @param a_max Max of bounding rect66* @param a_dataId Positive Id of data. Maybe zero, but negative numbers not allowed.67*/68void Insert(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {69myLayers[selectLayer(a_dataId)]->Insert(a_min, a_max, a_dataId);70}717273/** @brief Remove entry (delegate to appropriate layer)74* @param a_min Min of bounding rect75* @param a_max Max of bounding rect76* @param a_dataId Positive Id of data. Maybe zero, but negative numbers not allowed.77*/78void Remove(const float a_min[2], const float a_max[2], GUIGlObject* const & a_dataId) {79myLayers[selectLayer(a_dataId)]->Remove(a_min, a_max, a_dataId);80}8182/** @brief Find all within search rectangle (searches all layers in order)83* @param a_min Min of search bounding rect84* @param a_max Max of search bounding rect85* @param a_searchResult Search result array. Caller should set grow size. Function will reset, not append to array.86* @param a_resultCallback Callback function to return result. Callback should return 'true' to continue searching87* @param a_context User context to pass as parameter to a_resultCallback88* @return Returns the number of entries found89*/90int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings& c) const {91int result = 0;92for (std::vector<SUMORTree*>::const_iterator it = myLayers.begin(); it != myLayers.end(); ++it) {93result += (*it)->Search(a_min, a_max, c);94}95return result;96}979899protected:100/// @brief the layers for drawing101std::vector<SUMORTree*> myLayers;102103private:104105/// @brief select the appropriate layer for each object106inline size_t selectLayer(GUIGlObject* o) {107switch (o->getType()) {108case GLO_EDGE:109case GLO_LANE:110case GLO_POI:111case GLO_VEHICLE:112case GLO_PERSON:113return 1;114break;115default:116return 0;117}118}119120};121122123