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
mesh::TerrainErrorField::Impl Struct Reference
Collaboration diagram for mesh::TerrainErrorField::Impl:

Classes

struct  Stats
 
struct  Triangle
 

Public Member Functions

bool prepare (const QPointF *xy, const double *z, Triangle &T) const
 Validate a query plane and populate its local geometry/certification context.
 
bool nodeBound (const Node &n, const Triangle &T, double &bound, bool &overridden) const
 Check node/query rectangle relevance and derive its affine residual upper bound.
 
 ~Impl ()
 Release owned OGR forward/reverse transforms and the GDAL dataset handle.
 
bool readTile (GDALDataset *src, OGRCoordinateTransformation *ct, int tc, int tr, Tile &t, QString &err) const
 Read one native raster tile and optionally compute transformed local mesh pixel centers.
 
const Tile * tile (int col, int row) const
 Borrow a cached native tile for an absolute raster pixel, loading it on a miss.
 
const Tile * insertTile (std::unique_ptr< Tile > t) const
 Transfer a completed heap tile into the shared cost-bounded LRU cache.
 
double z (const Tile *t, int i) const
 Read one native tile elevation, reject missing/nonfinite input and apply vertical scale.
 
void meshXY (const Tile *t, int col, int row, int i, double &x, double &y) const
 Resolve one tile sample center into mesh coordinates relative to the field origin.
 
void summarizeTile (const Tile *t, int tx, int ty, Node *nodes, int leafCols, Stats &st) const
 Fit disjoint 16-pixel leaves of one tile and accumulate raw-terrain sample statistics.
 
void writeHeader (QDataStream &s) const
 Serialize the identity envelope for the native-ABI persisted summary hierarchy.
 
bool loadIndex (const QString &file)
 Attempt to replace summaries/statistics from a matching persisted index without modifying on a miss.
 
bool saveIndex (const QString &file) const
 Best-effort atomically persist the retained hierarchy and raw-terrain statistics.
 
void prefetch () const
 Best-effort warm the full summary-window raster cache after loading a saved hierarchy.
 
void prefetchBoxes (const QVector< QRectF > &boxes) const
 Load a budget-selected subset of missing tiles under mesh-coordinate rectangles in parallel.
 
bool build (const std::function< bool(double)> &progress)
 Construct leaf residual planes and aggregate the dyadic raw-terrain summary hierarchy.
 

Public Attributes

QRectF overrideBounds
 
std::function< double(double, double, double)> queryOverride
 
std::function< bool(const QRectF &)> overrideIntersects
 
GDALDataset * ds = nullptr
 
QString path
 Source file; empty for in-memory grids.
 
OGRCoordinateTransformation * toMesh = nullptr
 
OGRCoordinateTransformation * toDEM = nullptr
 
int width = 0
 
int height = 0
 
int c0 = 0
 
int r0 = 0
 
int cols = 0
 
int rows = 0
 
double geo [6] = {}
 
double inv [6] = {}
 
double scale = 1
 
double noData = nan
 
QPointF origin
 
QVector< Level > levels
 
QCache< quint64, Tile > cache
 
QMutex cacheMutex
 Guards cache only during the parallel build.
 
bool floatTiles = false
 
QString error
 
bool wholeUnits = true
 
double minZ = std::numeric_limits<double>::infinity()
 
double maxZ = -std::numeric_limits<double>::infinity()
 
std::function< bool()> cancelled
 
bool indexLoaded = false
 
bool indexSaved = false
 

Static Public Attributes

static constexpr quint32 kIndexMagic = 0x54454649
 
static constexpr quint16 kIndexVersion = 1
 

Constructor & Destructor Documentation

◆ ~Impl()

mesh::TerrainErrorField::Impl::~Impl ( )
inline

Release owned OGR forward/reverse transforms and the GDAL dataset handle.

Note
Member destruction also releases cache-owned tiles, summary arrays, strings and callbacks. No external input buffers are owned; exclude all concurrent readers/workers before destroying state. No source raster writes or callback notifications are performed.

Member Function Documentation

◆ build()

bool mesh::TerrainErrorField::Impl::build ( const std::function< bool(double)> &  progress)
inline

Construct leaf residual planes and aggregate the dyadic raw-terrain summary hierarchy.

Parameters
[in]progressOptional borrowed synchronous fraction callback, invoked at 0, completed row chunks, repeated .95 for parent levels, and 1. False stores Cancelled and returns false; exceptions propagate, no callback retained and reentrant field/dataset mutation is unsupported.
Returns
True after complete hierarchy, false for summary index overflow, tile/worker read/transform failure or progress cancellation. Requires initialized positive raster/window metadata, default-empty summaries/statistics and owned dataset; appends levels and can leave a partial hierarchy/cache on failure. Uses separate GDAL/OGR handles per parallel worker, disjoint leaf writes and deterministic statistic reductions; insertion is mutex protected. Allocates summary/worker storage, warms LRU, performs read-only raster IO and no index-file write or query-override application. Requires exclusive external field access.
Here is the call graph for this function:

◆ insertTile()

const Tile * mesh::TerrainErrorField::Impl::insertTile ( std::unique_ptr< Tile >  t) const
inline

Transfer a completed heap tile into the shared cost-bounded LRU cache.

Parameters
[in]tRequired nonnull unique_ptr moved by value; ownership is released to QCache, which can immediately delete/reject an over-budget tile. Header/arrays must match field storage/transform policy.
Returns
Borrowed cache-owned pointer for its key, null if not retained; invalidated by later eviction/ rebuild/destruction, never delete. Computes byte cost including transformed coordinate arrays; mutates cache and may allocate/evict. Caller holds cacheMutex during parallel build/warm-up insertion, and must exclude external query concurrency; no tile IO or reference retention beyond cache ownership.
Here is the caller graph for this function:

◆ loadIndex()

bool mesh::TerrainErrorField::Impl::loadIndex ( const QString &  file)
inline

Attempt to replace summaries/statistics from a matching persisted index without modifying on a miss.

Parameters
[in]fileBorrowed input pathname, unchanged; caller has selected a source/settings-specific cache key.
Returns
True after bytewise header match, checked level/count/extent reads, exact EOF and root/leaf layout validation; false on any miss, with current levels/statistics/error text unchanged. Node arrays load into temporaries before commit. Does not authenticate/checksum node contents or validate every intermediate hierarchy relationship/finite bound, nor prove source identity beyond the header. Allocates/reads file only, retains no filename reference and does not warm raster tiles or set public flags.
Here is the call graph for this function:

◆ meshXY()

void mesh::TerrainErrorField::Impl::meshXY ( const Tile *  t,
int  col,
int  row,
int  i,
double &  x,
double &  y 
) const
inline

Resolve one tile sample center into mesh coordinates relative to the field origin.

Parameters
[in]tRequired borrowed live tile; transformed arrays present when toMesh is active, unchanged.
[in]colAbsolute raster column corresponding to i, unchecked.
[in]rowAbsolute raster row corresponding to i, unchecked.
[in]iValid tile-local row-major index, used for cached transformed arrays.
[out]xBorrowed local mesh x output, always overwritten.
[out]yBorrowed local mesh y output, always overwritten; use distinct outputs.
Note
Without reprojection evaluates affine transform at col+.5,row+.5 then subtracts origin; with reprojection reads precomputed local arrays. No IO, coordinate-transform calls, allocations or validation.
Here is the caller graph for this function:

◆ nodeBound()

bool mesh::TerrainErrorField::Impl::nodeBound ( const Node &  n,
const Triangle &  T,
double &  bound,
bool &  overridden 
) const

Check node/query rectangle relevance and derive its affine residual upper bound.

Parameters
[in]nBorrowed summary node with finite valid bounds/plane/residual metadata, unchanged.
[in]TBorrowed successfully prepared triangle context in the same local frame, unchanged.
[out]boundBorrowed vertical upper bound, assigned only when node is nonempty and bbox overlaps.
[out]overriddenBorrowed flag, assigned only on that same relevant-node path; true when retained override bounds/predicate can affect the rectangle intersection.
Returns
False for empty/bbox-disjoint nodes, leaving outputs untouched; true for relevant nodes. Bound combines stored residual, corner plane difference and query slack, not an exact triangle polygon intersection. Invokes optional conservative callback synchronously; no IO/allocation or source mutation.

◆ prefetch()

void mesh::TerrainErrorField::Impl::prefetch ( ) const
inline

Best-effort warm the full summary-window raster cache after loading a saved hierarchy.

Note
Returns for in-memory/no-path fields or when estimated window bytes exceed cache budget. Uses synchronous QtConcurrent workers with separate datasets/transform clones and mutex-protected cache insertion; full-tile padding can still evict earlier tiles. Individual failures are ignored and future queries retry on demand. No hierarchy/result change, cancellation/progress or stored-error update; allocates worker tiles/readers and requires no simultaneous external field query/rebuild.
Here is the call graph for this function:

◆ prefetchBoxes()

void mesh::TerrainErrorField::Impl::prefetchBoxes ( const QVector< QRectF > &  boxes) const
inline

Load a budget-selected subset of missing tiles under mesh-coordinate rectangles in parallel.

Parameters
[in]boxesBorrowed finite mesh-CRS rectangles, unchanged; transformed pixel extrema/floor/ceil indices need int headroom. Invalid transform boxes are skipped, empty/no-path input returns.
Note
Clips candidate tile range to the summary window, then selects roughly half-cache capacity from an unordered key set (at least one selected key may exceed a zero computed budget). Workers own separate readers/cloned transforms, insert under mutex and ignore local failures without changing stored error. Mutates LRU and can evict entries, retains no boxes; synchronous completion, no concurrent external queries/rebuild or cancellation. Prefetch is a performance hint and never a coverage guarantee.
Here is the call graph for this function:

◆ prepare()

bool mesh::TerrainErrorField::Impl::prepare ( const QPointF *  xy,
const double *  z,
Triangle &  T 
) const

Validate a query plane and populate its local geometry/certification context.

Parameters
[in]xyRequired borrowed three-corner array in absolute mesh coordinates, finite and unchanged.
[in]zRequired borrowed three-elevation array in scaled output units, finite and unchanged.
[out]TBorrowed query context, partly overwritten before possible determinant failure; usable only when true. Stores relative corners, plane, bounds, rounding slack and override relevance.
Returns
False for no hierarchy, nonfinite z or zero/nonfinite determinant, true otherwise. Caller must ensure remaining plane arithmetic is finite/representable; no full coefficient check is added. Can invoke retained override-intersection callback synchronously, exceptions propagate; no raster IO or input-reference retention, requires exclusive field/callback access.
Here is the call graph for this function:

◆ readTile()

bool mesh::TerrainErrorField::Impl::readTile ( GDALDataset *  src,
OGRCoordinateTransformation *  ct,
int  tc,
int  tr,
Tile &  t,
QString &  err 
) const
inline

Read one native raster tile and optionally compute transformed local mesh pixel centers.

Parameters
[in]srcRequired borrowed open dataset with band 1 and dimensions matching this field; caller owns/closes it and provides one independent reader per parallel worker.
[in]ctOptional borrowed source-to-mesh transform, independent per worker; null uses implicit native coordinates. Caller owns/destroys transform and must exclude concurrent use of that handle.
[in]tcNonnegative tile column with tc*256 inside width, representable multiplication.
[in]trNonnegative tile row with tr*256 inside height.
[out]tBorrowed destination tile, header/arrays overwritten incrementally and possibly partial on failure. Native z uses exact float or double storage; transformed coordinates subtract field origin.
[out]errBorrowed diagnostic string, overwritten on RasterIO/transform failure, unchanged on success.
Returns
True after read and finite transformed-coordinate validation, false otherwise. Reads raw band values without scaling/NoData conversion (z() does that later), allocates tile arrays, retains no handles or output pointers and does not insert into the shared cache. Field metadata must remain stable.
Here is the caller graph for this function:

◆ saveIndex()

bool mesh::TerrainErrorField::Impl::saveIndex ( const QString &  file) const
inline

Best-effort atomically persist the retained hierarchy and raw-terrain statistics.

Parameters
[in]fileBorrowed destination path, parent volume/directory must exist and be writable, unchanged.
Returns
False for invalid/low-space volume (requires twice estimated bytes), open/short-write/stream/ commit failure; true on QSaveFile commit. Checks raw node writes, cancels on a short write, does not change in-memory summaries or diagnostics. Writes pinned Qt header/metadata and native Node byte arrays, so compatible ABI/endianness and caller-keyed source identity are required. No dataset writes, file-reference retention or guarantee against later external replacement.
Here is the call graph for this function:

◆ summarizeTile()

void mesh::TerrainErrorField::Impl::summarizeTile ( const Tile *  t,
int  tx,
int  ty,
Node *  nodes,
int  leafCols,
Stats &  st 
) const
inline

Fit disjoint 16-pixel leaves of one tile and accumulate raw-terrain sample statistics.

Parameters
[in]tRequired borrowed complete tile matching the supplied absolute tile origin, unchanged.
[in]txAbsolute tile first column aligned to 256, with valid 16-pixel-aligned summary window.
[in]tyAbsolute tile first row under the same alignment/extent contract.
[in,out]nodesRequired writable leaf-node array with leafCols*leafRows extent, initially defaulted; only this tile's disjoint leaves are populated, including bounds, valid/missing counts, fitted plane and maximum residual plus roundoff. No concurrent worker may touch the same leaf.
[in]leafColsPositive leaf-grid column stride, matching window layout.
[in,out]stBorrowed worker-local reduction, whole-unit flag ANDed and min/max extended over finite scaled samples. Requires positive field scale and representable fits/index arithmetic.
Note
Allocates no new tile/summary buffers, performs no IO or callback invocation and reads stable field metadata only; caller later merges reductions and owns all pointers. Does not apply query overrides.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tile()

const Tile * mesh::TerrainErrorField::Impl::tile ( int  col,
int  row 
) const
inline

Borrow a cached native tile for an absolute raster pixel, loading it on a miss.

Parameters
[in]colAbsolute raster column, valid range [0,width); out-of-range returns null.
[in]rowAbsolute raster row, valid range [0,height); out-of-range returns null.
Returns
Cache-owned tile pointer or null for bounds/read/cache-insertion failure. Pointer must never be deleted/retained across cache insertion/eviction, rebuild or destruction. Misses use this field's owned reader/transform, update error on checked IO failure, allocate and mutate LRU; no internal query locking, so external concurrent access is unsupported. Source raster remains read only.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeHeader()

void mesh::TerrainErrorField::Impl::writeHeader ( QDataStream &  s) const
inline

Serialize the identity envelope for the native-ABI persisted summary hierarchy.

Parameters
[in,out]sBorrowed output stream, advanced by magic/version/Node size/tile/leaf constants, raster/window dimensions, geotransform, scale, NoData, origin and reprojection-presence flag. Caller pins Qt_6_0 version and owns the device; stream errors remain in its status.
Note
Does not include source path/mtime/content or full CRS strings, so caller cache naming must encode those identities. Raw Node payload portability is limited to compatible ABI/endianness; no stream flush, ownership transfer, node serialization or field mutation occurs here.
Here is the caller graph for this function:

◆ z()

double mesh::TerrainErrorField::Impl::z ( const Tile *  t,
int  i 
) const
inline

Read one native tile elevation, reject missing/nonfinite input and apply vertical scale.

Parameters
[in]tRequired borrowed live cache/worker tile with arrays matching floatTiles, unchanged.
[in]iValid row-major local element index [0,t.cols*t.rows), unchecked.
Returns
Raw value times field scale in output elevation units, NaN for nonfinite raw value or exact NoData match. Scale multiplication is not separately overflow-checked. No IO, allocation, ownership retention or cache mutation; pointer must stay live throughout the read.
Here is the caller graph for this function:

Member Data Documentation

◆ c0

int mesh::TerrainErrorField::Impl::c0 = 0

◆ cache

QCache<quint64, Tile> mesh::TerrainErrorField::Impl::cache
mutable

◆ cacheMutex

QMutex mesh::TerrainErrorField::Impl::cacheMutex
mutable

Guards cache only during the parallel build.

◆ cancelled

std::function<bool()> mesh::TerrainErrorField::Impl::cancelled

◆ cols

int mesh::TerrainErrorField::Impl::cols = 0

◆ ds

GDALDataset* mesh::TerrainErrorField::Impl::ds = nullptr

◆ error

QString mesh::TerrainErrorField::Impl::error
mutable

◆ floatTiles

bool mesh::TerrainErrorField::Impl::floatTiles = false

◆ geo

double mesh::TerrainErrorField::Impl::geo[6] = {}

◆ height

int mesh::TerrainErrorField::Impl::height = 0

◆ indexLoaded

bool mesh::TerrainErrorField::Impl::indexLoaded = false

◆ indexSaved

bool mesh::TerrainErrorField::Impl::indexSaved = false

◆ inv

double mesh::TerrainErrorField::Impl::inv[6] = {}

◆ kIndexMagic

constexpr quint32 mesh::TerrainErrorField::Impl::kIndexMagic = 0x54454649
staticconstexpr

◆ kIndexVersion

constexpr quint16 mesh::TerrainErrorField::Impl::kIndexVersion = 1
staticconstexpr

◆ levels

QVector<Level> mesh::TerrainErrorField::Impl::levels

◆ maxZ

double mesh::TerrainErrorField::Impl::maxZ = -std::numeric_limits<double>::infinity()

◆ minZ

double mesh::TerrainErrorField::Impl::minZ = std::numeric_limits<double>::infinity()

◆ noData

double mesh::TerrainErrorField::Impl::noData = nan

◆ origin

QPointF mesh::TerrainErrorField::Impl::origin

◆ overrideBounds

QRectF mesh::TerrainErrorField::Impl::overrideBounds

◆ overrideIntersects

std::function<bool(const QRectF &)> mesh::TerrainErrorField::Impl::overrideIntersects

◆ path

QString mesh::TerrainErrorField::Impl::path

Source file; empty for in-memory grids.

◆ queryOverride

std::function<double(double, double, double)> mesh::TerrainErrorField::Impl::queryOverride

◆ r0

int mesh::TerrainErrorField::Impl::r0 = 0

◆ rows

int mesh::TerrainErrorField::Impl::rows = 0

◆ scale

double mesh::TerrainErrorField::Impl::scale = 1

◆ toDEM

OGRCoordinateTransformation * mesh::TerrainErrorField::Impl::toDEM = nullptr

◆ toMesh

OGRCoordinateTransformation* mesh::TerrainErrorField::Impl::toMesh = nullptr

◆ wholeUnits

bool mesh::TerrainErrorField::Impl::wholeUnits = true

◆ width

int mesh::TerrainErrorField::Impl::width = 0

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