Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2008-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 NamedRTree.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Michael Behrisch 18 : /// @date 27.10.2008 19 : /// 20 : // A RT-tree for efficient storing of SUMO's Named objects 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : #include <set> 25 : #include <foreign/rtree/RTree.h> 26 : #include <utils/common/Named.h> 27 : 28 : 29 : // specialized implementation for speedup and avoiding warnings 30 : #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor> 31 : 32 : template<> 33 : inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) { 34 : ASSERT(a_rect); 35 7757858 : const float extent0 = a_rect->m_max[0] - a_rect->m_min[0]; 36 7757858 : const float extent1 = a_rect->m_max[1] - a_rect->m_min[1]; 37 4941878 : return .78539816f * (extent0 * extent0 + extent1 * extent1); 38 : } 39 : 40 : template<> 41 : inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) { 42 : ASSERT(a_rectA && a_rectB); 43 : Rect newRect; 44 6929102 : newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]); 45 6929102 : newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]); 46 6929102 : newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]); 47 6929102 : newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]); 48 : return newRect; 49 : } 50 : 51 : // =========================================================================== 52 : // class definitions 53 : // =========================================================================== 54 : /** @class NamedRTree 55 : * @brief A RT-tree for efficient storing of SUMO's Named objects 56 : * 57 : * This class specialises the used RT-tree implementation from "rttree.h". 58 : * It stores names of "Named"-objects. 59 : * @see Named 60 : */ 61 : class NamedRTree : private NAMED_RTREE_QUAL { 62 : public: 63 : /// @brief Constructor 64 175894 : NamedRTree() : NAMED_RTREE_QUAL(&Named::addTo) { 65 : } 66 : 67 : 68 : /// @brief Destructor 69 163 : ~NamedRTree() { 70 140428 : } 71 : 72 : 73 : /** @brief Insert entry 74 : * @param a_min Min of bounding rect 75 : * @param a_max Max of bounding rect 76 : * @param a_data The instance of a Named-object to add (the ID is added) 77 : * @see RTree::Insert 78 : */ 79 5829 : void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) { 80 329984 : NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data); 81 328251 : } 82 : 83 : 84 : /** @brief Remove entry 85 : * @param a_min Min of bounding rect 86 : * @param a_max Max of bounding rect 87 : * @param a_data The instance of a Named-object to remove 88 : * @see RTree::Remove 89 : */ 90 12 : void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) { 91 16344 : NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data); 92 12 : } 93 : 94 : 95 : /** @brief Remove all enrties 96 : * @see RTree::RemoveAll 97 : */ 98 : void RemoveAll() { 99 34945 : NAMED_RTREE_QUAL::RemoveAll(); 100 : } 101 : 102 : 103 : /** @brief Find all within search rectangle 104 : * @param a_min Min of search bounding rect 105 : * @param a_max Max of search bounding rect 106 : * @param a_searchResult Search result array. Caller should set grow size. Function will reset, not append to array. 107 : * @param a_resultCallback Callback function to return result. Callback should return 'true' to continue searching 108 : * @param a_context User context to pass as parameter to a_resultCallback 109 : * @return Returns the number of entries found 110 : * @see RTree::Search 111 : */ 112 1648 : int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const { 113 226562 : return NAMED_RTREE_QUAL::Search(a_min, a_max, c); 114 : } 115 : 116 : 117 : };