![]() |
SWMMVis
6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
|
Uniform spatial grid index over a set of axis-aligned bboxes. More...
#include <meshspatialgrid.h>
Public Member Functions | |
| void | clear () |
| bool | isEmpty () const |
| void | rebuild (const QVector< QRectF > &bboxes) |
| (Re)build the grid from a set of bboxes. | |
| QVector< int > | query (const QRectF &rect) const |
Return the bbox indices whose bboxes intersect rect. | |
| void | candidatesAtPoint (double x, double y, const int *&begin, const int *&end) const |
| Candidate bbox indices for the single grid cell containing the point (x,y), returned as the CSR slice [*begin, *end) into cellIndices. | |
Public Attributes | |
| QRectF | extent |
| double | cellW = 0.0 |
| double | cellH = 0.0 |
| int | cols = 0 |
| int | rows = 0 |
| QVector< int > | cellOffsets |
| QVector< int > | cellIndices |
| int | avgPerCell = 0 |
| std::vector< quint32 > | seen |
| quint32 | epoch = 0 |
Uniform spatial grid index over a set of axis-aligned bboxes.
Construction: call rebuild with the bbox set; it sizes the grid, inserts every bbox into all cells its area overlaps, and prepares the query-time scratch state.
Lookup: call query with a region of interest; returns the bbox indices whose bboxes intersect the query rect, deduplicated and in insertion order.
Empty bbox sets are tolerated — isEmpty becomes true and queries return an empty list.
|
inline |
Candidate bbox indices for the single grid cell containing the point (x,y), returned as the CSR slice [*begin, *end) into cellIndices.
For point location this is preferable to query: a point lands in exactly one cell, and the bbox that contains it is guaranteed to be registered in that cell (rebuild() inserts each bbox into every cell its area overlaps, and the point's cell is always within the bbox's cell range). So no dedup is needed and no QVector is allocated — the caller just runs its exact point-in-shape test over the slice.
Yields an empty range (begin == end == nullptr) when the grid is unbuilt or the point is non-finite. An off-extent point clamps to the nearest border cell; its candidates simply fail the caller's containment test, so a true miss still resolves to "not found".
Reads only the immutable post-rebuild state — it does NOT touch the mutable seen/epoch scratch used by query() — so it allocates nothing and is safe to call in a per-point hot loop.
|
inline |
|
inline |
| QVector< int > MeshSpatialGrid::query | ( | const QRectF & | rect | ) | const |
Return the bbox indices whose bboxes intersect rect.
Indices are deduplicated (a bbox spanning many cells is reported exactly once) and returned in the same order they appear in the cell sweep. Empty grid, empty query, or no-intersection all yield an empty vector.
| void MeshSpatialGrid::rebuild | ( | const QVector< QRectF > & | bboxes | ) |
(Re)build the grid from a set of bboxes.
Invalid bboxes (negative width / height) are silently skipped but still occupy a slot in the index space so the returned indices remain parallel to the caller's input vector.
Complexity: O(B + N) where B = number of bbox–cell memberships and N = total cells. Two linear passes plus a prefix-sum.
| int MeshSpatialGrid::avgPerCell = 0 |
| double MeshSpatialGrid::cellH = 0.0 |
| QVector<int> MeshSpatialGrid::cellIndices |
| QVector<int> MeshSpatialGrid::cellOffsets |
| double MeshSpatialGrid::cellW = 0.0 |
| int MeshSpatialGrid::cols = 0 |
|
mutable |
| QRectF MeshSpatialGrid::extent |
| int MeshSpatialGrid::rows = 0 |
|
mutable |