SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
meshspatialgrid.h File Reference
#include <QRectF>
#include <QVector>
#include <QtGlobal>
#include <algorithm>
#include <cmath>
#include <vector>
Include dependency graph for meshspatialgrid.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MeshSpatialGrid
 Uniform spatial grid index over a set of axis-aligned bboxes. More...
 

Detailed Description

Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
Date
2026
License\n GPL-3.0-or-later

Uniform 2D spatial grid over an arbitrary set of axis-aligned rectangles. Used by SWMM2DMeshLayer to cull mesh triangles and edges to the visible map extent in O(visible) instead of O(N) per paint.

Originally a nested struct inside SWMM2DMeshLayer. Extracted to a stand- alone translation unit so the spatial-index logic can be unit-tested without linking the entire layer (which pulls in Qt Widgets, GDAL, the SWMM engine, and most of the renderer pipeline).

Storage layout

The cell occupancy lists are stored in CSR form:

 cellOffsets[k] .. cellOffsets[k+1]   →   range in cellIndices
                                          holding the bbox indices
                                          that touch cell k.

One contiguous QVector<int> for cellIndices means cell traversal in query() is a sequential read, which is materially cheaper than the prior QVector<QVector<int>> layout (one heap allocation per cell, pointer chase on every cell access).

Threading

query() is hot — it is called twice per frame (tri + edge grids) from the QSG renderer / QPainter fallback. It mutates seen and epoch through mutable members so the hot path needs zero allocations. Callers must serialise query() — the existing call sites are all on the Qt render / paint thread, so this is implicit.