Generate a 2D triangular mesh. More...
#include <mesh/meshgenerator.h>
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 ®ion) |
| 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 ®ion) |
| 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. | |
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();
|
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.
|
inlinenodiscard |
Borrow terrain lines retained by the most recent generation attempt.
Break lines kept by the last generate() (after cutting and simplification).
| void mesh::MeshGenerator::addConstraintSegment | ( | const ConstraintSegment & | seg | ) |
Append an owned copy of a required constraint polyline and its marker/tag/strip request.
| [in] | seg | Borrowed >=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. |
| void mesh::MeshGenerator::addDomain | ( | const QPolygonF & | outerBoundary | ) |
Append one copied outer boundary to current domain components.
| [in] | outerBoundary | Borrowed 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.
| void mesh::MeshGenerator::addHole | ( | const QPointF & | interiorPointInsideHole | ) |
Append a copied interior seed for a constraint-bounded excluded component.
| [in] | interiorPointInsideHole | Borrowed 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. |
| void mesh::MeshGenerator::addPatch | ( | const PatchMesh & | patch | ) |
Append an owned local-index quad patch for later validated constrained stitching.
| [in] | patch | Borrowed 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.
| void mesh::MeshGenerator::addQuadRegion | ( | const QuadRegion & | region | ) |
Append a copied region ring, tag, optional spacing and requested quad strategy.
| [in] | region | Borrowed 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.
| void mesh::MeshGenerator::addRegion | ( | const RegionMarker & | region | ) |
Append a copied region-flood tagging seed and attribute metadata.
| [in] | region | Borrowed 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. |
| void mesh::MeshGenerator::addSteinerPoint | ( | const SteinerPoint & | pt | ) |
Append an owned mandatory point with marker/tag and optional sampled elevation metadata.
| [in] | pt | Borrowed 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. |
|
inlinenodiscard |
Borrow the patch planning records of the most recent generation attempt.
|
nodiscard |
Generate an owned mixed mesh from copied geometry with local constraints, refinement and stitching.
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.
|
nodiscard |
Compute early terrain-line preparation against accumulated geometry before generated strips.
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.
|
nodiscard |
Return the compatibility placeholder for triangle-pairing locks.
| [in] | mesh | Borrowed result, ignored/unchanged; generator never pairs existing triangles. |
Retained for API compatibility: always empty (the generator never pairs triangles).
|
inlinenodiscard |
Borrow one outcome report per configured quad region from the last generation attempt.
One report per addQuadRegion() call, filled by generate().
| void mesh::MeshGenerator::reserveSteinerPoints | ( | qsizetype | additional | ) |
Reserve total capacity for current plus additional mandatory points without changing count.
| [in] | additional | Intended 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.
| void mesh::MeshGenerator::setDomain | ( | const QPolygonF & | outerBoundary | ) |
Replace all domain rings with one copied boundary without changing other accumulated inputs.
| [in] | outerBoundary | Borrowed 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.
| void mesh::MeshGenerator::setDomains | ( | const QVector< QPolygonF > & | outerBoundaries | ) |
Replace domain-ring storage with copied outer polygons.
| [in] | outerBoundaries | Borrowed 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.
| void mesh::MeshGenerator::setOptions | ( | const GenerationOptions & | opts | ) |
Copy numeric/strategy settings for subsequent generation without running validation.
| [in] | opts | Borrowed 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. |
| void mesh::MeshGenerator::setRefineHook | ( | const RefineHook & | hook | ) |
Copy synchronous sizing, elevation, error, progress and cancellation callbacks.
| [in] | hook | Borrowed 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.
| void mesh::MeshGenerator::setTerrainBreaklines | ( | const QVector< QVector< QPointF > > & | lines | ) |
Replace owned dense noncoupling terrain line inputs.
| [in] | lines | Borrowed 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.
|
inlinenodiscard |
Borrow counts and diagnostics from the most recent generation attempt.
Counts from the last generate().
|
nodiscard |
Copy the last generation attempt's constraint-marker tag value.
| [in] | marker | Caller edge marker integer. |
Translate an output edge's marker back to a tag string.
|
nodiscard |
Copy the last generation attempt's marker-to-vertex-tag lookup value.
| [in] | marker | Caller marker integer; zero/unknown returns empty unless explicitly stored. |
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().