Loading...
Searching...
No Matches
mesh::MeshGenerator Class Reference

Generate a 2D triangular mesh. More...

#include <mesh/meshgenerator.h>

Collaboration diagram for mesh::MeshGenerator:

Public Member Functions

 MeshGenerator ()=default
 Construct an empty geometry accumulator with default options and no callbacks.
 
void setDomain (const QPolygonF &outerBoundary)
 Replace all domain rings with one copied boundary without changing other accumulated inputs.
 
void setDomains (const QVector< QPolygonF > &outerBoundaries)
 Replace domain-ring storage with copied outer polygons.
 
void addDomain (const QPolygonF &outerBoundary)
 Append one copied outer boundary to current domain components.
 
void addConstraintSegment (const ConstraintSegment &seg)
 Append an owned copy of a required constraint polyline and its marker/tag/strip request.
 
void addSteinerPoint (const SteinerPoint &pt)
 Append an owned mandatory point with marker/tag and optional sampled elevation metadata.
 
void reserveSteinerPoints (qsizetype additional)
 Reserve total capacity for current plus additional mandatory points without changing count.
 
void addHole (const QPointF &interiorPointInsideHole)
 Append a copied interior seed for a constraint-bounded excluded component.
 
void addRegion (const RegionMarker &region)
 Append a copied region-flood tagging seed and attribute metadata.
 
void addPatch (const PatchMesh &patch)
 Append an owned local-index quad patch for later validated constrained stitching.
 
void addQuadRegion (const QuadRegion &region)
 Append a copied region ring, tag, optional spacing and requested quad strategy.
 
void setTerrainBreaklines (const QVector< QVector< QPointF > > &lines)
 Replace owned dense noncoupling terrain line inputs.
 
const QVector< QVector< QPointF > > & acceptedTerrainBreaklines () const
 Borrow terrain lines retained by the most recent generation attempt.
 
QVector< QVector< QPointF > > previewTerrainBreaklines () const
 Compute early terrain-line preparation against accumulated geometry before generated strips.
 
const QVector< QuadRegionReport > & quadRegionReports () const
 Borrow one outcome report per configured quad region from the last generation attempt.
 
const GenerationStats & stats () const
 Borrow counts and diagnostics from the most recent generation attempt.
 
const QVector< PatchDecision > & cellPlanDecisions () const
 Borrow the patch planning records of the most recent generation attempt.
 
QSet< QPair< int, int > > quadRegionMergeLocks (const MeshResult &mesh) const
 Return the compatibility placeholder for triangle-pairing locks.
 
void setOptions (const GenerationOptions &opts)
 Copy numeric/strategy settings for subsequent generation without running validation.
 
void setRefineHook (const RefineHook &hook)
 Copy synchronous sizing, elevation, error, progress and cancellation callbacks.
 
MeshResult generate () const
 Generate an owned mixed mesh from copied geometry with local constraints, refinement and stitching.
 
QString tagForVertexMarker (int marker) const
 Copy the last generation attempt's marker-to-vertex-tag lookup value.
 
QString tagForEdgeMarker (int marker) const
 Copy the last generation attempt's constraint-marker tag value.
 

Detailed Description

Generate a 2D triangular mesh.

Usage:

MeshGenerator g;
g.setDomain(boundaryPolygon);
g.addSteinerPoint({junctionXY, 1, "J1"});       // marker = 1
g.addConstraintSegment({conduitPath, 100, "C5"}); // marker = 100
g.setOptions({.maxArea = 50.0, .minAngleDeg = 28.0});
const MeshResult r = g.generate();

Constructor & Destructor Documentation

◆ MeshGenerator()

mesh::MeshGenerator::MeshGenerator ( )
default

Construct an empty geometry accumulator with default options and no callbacks.

Owns subsequently copied inputs; no engine/GDAL/GUI handle, file access or generated mesh yet. Generator is thread-confined: logically const generation updates mutable reports/tag tables.

Member Function Documentation

◆ acceptedTerrainBreaklines()

const QVector< QVector< QPointF > > & mesh::MeshGenerator::acceptedTerrainBreaklines ( ) const
inlinenodiscard

Borrow terrain lines retained by the most recent generation attempt.

Returns
Const reference to owned prepared paths, closing point repeated for loops. Failure may leave partial diagnostic state, so pair with generate() result. Valid only while owner/current mutable state lives; next generation invalidates/replaces storage. No allocation or ownership transfer.

Break lines kept by the last generate() (after cutting and simplification).

◆ addConstraintSegment()

void mesh::MeshGenerator::addConstraintSegment ( const ConstraintSegment & seg)

Append an owned copy of a required constraint polyline and its marker/tag/strip request.

Parameters
[in]segBorrowed >=2-point finite mesh-frame path, unchanged; closed loops repeat first point. Marker/tag identity is caller-managed; stripWidth positive requests a generated aligned strip, otherwise plain constraint. Generation may join near/crossing ordinary constraints and drop unsuitable strips. No immediate geometry/identity audit, ownership transfer, file access or retained source references.

◆ addDomain()

void mesh::MeshGenerator::addDomain ( const QPolygonF & outerBoundary)

Append one copied outer boundary to current domain components.

Parameters
[in]outerBoundaryBorrowed finite simple ring in shared mesh XY frame, unchanged; invalid/ empty input is retained and handled later. Other rings expected disjoint as documented by setDomains. No immediate validation, coordinate transform, source retention, engine/IO changes; may allocate.

Append one more closed boundary polygon to the current domain set. Equivalent to building up via setDomains.

◆ addHole()

void mesh::MeshGenerator::addHole ( const QPointF & interiorPointInsideHole)

Append a copied interior seed for a constraint-bounded excluded component.

Parameters
[in]interiorPointInsideHoleBorrowed finite XY seed in intended closed-ring interior, unchanged. No boundary is created by a seed alone; caller supplies a closed constraint ring. Later joining can reseat nearby displaced seeds, and region flooding removes live component. No immediate validation, source retention, engine/file access or coordinate conversion; append may allocate.

◆ addPatch()

void mesh::MeshGenerator::addPatch ( const PatchMesh & patch)

Append an owned local-index quad patch for later validated constrained stitching.

Parameters
[in]patchBorrowed finite valid PatchMesh, unchanged. Caller supplies simple compatible boundary, valid CCW cells, matching subdivisions at shared interfaces and no out-of-domain/overlapping/required constraint-crossing interior. Validation deferred to generate(). Boundary edges become fixed, interior removed, quads appended after triangles; terrain elevation comes from caller hook/postprocessing. Copies attributes/lines; no immediate engine/IO mutation, source-pointer retention or unit conversion.

Stitch a structured quad patch (mesh/meshpatch.h) into the domain. Its boundary segments become fixed constraints (refinement never splits them), its interior a hole (seed = the first quad's centroid), and its quads are appended after every triangle with vertices merged by coordinate (GenerationOptions::patchSnapEps). Patch vertices receive whatever elevation fill the caller applies to MeshResult::vertices afterwards.

◆ addQuadRegion()

void mesh::MeshGenerator::addQuadRegion ( const QuadRegion & region)

Append a copied region ring, tag, optional spacing and requested quad strategy.

Parameters
[in]regionBorrowed finite mesh-frame QuadRegion, unchanged. Four-sided admissible regions may become mapped patches, others retain constrained triangles and positive spacing override; directional spacing units/axis follow mapped patch contract. Background regions affect sizing/tag handling without ordinary ring constraints. Outcome recorded by generate(), not guaranteed by request. No immediate classification/validation, source retention, coordinate conversion or IO.

Register a quad region (mesh/meshquadregion.h). A ring that classifyQuadRegion() finds four-sided is meshed with aligned (transfinite) quads at the region's spacing — or directional spacing — and the local size otherwise; any other ring, or one in TrianglesOnly mode, stays a constraint loop with triangles inside and its spacing (when > 0) as a size override. Cells inside carry the region's tag. quadRegionReports() says which happened and why.

◆ addRegion()

void mesh::MeshGenerator::addRegion ( const RegionMarker & region)

Append a copied region-flood tagging seed and attribute metadata.

Parameters
[in]regionBorrowed finite mesh-frame seed and tag/attribute, unchanged; attribute converts to int lookup key, so caller ensures representable values/unique intended identity. maxArea is stored but not independently used as a per-region size bound in this implementation; quad-region spacing or targetAreaAt provide sizing. First flood of a component determines otherwise-empty tags. No boundary creation, immediate validation, coordinate conversion, source retention or IO.

◆ addSteinerPoint()

void mesh::MeshGenerator::addSteinerPoint ( const SteinerPoint & pt)

Append an owned mandatory point with marker/tag and optional sampled elevation metadata.

Parameters
[in]ptBorrowed finite mesh-frame XY record, unchanged; duplicate coordinates may coalesce, later marker/tag collisions can overwrite lookup values. z/hasZ metadata are stored but this generator does not itself apply hasZ as an exact-height override; caller/pipeline maintains elevation seed cache. No immediate validation, CRS/units conversion, source retention or engine/IO change; append may allocate.

◆ cellPlanDecisions()

const QVector< PatchDecision > & mesh::MeshGenerator::cellPlanDecisions ( ) const
inlinenodiscard

Borrow the patch planning records of the most recent generation attempt.

Returns
Const reference to owned records, cleared at the start of each attempt and possibly partial on failure: fixed patches (when the patch gate is active), unified-plan region decisions, and conduit / bank-pair strip outcomes (unified planning only). Empty when neither unifiedCellPlanning nor RefineHook::terrainToleranceForFootprint is set. Valid until the next generate(); no allocation or synchronization.

◆ generate()

MeshResult mesh::MeshGenerator::generate ( ) const
nodiscard

Generate an owned mixed mesh from copied geometry with local constraints, refinement and stitching.

Returns
MeshResult with ok true and triangles before quads, or fresh empty failure result carrying errorMsg. Finite domain/constraint/seed/patch/region coordinates checked; caller still ensures valid scales/int-safe extents, compatible Cartesian units, intended rings/seeds and token/marker identities. Joins ordinary near/crossing constraints within scale-derived tolerance, never moves pinned/domain vertices during vertex merge; can insert kink points into nearby segments. Validates explicit patch placement/welded boundaries, classifies optional quad regions, drops unsuitable auto strips, prepares terrain lines, builds/restricts CDT, optionally seeds/refines/coarsens and flood-tags cells. Full input topology/physical model identity is not exhaustively certified. A leaking generated patch can trigger retry with its quantized outline-centroid identity excluded, at most 65 attempts. User patches can still fail rather than fall back. Cancellation clears returned mesh, but reports/tag tables may be partial. Quality/size/terrain targets can remain unmet at caps/fixed edges/spacing floors while ok true; inspect stats and perform caller's final accuracy/engine checks. Output can contain unused retained CDT vertices; no active-only compaction promised. Stored Steiner z/hasZ are not directly reapplied here; terrainElevationAt/postprocessing determine elevations. Although const, mutates cached reports, marker tables and retry set: thread-confined, no simultaneous calls/readers/setters. All callbacks synchronous as setRefineHook describes. Allocates full geometry, indexes/queues/temporary grids and result; cell budget is not a strict total memory bound and can be exceeded slightly by atomic topology operations. No engine/GDAL ownership or final file publication; diagnostic Qt logging occurs. Caller owns subsequent elevation validation, mapping, save and adoption.

Generates; a structured patch whose interior removal leaks (its ring is not watertight) is excluded and generation retried, so it falls back to triangles and is counted as dropped instead of failing.

Generate the mesh. Returns a result with ok=false + errorMsg on failure.

◆ previewTerrainBreaklines()

QVector< QVector< QPointF > > mesh::MeshGenerator::previewTerrainBreaklines ( ) const
nodiscard

Compute early terrain-line preparation against accumulated geometry before generated strips.

Returns
Owned copied prepared paths, or raw configured lines when no terrain/no positive minCellSize/ domain or no usable domain constraints. Does not update accepted lines/reports/tag tables. Existing explicit patches excluded; later auto strips can further trim lines. Allocates spatial indexes/paths, does not call engine/GDAL or publish files; geometry/scales must satisfy preparation prerequisites. No cancellation callback is passed into this preview helper.

The break lines generate() would keep before any quad strip is placed (the same cut-back and simplification against the inputs set so far) — the steps a size field may treat as captured by mesh edges (SizeFieldOptions::steps). Lines near later strips can still be cut back. Needs GenerationOptions::minCellSize > 0; otherwise the lines as set.

Here is the call graph for this function:

◆ quadRegionMergeLocks()

QSet< QPair< int, int > > mesh::MeshGenerator::quadRegionMergeLocks ( const MeshResult & mesh) const
nodiscard

Return the compatibility placeholder for triangle-pairing locks.

Parameters
[in]meshBorrowed result, ignored/unchanged; generator never pairs existing triangles.
Returns
Empty set on every call, no validation, retained reference, source mutation or IO.

Retained for API compatibility: always empty (the generator never pairs triangles).

◆ quadRegionReports()

const QVector< QuadRegionReport > & mesh::MeshGenerator::quadRegionReports ( ) const
inlinenodiscard

Borrow one outcome report per configured quad region from the last generation attempt.

Returns
Const reference, possibly empty/partial on early failure; requested/resolved modes and notes are diagnostics, not a current mesh validity certificate. Owner/no-mutation lifetime, no allocation, ownership transfer or concurrent generation allowed.

One report per addQuadRegion() call, filled by generate().

◆ reserveSteinerPoints()

void mesh::MeshGenerator::reserveSteinerPoints ( qsizetype additional)

Reserve total capacity for current plus additional mandatory points without changing count.

Parameters
[in]additionalIntended nonnegative extra count, caller-capped to representable qsizetype sum and available memory. No overflow/resource validation in this method. May allocate/reallocate owned storage, retains no source references, does no geometry/IO work.

Pre-reserve capacity for additional upcoming addSteinerPoint calls. Avoids the transient ~2x peak of geometric growth when bulk- adding terrain points; callers should cap the request.

◆ setDomain()

void mesh::MeshGenerator::setDomain ( const QPolygonF & outerBoundary)

Replace all domain rings with one copied boundary without changing other accumulated inputs.

Parameters
[in]outerBoundaryBorrowed polygon in common mesh Cartesian XY frame, unchanged. Open or repeated-closing-point form accepted by later normalization; finite/simple/nondegenerate ring required. Copies even empty/invalid input; validation deferred to generate(). Allocates owned storage, no CRS conversion, other-input clearing, engine/file changes or retained source reference.

Replace the domain with a single closed boundary polygon.

◆ setDomains()

void mesh::MeshGenerator::setDomains ( const QVector< QPolygonF > & outerBoundaries)

Replace domain-ring storage with copied outer polygons.

Parameters
[in]outerBoundariesBorrowed mutually compatible finite simple rings, unchanged; caller uses disjoint/nonoverlapping outer components with consistent constraints/seeds. Empty clears domains. Other input categories/reports are not reset here. Validation deferred, implicit sharing may allocate later; no source references, coordinate conversion, engine/IO operations or synchronization.

Replace the domain with multiple disjoint closed polygons. Each polygon becomes its own boundary ring; the interior of every ring is meshed and the gaps are left unmeshed. Useful when the meshing region is a multi-catchment area or a layer containing several non-overlapping polygons.

◆ setOptions()

void mesh::MeshGenerator::setOptions ( const GenerationOptions & opts)

Copy numeric/strategy settings for subsequent generation without running validation.

Parameters
[in]optsBorrowed options in mesh XY/area units, unchanged; caller supplies finite compatible positive scales and representable budgets. geometry/quad strategy checks occur later; angle target is not a guarantee. Reports are not reset until generation. No retained source reference or IO.

◆ setRefineHook()

void mesh::MeshGenerator::setRefineHook ( const RefineHook & hook)

Copy synchronous sizing, elevation, error, progress and cancellation callbacks.

Parameters
[in]hookBorrowed callable bundle copied into generator, so captures/resources must remain valid until replaced or generator destroyed. All invoked on calling thread; must not throw, reenter or mutate this generator. targetAreaAt supersedes maxArea (finite positive area in mesh XY squared units, <=0/nonfinite disables local cap). Terrain callbacks use mesh XY and consistent Z/residual units, three-point/height arrays borrowed only during invocation; positive error initializes witness, NaN denotes unknown. terrainErrorBound must certify residual INCLUDING coverage for coarsening. Callbacks may allocate/access caller-owned caches under caller's thread policy. isCancelled is cooperative, onProgress advisory and receives running counts not guaranteed final cell count. No invocation or validation here; caller excludes concurrent hook replacement/generation.

Install cancellation / progress / graded-sizing callbacks. When hook.targetAreaAt is set it supersedes GenerationOptions::maxArea. If the hook reports cancellation, generate() returns ok=false with errorMsg set rather than a partial mesh.

◆ setTerrainBreaklines()

void mesh::MeshGenerator::setTerrainBreaklines ( const QVector< QVector< QPointF > > & lines)

Replace owned dense noncoupling terrain line inputs.

Parameters
[in]linesBorrowed polylines in mesh XY frame, unchanged; closed loops repeat first point. Preparation filters nonfinite/repeated samples, trims/simplifies/splits/culls lines to avoid other constraints and patches. Lines do not themselves seed sizing, holes, region barriers or boundaryEdges. Copy only here; reports unchanged until generation, no callback, source retention or engine/file access.

Terrain break lines (mesh/terrainbreaklines.h): DENSE polylines in mesh coordinates (vertex spacing about one DEM pixel; the cut-back distance grows with a line's spacing); a closed loop repeats its first point. They become non-coupling constraints so a mesh edge lies on each curb, wall or bank — but only where they keep clear of everything else: generate() cuts every line back from the domain and closed hole rings, other constraints, patches, Steiner points and previously accepted lines (longest first), simplifies what remains within max(floor/4, 0.75 · spacing), splits it where it folds back, and drops pieces shorter than four floor sizes. They do not seed sizing, never bound holes or region tags, and are not listed in MeshResult::boundaryEdges.

◆ stats()

const GenerationStats & mesh::MeshGenerator::stats ( ) const
inlinenodiscard

Borrow counts and diagnostics from the most recent generation attempt.

Returns
Const owned reference, reset at each attempt and possibly partial on failure/cancellation. Capped refinement or below-angle counts can coexist with successful mesh. No ownership transfer, allocation, synchronization or source mutation; next generation replaces contents.

Counts from the last generate().

◆ tagForEdgeMarker()

QString mesh::MeshGenerator::tagForEdgeMarker ( int marker) const
nodiscard

Copy the last generation attempt's constraint-marker tag value.

Parameters
[in]markerCaller edge marker integer.
Returns
Owned/implicitly shared last configured nonzero/nonempty constraint tag or empty absent. Not an output-edge existence proof; failure may retain partial lookup. No mutation/IO/input retention.

Translate an output edge's marker back to a tag string.

◆ tagForVertexMarker()

QString mesh::MeshGenerator::tagForVertexMarker ( int marker) const
nodiscard

Copy the last generation attempt's marker-to-vertex-tag lookup value.

Parameters
[in]markerCaller marker integer; zero/unknown returns empty unless explicitly stored.
Returns
Owned/implicitly shared tag, empty if absent. Built only from nonzero/nonempty Steiner marker entries, later entries overwrite; may be partial on failed generation. No source mutation/IO.

Translate an output point's marker back to a tag string. Used by clients that don't want to maintain their own map. The generator builds this from SteinerPoint::marker→tag during generate().


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