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 Struct Reference

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

#include <meshspatialgrid.h>

Collaboration diagram for MeshSpatialGrid:

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
 

Detailed Description

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.

Member Function Documentation

◆ candidatesAtPoint()

void MeshSpatialGrid::candidatesAtPoint ( double  x,
double  y,
const int *&  begin,
const int *&  end 
) const
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.

◆ clear()

void MeshSpatialGrid::clear ( )
inline
Here is the caller graph for this function:

◆ isEmpty()

bool MeshSpatialGrid::isEmpty ( ) const
inline
Here is the caller graph for this function:

◆ query()

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.

Here is the caller graph for this function:

◆ rebuild()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ avgPerCell

int MeshSpatialGrid::avgPerCell = 0

◆ cellH

double MeshSpatialGrid::cellH = 0.0

◆ cellIndices

QVector<int> MeshSpatialGrid::cellIndices

◆ cellOffsets

QVector<int> MeshSpatialGrid::cellOffsets

◆ cellW

double MeshSpatialGrid::cellW = 0.0

◆ cols

int MeshSpatialGrid::cols = 0

◆ epoch

quint32 MeshSpatialGrid::epoch = 0
mutable

◆ extent

QRectF MeshSpatialGrid::extent

◆ rows

int MeshSpatialGrid::rows = 0

◆ seen

std::vector<quint32> MeshSpatialGrid::seen
mutable

The documentation for this struct was generated from the following files: