Loading...
Searching...
No Matches
constraintsimplifier.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2#pragma once
3#include <QPointF>
4#include <QString>
5#include <QVector>
6#include <functional>
7#include <optional>
8
9namespace mesh
10{
28 enum class Mode { Preserve, Simplify };
32 double maxDeviation = 0; // XY, in the common planar frame
36 double maxZDeviation = 0; // Z, in the supplied elevation units; 0 preserves exact heights
39 double maxTurnDegrees = 5;
42 double maxAreaChangeFraction = .001; // Relative to original ring area; -1 disables
45 double maxAreaChange = -1; // Absolute area in squared XY units; -1 disables
48 double minimumClearance = 0;
56 QString validate() const;
57};
58// Unset fields inherit from the parent policy. The caller supplies consistent
59// planar/elevation units before resolving; no implicit conversion or clamping.
67 int mode = -1; // -1 inherits, 0 preserves, 1 simplifies
79 std::optional<double> maxDeviation, maxZDeviation, maxTurnDegrees,
87 QString validate() const;
95};
96
105 QString id;
106 QVector<QPointF> xy;
108 QVector<double> z; // Empty or exactly one finite value per XY vertex
110 QVector<bool> fixed; // Semantic vertices; absent flags mean false
111 bool closed = false;
127 int marker = 0;
128 bool requiredInMesh = true;
130 QString label; // Optional human-readable source label; id remains stable.
131};
132
138 QString id;
145 qsizetype removed = 0, rejectedShortcuts = 0;
160 bool budgetRetained = false, rolledBack = false;
161 // Empty means identity. Otherwise maps each output vertex to its original index.
163 QVector<int> sourceVertices;
164};
165
169 QVector<QPointF> protectedPoints;
172 std::function<bool()> cancelled;
173 // Zero selects 256 operations per input vertex plus 100,000. Exhaustion
174 // retains original features, never relaxes geometry checks.
176 quint64 workBudget = 0;
181 // A bounded shared-edge workspace; exceeding it retains the original graph.
183 quint64 maximumWorkspaceBytes = quint64(1) << 30;
184};
185
192 bool ok = false, cancelled = false;
193 QString error;
194 QVector<SimplificationFeature> features;
195 QVector<SimplificationChange> changes;
204 quint64 sharedSegments = 0, sharedChains = 0, workUsed = 0;
205};
206// All features share one immutable segment index. Input must describe the
207// intended original graph in one planar frame. Coordinates never move. Every
208// accepted shortcut is checked against its entire original span (XY and Z),
209// original obstacles/pins and swept pockets; output shortcuts are checked
210// against each other. Exact shared-edge chains are simplified once under the
211// strictest owner policies and stitched back with source mappings. Differently
212// sampled overlaps remain conservative; coordinates are never proximity-welded.
233simplifyConstraints(const QVector<SimplificationFeature> &features,
234 const ConstraintSimplificationOptions &options = {});
235
236namespace detail
237{
238// Internal shared-chain adapter; the public entry point validates input first.
250ConstraintSimplificationResult
251simplifySharedConstraints(const QVector<SimplificationFeature> &features,
252 const ConstraintSimplificationOptions &options);
253}
254}
ConstraintSimplificationResult simplifySharedConstraints(const QVector< SimplificationFeature > &features, const ConstraintSimplificationOptions &options)
Internal: group exactly shared segments into chains, simplify each chain once under the strictest own...
Definition constraintshared.cpp:6
The Qt-facing MeshKit API (meshkit::core_qt, meshkit::model_qt, meshkit::io_qt): mesh value types and...
ConstraintSimplificationResult simplifyConstraints(const QVector< SimplificationFeature > &features, const ConstraintSimplificationOptions &options={})
Remove redundant vertices from a collection of constraint features without moving any coordinate.
Definition constraintsimplifier.cpp:9
Partial ConstraintSimplificationPolicy layered over a parent policy, for per-source overrides.
Definition constraintsimplifier.h:65
int mode
Mode override; validate() rejects values outside [-1, 1].
Definition constraintsimplifier.h:67
ConstraintSimplificationPolicy resolve(ConstraintSimplificationPolicy parent) const
Apply the set fields to a parent policy.
Definition constraintsimplifier.cpp:8
std::optional< double > maxTurnDegrees
Replaces ConstraintSimplificationPolicy::maxTurnDegrees when set (degrees).
Definition constraintsimplifier.h:79
std::optional< double > minimumClearance
Replaces ConstraintSimplificationPolicy::minimumClearance when set (XY units).
Definition constraintsimplifier.h:80
std::optional< double > maxAreaChangeFraction
Replaces ConstraintSimplificationPolicy::maxAreaChangeFraction when set; must be nonnegative here,...
Definition constraintsimplifier.h:80
std::optional< double > maxZDeviation
Replaces ConstraintSimplificationPolicy::maxZDeviation when set (Z units).
Definition constraintsimplifier.h:79
QString validate() const
Check the override on its own.
Definition constraintsimplifier.cpp:7
std::optional< double > maxDeviation
Replaces ConstraintSimplificationPolicy::maxDeviation when set (XY units).
Definition constraintsimplifier.h:79
Collection-wide inputs and resource limits for simplifyConstraints().
Definition constraintsimplifier.h:166
std::function< bool()> cancelled
Optional cancellation poll, called synchronously at the start and about every 4096 work units; return...
Definition constraintsimplifier.h:172
quint64 maximumWorkspaceBytes
Estimated byte limit for the shared-edge canonicalization records (1 GiB by default).
Definition constraintsimplifier.h:183
QVector< QPointF > protectedPoints
Finite points in the planar frame that no shortcut may pass through or enclose between itself and the...
Definition constraintsimplifier.h:169
quint64 workBudget
Work-unit limit for the pass; 0 selects 256 per input vertex plus 100,000.
Definition constraintsimplifier.h:176
bool canonicalizeSharedEdges
Simplify segments shared exactly by several features once, as canonical chains under the strictest ow...
Definition constraintsimplifier.h:180
Per-feature limits for constraint simplification.
Definition constraintsimplifier.h:21
double maxDeviation
Largest XY distance a removed vertex may lie from the shortcut replacing it; 0 allows removing only e...
Definition constraintsimplifier.h:32
Mode mode
Simplification mode; Preserve by default.
Definition constraintsimplifier.h:29
double minimumClearance
XY distance a shortcut must keep from other original segments and protected points that do not touch ...
Definition constraintsimplifier.h:48
double maxTurnDegrees
Corner limit in degrees (0 = straight on): a vertex whose direction change exceeds it,...
Definition constraintsimplifier.h:39
double maxAreaChange
Rings only: largest |area change|; must be finite and nonnegative or exactly -1.
Definition constraintsimplifier.h:45
Mode
Whether a feature may lose vertices.
Definition constraintsimplifier.h:28
@ Preserve
Keep every vertex; the feature is returned unchanged.
Definition constraintsimplifier.h:28
@ Simplify
Remove vertices wherever this policy and the topology checks allow it.
Definition constraintsimplifier.h:28
QString validate() const
Check every field against its valid range.
Definition constraintsimplifier.cpp:6
double maxAreaChangeFraction
Rings only: largest |area change| as a fraction of |original area|, in [0, 1] or exactly -1.
Definition constraintsimplifier.h:42
double maxZDeviation
Largest difference between a removed vertex's z and the height interpolated linearly along the shortc...
Definition constraintsimplifier.h:36
Output of simplifyConstraints(); features and changes are parallel to the input.
Definition constraintsimplifier.h:186
bool ok
True when the pass finished, also when exhausted limits kept the originals (see SimplificationChange:...
Definition constraintsimplifier.h:192
quint64 sharedChains
Canonical chains built from shared segments; counted only by the shared-edge path,...
Definition constraintsimplifier.h:204
quint64 sharedSegments
Distinct segments owned by more than one feature; counted only by the shared-edge path,...
Definition constraintsimplifier.h:204
bool cancelled
Cancellation was observed; ok is false and the features are the originals.
Definition constraintsimplifier.h:192
QVector< SimplificationFeature > features
Output features; the originals on failure.
Definition constraintsimplifier.h:194
QVector< SimplificationChange > changes
One outcome per input feature.
Definition constraintsimplifier.h:195
QString error
English reason when ok is false without cancellation; otherwise empty.
Definition constraintsimplifier.h:193
quint64 workUsed
Work units consumed, including shared-edge indexing.
Definition constraintsimplifier.h:204
Outcome for one input feature; ConstraintSimplificationResult::changes is parallel to the input.
Definition constraintsimplifier.h:137
bool rolledBack
A simplification was reverted: the ring area limits failed or the ring area changed sign or vanished,...
Definition constraintsimplifier.h:160
qsizetype rejectedShortcuts
Candidate shortcuts refused by a deviation or topology check; each refusal keeps one more vertex and ...
Definition constraintsimplifier.h:145
double areaChange
Rings only: |output area - input area| in squared XY units.
Definition constraintsimplifier.h:152
QVector< int > sourceVertices
Output-to-input vertex indices, increasing; a repeated closing vertex maps to the last.
Definition constraintsimplifier.h:163
double maxZDeviation
Largest elevation error of a removed vertex against its accepted shortcut.
Definition constraintsimplifier.h:152
QString id
Copy of SimplificationFeature::id.
Definition constraintsimplifier.h:138
double maxDeviation
Largest XY distance of a removed vertex from its accepted shortcut.
Definition constraintsimplifier.h:152
bool budgetRetained
The work budget, the workspace limit or cancellation stopped the pass, so the original geometry was k...
Definition constraintsimplifier.h:160
qsizetype removed
Vertices removed (input minus output xy count); 0 when the feature is unchanged.
Definition constraintsimplifier.h:145
One source constraint, an open polyline or a ring, given to simplifyConstraints().
Definition constraintsimplifier.h:104
QString label
Display label; makeConstraintPreview() falls back to id when it is empty.
Definition constraintsimplifier.h:130
QVector< double > z
Elevations parallel to xy; a repeated closing vertex must repeat its elevation.
Definition constraintsimplifier.h:108
ConstraintSimplificationPolicy policy
Limits for this feature; validated before use.
Definition constraintsimplifier.h:112
bool closed
Treat the feature as a ring even without a repeated closing vertex.
Definition constraintsimplifier.h:111
Role
Meaning of the feature for the delivered-mesh audit; ignored by the simplifier.
Definition constraintsimplifier.h:126
@ Line
Ordinary constraint path.
Definition constraintsimplifier.h:126
@ Protected
Protected outline, such as a region or fixed-patch boundary; the mesh audit treats it like Line,...
Definition constraintsimplifier.h:126
@ Hole
Hole ring; the mesh audit requires its cells on the outer side.
Definition constraintsimplifier.h:126
@ Domain
Domain outer ring; the mesh audit requires its cells on the inner side.
Definition constraintsimplifier.h:126
QVector< QPointF > xy
Vertices in the common planar frame; all must be finite.
Definition constraintsimplifier.h:106
bool requiredInMesh
False makes the delivered-mesh audit skip it.
Definition constraintsimplifier.h:128
QString id
Caller identifier, copied to SimplificationChange::id and error prefixes.
Definition constraintsimplifier.h:105
enum mesh::SimplificationFeature::Role role
Feature role; Role::Line by default.
QVector< bool > fixed
Per-vertex flags parallel to xy; a flagged vertex is never removed.
Definition constraintsimplifier.h:110
int marker
Boundary marker; when nonzero, the mesh audit matches only this marker.
Definition constraintsimplifier.h:127