Manifold 3.0
Robust geometry
Loading...
Searching...
No Matches
ExecutionContext Class Reference

Observe and control a long-running Manifold evaluation. More...

#include <common.h>

Public Member Functions

 ExecutionContext (const ExecutionContext &)
 ExecutionContext (ExecutionContext &&) noexcept
ExecutionContext & operator= (const ExecutionContext &)
ExecutionContext & operator= (ExecutionContext &&) noexcept
void Cancel ()
 Request cancellation. Can be called from any thread. Idempotent.
bool Cancelled () const
 Has cancellation been requested?
double Progress () const

Public Attributes

std::shared_ptr< Impl > impl_

Detailed Description

Observe and control a long-running Manifold evaluation.

Attach to a Manifold via Manifold::WithContext(ctx); the next eager op invoked on the result (Status, Refine / RefineToLength / RefineToTolerance, Hull, MinkowskiSum / MinkowskiDifference) snapshots the ctx and reports progress and observes cancellation through it. Safe to read/write from any thread.

Copyable and movable: copies share the same underlying state via a shared_ptr, so one thread can evaluate while another holds a copy and observes Progress() or calls Cancel(). Use a separate context per evaluation; passing the same context (or a copy of it) to two concurrent eager ops produces meaningless progress values because both calls reset and mutate the same counters.

Cancellation is permanent for a Manifold: once requested and detected, the Manifold's status becomes Error::Cancelled and stays Cancelled. To retry, construct a new Manifold. A context, however, is reusable: each evaluation through it resets the progress counters, but it does NOT clear the cancel flag – once Cancel() has been called on a context, every subsequent evaluation with that context (or any copy of it) will short-circuit to Error::Cancelled. Construct a fresh context to make a new evaluation cancellable independently.

Cancellation granularity varies by op: Boolean trees check per sub-boolean (so a single very large boolean may run to completion before the next check); Hull checks at the boundaries of its main phases (post-buildMesh and post-SortGeometry); Minkowski checks per face of the first input and per internal BatchBoolean batch.

Example: cancel a long-running BatchBoolean from an observer thread.

ExecutionContext ctx;
Manifold big = Manifold::BatchBoolean(items, OpType::Add).WithContext(ctx);
std::thread eval([&] {
if (big.Status() == Manifold::Error::Cancelled) {
// evaluation was cancelled
}
});
// ...later, from the UI thread:
ctx.Cancel();
eval.join();
void Cancel()
Request cancellation. Can be called from any thread. Idempotent.
This library's internal representation of an oriented, 2-manifold, triangle mesh - a simple boundary-...
Definition manifold.h:67
Manifold WithContext(const ExecutionContext &ctx) const
Definition manifold.cpp:165
static Manifold BatchBoolean(const std::vector< Manifold > &manifolds, OpType op)
Definition manifold.cpp:889
Error Status() const
Definition manifold.cpp:296

Example: cancel a Minkowski sum mid-evaluation.

ExecutionContext ctx;
std::thread eval([&] {
if (a.WithContext(ctx).MinkowskiSum(b).Status() ==
Manifold::Error::Cancelled) {
// evaluation was cancelled
}
});
ctx.Cancel();
eval.join();

Member Function Documentation

◆ Progress()

double Progress ( ) const

Normalized progress in [0, 1]. Monotonically increases during evaluation. Returns 1.0 when no work has been scheduled (interpreted as trivially complete – e.g. a single-leaf manifold has nothing to evaluate, and Progress() called before any Status(ctx) reflects the same "no pending work" state).