ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
sam3_assets.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#include "reusex/vision/sam3/EngineBuildProfiles.hpp"
8
9#include <atomic>
10#include <filesystem>
11#include <functional>
12#include <stdexcept>
13#include <string>
14#include <vector>
15
16namespace reusex::vision::sam3 {
17
27
28const char *to_string(PrepState state);
29
31class Sam3PrepCancelled : public std::runtime_error {
32 public:
33 using std::runtime_error::runtime_error;
34};
35
39 float fraction = 0.0f;
40 std::string message;
45 std::vector<std::string> update_engines;
46};
47
48using ProgressCallback = std::function<void(const PrepProgress &)>;
49
54 std::filesystem::path models_dir;
55
58 std::string manifest_url;
59
62 bool allow_download = true;
63
66 bool use_cuda = true;
67
73 const std::atomic<bool> *cancel = nullptr;
74};
75
80const std::vector<std::string> &required_engines();
81
86std::filesystem::path
87resolve_models_dir(const std::filesystem::path &explicit_dir = {});
88
92std::filesystem::path sam3_onnx_dir(const Sam3AssetOptions &opts);
93
96std::filesystem::path sam3_engine_dir(const Sam3AssetOptions &opts);
97
104std::vector<std::string>
105missing_onnx_files(const std::filesystem::path &onnx_dir);
106
113std::vector<std::string>
114missing_engine_files(const std::filesystem::path &onnx_dir,
115 const std::filesystem::path &engine_dir);
116
123load_engine_build_profiles(const std::filesystem::path &onnx_dir);
124
131std::vector<std::string> stale_engines(const std::filesystem::path &onnx_dir,
132 const std::filesystem::path &engine_dir);
133
138std::vector<std::string>
139fallback_engines(const std::filesystem::path &engine_dir);
140
150std::vector<std::string>
151fallback_engines_to_retry(const std::filesystem::path &onnx_dir,
152 const std::filesystem::path &engine_dir);
153
161
179std::filesystem::path prepare_sam3_model(const Sam3AssetOptions &opts,
180 const ProgressCallback &cb = {});
181
182} // namespace reusex::vision::sam3
Thrown by prepare_sam3_model() when Sam3AssetOptions::cancel was raised.
std::filesystem::path prepare_sam3_model(const Sam3AssetOptions &opts, const ProgressCallback &cb={})
Ensure the managed SAM3 model is ready and return a directory that vision::create_model_from_path can...
std::vector< std::string > fallback_engines_to_retry(const std::filesystem::path &onnx_dir, const std::filesystem::path &engine_dir)
The fallback_engines() whose recipe profile is worth building again: the ONNX it failed against has c...
std::function< void(const PrepProgress &)> ProgressCallback
std::vector< std::string > stale_engines(const std::filesystem::path &onnx_dir, const std::filesystem::path &engine_dir)
Built engines (names, without .engine) whose recipe differs from the one load_engine_build_profiles()...
std::filesystem::path sam3_engine_dir(const Sam3AssetOptions &opts)
The device-specific engine cache directory for the managed SAM3 model (keyed by GPU + TensorRT versio...
PrepProgress sam3_status(const Sam3AssetOptions &opts)
Non-blocking status probe: is the managed model already loadable, and in what state?
std::vector< std::string > missing_engine_files(const std::filesystem::path &onnx_dir, const std::filesystem::path &engine_dir)
Files the engine directory still lacks before it is loadable (empty ⟹ ready): the required_engines(),...
std::filesystem::path resolve_models_dir(const std::filesystem::path &explicit_dir={})
Resolve the base models directory: explicit models_dir > $REUSEX_MODELS_DIR > $XDG_CACHE_HOME/reusex/...
std::filesystem::path sam3_onnx_dir(const Sam3AssetOptions &opts)
The directory holding the portable ONNX + tokenizer.json + tracker-meta.json.
EngineBuildProfiles load_engine_build_profiles(const std::filesystem::path &onnx_dir)
The engine-build recipe for an ONNX dir: its own engine-build.json when present and at least as new (...
std::vector< std::string > missing_onnx_files(const std::filesystem::path &onnx_dir)
Files the ONNX directory still lacks before it counts as a complete bundle (empty ⟹ complete).
const char * to_string(PrepState state)
PrepState
Lifecycle state of the managed SAM3 model on this device.
@ building
compiling GPU-specific TensorRT engines from ONNX
@ not_built
ONNX present, device engines not built, no build running.
@ downloading
fetching the portable ONNX bundle
@ ready
engines (or ONNX, for CPU) present and loadable
@ absent
the (complete) ONNX bundle is not on disk yet
std::vector< std::string > fallback_engines(const std::filesystem::path &engine_dir)
Engines (names, without .engine) the engine directory's stamp records as built text-only because thei...
const std::vector< std::string > & required_engines()
The detector engines every SAM3 model needs (vision encoder, text encoder, geometry encoder,...
void error(fmt::format_string< Args... > format, Args &&...args)
Definition logging.hpp:100
The full set of per-engine build recipes.
Best-effort progress report emitted during preparation.
float fraction
0..1 within the current phase (best-effort)
std::vector< std::string > update_engines
Only from sam3_status() in state not_built: when the engines are all there and the only gap is engine...
std::string message
human-readable detail
Controls where the managed SAM3 model lives and how it is fetched.
bool allow_download
If true, missing ONNX may be downloaded.
std::string manifest_url
URL of the release manifest (JSON listing the ONNX bundle files + sha256).
const std::atomic< bool > * cancel
Optional cooperative-cancellation flag (not owned).
std::filesystem::path models_dir
Base models directory.
bool use_cuda
Build engines for CUDA (true) or leave the ONNX in place for the CPU/ONNX runtime backend (false).