GEOS 3.11.1
SimpleSTRdistance.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <cassert>
18#include <cstddef>
19#include <geos/export.h>
20#include <geos/geom/Envelope.h>
21#include <geos/index/strtree/SimpleSTRtree.h>
22#include <geos/index/strtree/SimpleSTRnode.h>
23
24#include <vector>
25#include <queue>
26
27#ifdef _MSC_VER
28#pragma warning(push)
29#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30#endif
31
32namespace geos {
33namespace index { // geos::index
34namespace strtree { // geos::index::strtree
35
36
37
38
39
40class GEOS_DLL SimpleSTRpair {
41
42private:
43
44 SimpleSTRnode* node1;
45 SimpleSTRnode* node2;
46 ItemDistance* itemDistance;
47 double m_distance;
48
60 double distance();
61
62public:
63
64 SimpleSTRpair(SimpleSTRnode* p_node1, SimpleSTRnode* p_node2, ItemDistance* p_itemDistance)
65 : node1(p_node1)
66 , node2(p_node2)
67 , itemDistance(p_itemDistance)
68 {
69 m_distance = distance();
70 }
71
72 SimpleSTRnode* getNode(int i) const;
73
84 double getDistance() const;
85
91 bool isLeaves() const;
92
99 double maximumDistance();
100
101 friend std::ostream& operator<<(std::ostream& os, SimpleSTRpair& pair);
102
103
104};
105
106
107
108class GEOS_DLL SimpleSTRdistance {
109
110
111public:
112
113 struct STRpairQueueCompare {
114 bool
115 operator()(const SimpleSTRpair* a, const SimpleSTRpair* b)
116 {
117 return a->getDistance() > b->getDistance();
118 }
119 };
120
121 typedef std::priority_queue<SimpleSTRpair*,
122 std::vector<SimpleSTRpair*>,
123 STRpairQueueCompare> STRpairQueue;
124
125
126 /* Initialize class */
127 SimpleSTRdistance(SimpleSTRnode* root1, SimpleSTRnode* root2, ItemDistance* p_itemDistance);
128
129 /* Turn over the calculation */
130 std::pair<const void*, const void*> nearestNeighbour();
131 bool isWithinDistance(double maxDistance);
132
133
134private:
135
136 std::deque<SimpleSTRpair> pairStore;
137 SimpleSTRpair* initPair;
138 ItemDistance* itemDistance;
139
140 /* Utility method to store allocated pairs */
141 SimpleSTRpair* createPair(SimpleSTRnode* p_node1, SimpleSTRnode* p_node2, ItemDistance* p_itemDistance);
142
143 std::pair<const void*, const void*> nearestNeighbour(SimpleSTRpair* p_initPair);
144 std::pair<const void*, const void*> nearestNeighbour(SimpleSTRpair* p_initPair, double maxDistance);
145
146 bool isWithinDistance(SimpleSTRpair* p_initPair, double maxDistance);
147
148 void expandToQueue(SimpleSTRpair* pair, STRpairQueue&, double minDistance);
149 void expand(SimpleSTRnode* nodeComposite, SimpleSTRnode* nodeOther,
150 bool isFlipped, STRpairQueue& priQ, double minDistance);
151
152
153};
154
155
156
157
158
159} // namespace geos::index::strtree
160} // namespace geos::index
161} // namespace geos
162
163#ifdef _MSC_VER
164#pragma warning(pop)
165#endif
166
Basic namespace for all GEOS functionalities.
Definition: geos.h:39