ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
stages.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7// Database-level pipeline stage execution (#265, Phase 1).
8//
9// The algorithms in segmentation/ and reconstruction/ are pure functions over
10// PCL clouds; the "load the named clouds out of a ProjectDB, run the algorithm,
11// write the results back, record it in pipeline_log" wrapper used to live only
12// inside apps/rux/src/create/*.cpp. This header lifts that wrapper DOWN into
13// the library so both `rux create <stage>` and the GUI/daemon job runners drive
14// the exact same code path (issue #265: "shared logic goes DOWN into the
15// library, not sideways between apps").
16//
17// Layering: this is the `pipeline` module, which sits ABOVE the Layer-3 peers
18// (segmentation / reconstruction / slam / io) — it is the one place allowed to
19// link several of them at once. See docs/STANDARDS.md §1.
20
21#include <atomic>
22#include <cstdint>
23#include <filesystem>
24#include <functional>
25#include <optional>
26#include <string>
27#include <string_view>
28#include <vector>
29
30namespace reusex {
31class ProjectDB;
32}
33
34namespace reusex::pipeline {
35
48
50std::string_view to_string(JobStage stage);
51
59std::string_view pipeline_log_name(JobStage stage);
60
62std::optional<JobStage> parse_job_stage(std::string_view name);
63
65std::vector<std::string> job_stage_names();
66
70
75 std::string kind;
80 std::string name;
84 int64_t count = -1;
85};
86
89 bool ok = false;
90 bool cancelled = false;
96 bool invalid_input = false;
97 std::string message;
101 std::vector<StageArtifact> outputs;
102
103 static StageResult success(std::string message = {});
104 static StageResult success(std::string message,
105 std::vector<StageArtifact> outputs);
106 static StageResult failure(std::string message);
107 static StageResult invalid(std::string message);
108 static StageResult cancel(std::string message = "cancelled");
109};
110
114 std::filesystem::path project;
120 std::string parameters;
122 const std::atomic_bool *cancel_token = nullptr;
126 std::string job_id;
127
129 bool is_cancelled() const noexcept;
130};
131
138
141
144using StageExecutor = std::function<StageResult(const StageContext &)>;
145
148
149} // namespace reusex::pipeline
std::vector< std::string > job_stage_names()
Every name accepted by parse_job_stage(), in pipeline order.
std::optional< JobStage > parse_job_stage(std::string_view name)
Parse a canonical stage name. Returns nullopt for an unknown name.
std::string_view pipeline_log_name(JobStage stage)
The name this stage writes into pipeline_log.stage.
std::string_view to_string(JobStatus status)
Canonical lower-case status name used on the wire.
JobStage
A pipeline stage that can be executed as a job.
Definition stages.hpp:42
@ clouds
back-project sensor frames into "cloud" + "normals"
Definition stages.hpp:43
@ instances
split semantic labels into spatial instances
Definition stages.hpp:46
@ planes
detect planar surfaces -> "planes"/"plane_*"
Definition stages.hpp:44
@ rooms
partition planes into rooms -> "rooms"
Definition stages.hpp:45
StageExecutor default_stage_executor()
The executor that actually runs the pipeline (a thin wrap of run_stage).
std::function< StageResult(const StageContext &)> StageExecutor
Stage execution strategy.
Definition stages.hpp:144
bool stage_supports_cancellation(JobStage stage)
True when the stage threads the cancel token into its inner loop, i.e.
StageResult run_stage(ProjectDB &db, const StageContext &ctx)
Run a stage against an already-open, writable ProjectDB.
One artifact a stage wrote, so a client can refresh exactly what changed instead of re-fetching every...
Definition stages.hpp:73
int64_t count
Points/rows written; -1 when not meaningful, or when the stage does not have the number in hand and c...
Definition stages.hpp:84
std::string name
Stored name, e.g.
Definition stages.hpp:80
std::string kind
"cloud" | "mesh" | "table".
Definition stages.hpp:75
Everything a stage execution needs, independent of any HTTP/CLI front end.
Definition stages.hpp:112
bool is_cancelled() const noexcept
True when a cancel token is present and set.
JobStage stage
Which stage to run.
Definition stages.hpp:116
const std::atomic_bool * cancel_token
Cooperative cancellation flag, owned by the caller. May be null.
Definition stages.hpp:122
std::filesystem::path project
Path to the .rux project the stage reads and writes.
Definition stages.hpp:114
std::string parameters
Stage parameters as a JSON object (empty string = all defaults).
Definition stages.hpp:120
std::string job_id
Identifier of the job driving this run, or empty for a direct call.
Definition stages.hpp:126
Outcome of one stage execution.
Definition stages.hpp:88
std::string message
Human-readable summary or failure reason.
Definition stages.hpp:97
static StageResult success(std::string message={})
std::vector< StageArtifact > outputs
What this run actually wrote.
Definition stages.hpp:101
bool cancelled
The stage stopped early on a cancel request.
Definition stages.hpp:90
static StageResult cancel(std::string message="cancelled")
static StageResult failure(std::string message)
bool invalid_input
The request was refused before/without doing the work because an input or a parameter was invalid,...
Definition stages.hpp:96
bool ok
The stage completed and wrote its outputs.
Definition stages.hpp:89
static StageResult success(std::string message, std::vector< StageArtifact > outputs)
static StageResult invalid(std::string message)