Skip to content

Commit 21b0f96

Browse files
r-tree implementation
1 parent 6333af5 commit 21b0f96

File tree

7 files changed

+768
-11
lines changed

7 files changed

+768
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ set(GUI_HDRS
842842
${GUI_HDR_DIR}/safe_mode_gui.h
843843
${GUI_HDR_DIR}/SendToGpsDlg.h
844844
${GUI_HDR_DIR}/SendToPeerDlg.h
845+
${GUI_HDR_DIR}/spatial_rtree.h
845846
${GUI_HDR_DIR}/Station_Data.h
846847
${GUI_HDR_DIR}/styles.h
847848
${GUI_HDR_DIR}/svg_utils.h

gui/include/gui/shapefile_basemap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "ShapefileReader.hpp"
3737
#include "poly_math.h"
3838
#include "ocpndc.h"
39+
#include "spatial_rtree.h"
3940

4041
#if (defined(OCPN_GHC_FILESYSTEM) || \
4142
(defined(__clang_major__) && (__clang_major__ < 15)))
@@ -143,6 +144,7 @@ class ShapeBaseChart {
143144
_min_scale(min_scale),
144145
_filename(filename),
145146
_reader(nullptr),
147+
_rtree(nullptr),
146148
_color(color) {
147149
_is_usable = fs::exists(filename);
148150
}
@@ -153,13 +155,16 @@ class ShapeBaseChart {
153155
this->_is_tiled = t._is_tiled;
154156
this->_min_scale = t._min_scale;
155157
this->_reader = nullptr;
158+
this->_rtree = nullptr; // Will be recreated when LoadSHP() is called
156159
this->_color = t._color;
157160
this->_dmod = t._dmod;
158161
this->_loading = t._loading;
159162
}
160163
~ShapeBaseChart() {
161164
CancelLoading(); // Ensure async operation is done before cleanup.
162165
delete _reader;
166+
// _rtree is managed by a std::unique_ptr so it will be automatically
167+
// cleaned up
163168
}
164169

165170
void SetColor(wxColor color) { _color = color; }
@@ -263,6 +268,12 @@ class ShapeBaseChart {
263268
* for efficient spatial queries.
264269
*/
265270
std::unordered_map<LatLonKey, std::vector<size_t>> _tiles;
271+
/**
272+
* R-tree spatial index for efficient spatial queries. Provides logarithmic
273+
* search time for finding features that intersect with a given bounding box
274+
* or line segment. Built during LoadSHP() and used by CrossesLand().
275+
*/
276+
std::unique_ptr<RTree> _rtree;
266277
/**
267278
* The color used for rendering land areas in this specific chart instance.
268279
* Initially set during construction from the parent ShapeBaseChartSet's

0 commit comments

Comments
 (0)