/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2008-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 NamedRTree.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date 27.10.200818///19// A RT-tree for efficient storing of SUMO's Named objects20/****************************************************************************/21#pragma once22#include <config.h>23#include <set>24#include <foreign/rtree/RTree.h>25#include <utils/common/Named.h>262728// specialized implementation for speedup and avoiding warnings29#define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>3031template<>32inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {33ASSERT(a_rect);34const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];35const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];36return .78539816f * (extent0 * extent0 + extent1 * extent1);37}3839template<>40inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {41ASSERT(a_rectA && a_rectB);42Rect newRect;43newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);44newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);45newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);46newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);47return newRect;48}4950// ===========================================================================51// class definitions52// ===========================================================================53/** @class NamedRTree54* @brief A RT-tree for efficient storing of SUMO's Named objects55*56* This class specialises the used RT-tree implementation from "rttree.h".57* It stores names of "Named"-objects.58* @see Named59*/60class NamedRTree : private NAMED_RTREE_QUAL {61public:62/// @brief Constructor63NamedRTree() : NAMED_RTREE_QUAL(&Named::addTo) {64}656667/// @brief Destructor68~NamedRTree() {69}707172/** @brief Insert entry73* @param a_min Min of bounding rect74* @param a_max Max of bounding rect75* @param a_data The instance of a Named-object to add (the ID is added)76* @see RTree::Insert77*/78void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {79NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);80}818283/** @brief Remove entry84* @param a_min Min of bounding rect85* @param a_max Max of bounding rect86* @param a_data The instance of a Named-object to remove87* @see RTree::Remove88*/89void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {90NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);91}929394/** @brief Remove all enrties95* @see RTree::RemoveAll96*/97void RemoveAll() {98NAMED_RTREE_QUAL::RemoveAll();99}100101102/** @brief Find all within search rectangle103* @param a_min Min of search bounding rect104* @param a_max Max of search bounding rect105* @param a_searchResult Search result array. Caller should set grow size. Function will reset, not append to array.106* @param a_resultCallback Callback function to return result. Callback should return 'true' to continue searching107* @param a_context User context to pass as parameter to a_resultCallback108* @return Returns the number of entries found109* @see RTree::Search110*/111int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {112return NAMED_RTREE_QUAL::Search(a_min, a_max, c);113}114115116};117118119