1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file NamedRTree.h
11 /// @author Daniel Krajzewicz
12 /// @author Jakob Erdmann
13 /// @author Michael Behrisch
14 /// @date 27.10.2008
15 /// @version $Id$
16 ///
17 // A RT-tree for efficient storing of SUMO's Named objects
18 /****************************************************************************/
19 #ifndef NamedRTree_h
20 #define NamedRTree_h
21
22
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26
27 #include <set>
28 #include <foreign/rtree/RTree.h>
29 #include <utils/common/Named.h>
30
31
32 // specialized implementation for speedup and avoiding warnings
33 #define NAMED_RTREE_QUAL RTree<Named*, Named, float, 2, Named::StoringVisitor>
34
35 template<>
RectSphericalVolume(Rect * a_rect)36 inline float NAMED_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
37 ASSERT(a_rect);
38 const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
39 const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
40 return .78539816f * (extent0 * extent0 + extent1 * extent1);
41 }
42
43 template<>
CombineRect(Rect * a_rectA,Rect * a_rectB)44 inline NAMED_RTREE_QUAL::Rect NAMED_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
45 ASSERT(a_rectA && a_rectB);
46 Rect newRect;
47 newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
48 newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
49 newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
50 newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
51 return newRect;
52 }
53
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
57 /** @class NamedRTree
58 * @brief A RT-tree for efficient storing of SUMO's Named objects
59 *
60 * This class specialises the used RT-tree implementation from "rttree.h".
61 * It stores names of "Named"-objects.
62 * @see Named
63 */
64 class NamedRTree : private NAMED_RTREE_QUAL {
65 public:
66 /// @brief Constructor
NamedRTree()67 NamedRTree() : NAMED_RTREE_QUAL(&Named::addTo) {
68 }
69
70
71 /// @brief Destructor
~NamedRTree()72 ~NamedRTree() {
73 }
74
75
76 /** @brief Insert entry
77 * @param a_min Min of bounding rect
78 * @param a_max Max of bounding rect
79 * @param a_data The instance of a Named-object to add (the ID is added)
80 * @see RTree::Insert
81 */
Insert(const float a_min[2],const float a_max[2],Named * const & a_data)82 void Insert(const float a_min[2], const float a_max[2], Named* const& a_data) {
83 NAMED_RTREE_QUAL::Insert(a_min, a_max, a_data);
84 }
85
86
87 /** @brief Remove entry
88 * @param a_min Min of bounding rect
89 * @param a_max Max of bounding rect
90 * @param a_data The instance of a Named-object to remove
91 * @see RTree::Remove
92 */
Remove(const float a_min[2],const float a_max[2],Named * const & a_data)93 void Remove(const float a_min[2], const float a_max[2], Named* const& a_data) {
94 NAMED_RTREE_QUAL::Remove(a_min, a_max, a_data);
95 }
96
97
98 /** @brief Remove all enrties
99 * @see RTree::RemoveAll
100 */
RemoveAll()101 void RemoveAll() {
102 NAMED_RTREE_QUAL::RemoveAll();
103 }
104
105
106 /** @brief Find all within search rectangle
107 * @param a_min Min of search bounding rect
108 * @param a_max Max of search bounding rect
109 * @param a_searchResult Search result array. Caller should set grow size. Function will reset, not append to array.
110 * @param a_resultCallback Callback function to return result. Callback should return 'true' to continue searching
111 * @param a_context User context to pass as parameter to a_resultCallback
112 * @return Returns the number of entries found
113 * @see RTree::Search
114 */
Search(const float a_min[2],const float a_max[2],const Named::StoringVisitor & c)115 int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor& c) const {
116 return NAMED_RTREE_QUAL::Search(a_min, a_max, c);
117 }
118
119
120 };
121
122
123 #endif
124
125 /****************************************************************************/
126