Loading...
Searching...
No Matches
mesh.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2#pragma once
3#include "geometry.hpp"
4#include "events.hpp"
5#include <array>
6#include <functional>
7#include <string>
8#include <vector>
9
10namespace meshkit
11{
13using Index = std::uint32_t;
20constexpr Index missingIndex = ~Index(0);
27enum class PathKind : std::uint8_t { Outer, Hole, Line, Region };
37
48struct Path {
49 std::vector<Index> vertices;
54 std::int32_t marker = 0;
59 std::int64_t id = 0;
64 bool closed = false;
65};
66
72struct Cell {
77 std::array<Index, 4> vertices{};
82 std::int32_t region = 0;
83 std::uint8_t count = 3;
84};
85
86struct Edge {
94 Index a = 0, b = 0;
99 std::int32_t marker = 0;
100};
101
102struct Label {
103 std::int32_t id = 0;
104 std::string name;
105};
106
114 std::int64_t sourceId = 0;
115 std::int32_t marker = 0;
116};
117
125struct Metadata {
139 bool unitsKnown = true;
146 std::string crs, description;
147};
148// Geometry and sparse numeric attributes only; no engine/coupling ownership.
149// Empty id/marker arrays mean sequential one-based ids / zero markers. Arrays
150// are owned and contiguous. Connectivity is zero-based uint32 throughout.
159struct Mesh {
160 std::vector<Point3> vertices;
161 std::vector<Cell> cells;
166 std::vector<Edge> edges;
171 std::vector<Path> paths;
182 std::vector<std::int64_t> vertexIds, cellIds, edgeIds;
184 std::vector<std::int32_t> vertexMarkers;
185 std::vector<Label> labels;
187 std::vector<VertexAlias> aliases;
189};
190
198struct Limits {
209 std::uint64_t maxVertices = 20000000, maxCells = 20000000, maxEdges = 40000000;
211 std::uint64_t maxWorkspaceBytes = std::uint64_t(4) << 30;
218 std::uint64_t maxWork = 0; // Zero: 20 billion for the operation's own counter (above).
226 std::uint64_t maxMetadataBytes = 8 * 1024 * 1024, maxRecordBytes = 1024 * 1024;
227};
228
233 std::uint32_t schemaVersion = 1;
242 std::string code, message;
251 std::uint64_t work = 0, record = 0;
252 double seconds = 0;
257 bool complete() const noexcept
258 {
260 }
261};
262// Local connectivity/finite/positive convex-cell validation. It does not prove
263// arbitrary nonincident nonoverlap or CRS correctness. Caller owns metadata.
284OperationReport validateMesh(const Mesh &, const Limits & = {},
285 const std::function<bool()> &cancelled = {});
286}
The Qt-free MeshKit library: job events and progress (meshkit::runtime), the neutral mesh model,...
OperationReport validateMesh(const Mesh &, const Limits &={}, const std::function< bool()> &cancelled={})
Check a mesh's local validity without modifying it.
Definition mesh.cpp:9
std::uint32_t Index
Zero-based index into a native vertex, cell or edge array.
Definition mesh.hpp:13
PathKind
Role of a Path in a JobRequest or a delivered Mesh.
Definition mesh.hpp:27
@ Line
Constrained polyline (breakline) whose segments become chains of cell edges.
Definition mesh.hpp:27
@ Hole
Ring subtracted from the domain; cells inside it are removed.
Definition mesh.hpp:27
@ Outer
Outer domain ring; the domain is the union of all outer rings minus the holes.
Definition mesh.hpp:27
@ Region
Closed constrained ring inside the domain; it separates region-label components but does not add or r...
Definition mesh.hpp:27
RunStatus
Status of a running or finished operation (see statusName()).
Definition events.hpp:43
@ CompleteWithExceptions
Finished with a result, but with recorded exceptions.
Definition events.hpp:46
@ Complete
Finished; every checked requirement holds.
Definition events.hpp:45
@ Failed
Stopped by an error such as an exception or I/O error; no result.
Definition events.hpp:49
constexpr Index missingIndex
Sentinel index (all bits set, 4294967295) meaning "no index".
Definition mesh.hpp:20
Triangle or quadrilateral cell of a Mesh.
Definition mesh.hpp:72
std::int32_t region
Region identifier, named by the Label with the same id when one exists; 0 when no region was assigned...
Definition mesh.hpp:82
std::array< Index, 4 > vertices
Corner vertex indices in counter-clockwise order; only the first count entries are used (runJob() wri...
Definition mesh.hpp:77
std::uint8_t count
Number of corners: 3 (triangle) or 4 (quadrilateral).
Definition mesh.hpp:83
Vertex and cell counters of an operation or event; -1 marks a value not available.
Definition events.hpp:81
Marked edge between two vertices of a Mesh.
Definition mesh.hpp:86
Index b
Second endpoint, a zero-based index into Mesh::vertices; validateMesh() requires it to differ from a.
Definition mesh.hpp:94
std::int32_t marker
Numeric marker; runJob() writes the Path::marker of the source path (or the marker of a patch line).
Definition mesh.hpp:99
Index a
First endpoint, a zero-based index into Mesh::vertices.
Definition mesh.hpp:94
Name of a region identifier used by Cell::region.
Definition mesh.hpp:102
std::string name
Region name as UTF-8 text.
Definition mesh.hpp:104
Resource caps for jobs, validation and file I/O.
Definition mesh.hpp:198
std::uint64_t maxWorkspaceBytes
Cap on estimated workspace in bytes (computed from counts, not measured); default 4 GiB.
Definition mesh.hpp:211
std::uint64_t maxRecordBytes
Cap on the length in bytes of one SMS 2DM text line; default 1 MiB.
Definition mesh.hpp:226
std::uint64_t maxMetadataBytes
Cap on metadata text bytes (CRS, description, label names and, for a job, the provider identity); the...
Definition mesh.hpp:226
std::uint64_t maxEdges
Maximum number of edges, of paths, and of vertex indices summed over all paths; default 40 000 000.
Definition mesh.hpp:209
std::uint64_t maxVertices
Maximum number of vertices (source points, working vertices during refinement, mesh vertices,...
Definition mesh.hpp:209
std::uint64_t maxWork
Work-unit allowance of one operation's own counter.
Definition mesh.hpp:218
std::uint64_t maxCells
Maximum number of cells; default 20 000 000.
Definition mesh.hpp:209
Neutral owned mesh: XYZ vertices, triangle/quad cells, marked edges, paths, optional external ids and...
Definition mesh.hpp:159
Metadata metadata
Units, CRS text and description.
Definition mesh.hpp:188
std::vector< Label > labels
Names of the region ids used by Cell::region; ids are unique.
Definition mesh.hpp:185
std::vector< Cell > cells
Triangle and quadrilateral cells.
Definition mesh.hpp:161
std::vector< Path > paths
Delivered paths.
Definition mesh.hpp:171
std::vector< Point3 > vertices
Vertex positions; every coordinate must be finite.
Definition mesh.hpp:160
std::vector< std::int32_t > vertexMarkers
Numeric vertex markers: empty means all zero; otherwise one marker per vertex.
Definition mesh.hpp:184
std::vector< Edge > edges
Marked constraint edges, not every cell edge.
Definition mesh.hpp:166
std::vector< VertexAlias > aliases
Further source identities merged into shared vertices (exact XY duplicates).
Definition mesh.hpp:187
std::vector< std::int64_t > edgeIds
External edge ids: empty means one-based sequential ids; otherwise one unique id per edge.
Definition mesh.hpp:182
std::vector< std::int64_t > vertexIds
External vertex ids: empty means 1, 2, 3, ...; otherwise one unique id per vertex.
Definition mesh.hpp:182
std::vector< std::int64_t > cellIds
External cell ids: empty means one-based sequential ids; otherwise one unique id per cell.
Definition mesh.hpp:182
Physical units, coordinate reference text and description of a mesh or job request.
Definition mesh.hpp:125
double verticalMetresPerUnit
Metres per Z (elevation) unit; default 1.
Definition mesh.hpp:134
bool unitsKnown
Whether the unit scales are declared; default true.
Definition mesh.hpp:139
double horizontalMetresPerUnit
Metres per XY plane unit, the unit of point and vertex x/y; default 1.
Definition mesh.hpp:134
std::string description
Free-form description (UTF-8); may be empty.
Definition mesh.hpp:146
std::string crs
Coordinate reference system text (UTF-8), carried through unchanged; may be empty.
Definition mesh.hpp:146
Versioned outcome of a native operation: mesh validation, file I/O, or a job (as the base of JobRepor...
Definition mesh.hpp:232
RunStatus status
Final status; Failed until the operation sets it.
Definition mesh.hpp:234
std::uint32_t schemaVersion
Report schema version; 1 in this release.
Definition mesh.hpp:233
std::string message
Human-readable description of the outcome.
Definition mesh.hpp:242
std::uint64_t record
Record reached by a file reader (the SMS 2DM line number, or the number of MeshKit binary records rea...
Definition mesh.hpp:251
std::uint64_t work
Work units used by the operation's own counter (see Limits::maxWork).
Definition mesh.hpp:251
std::string code
Short machine-readable outcome code, e.g.
Definition mesh.hpp:242
double seconds
Elapsed time of the operation in seconds (steady clock).
Definition mesh.hpp:252
Counts counts
Vertex and cell counters of the operation; -1 where unavailable.
Definition mesh.hpp:243
bool complete() const noexcept
Whether the operation delivered a result.
Definition mesh.hpp:257
Indexed polyline or ring: a source constraint of a JobRequest, or a delivered path of a Mesh.
Definition mesh.hpp:48
bool closed
Explicit closure of a Line path.
Definition mesh.hpp:64
std::int32_t marker
Numeric marker; runJob() copies it to every delivered Edge along this path.
Definition mesh.hpp:54
std::vector< Index > vertices
Zero-based vertex indices; at least two are required.
Definition mesh.hpp:49
PathKind kind
Role of the path; defaults to an open Line.
Definition mesh.hpp:50
Extra source identity merged into a shared output vertex.
Definition mesh.hpp:112
std::int64_t sourceId
External id of the merged source point.
Definition mesh.hpp:114
Index vertex
Zero-based index of the shared vertex in Mesh::vertices.
Definition mesh.hpp:113
std::int32_t marker
Marker of the merged source point.
Definition mesh.hpp:115