ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
IMLBackend.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6#include "reusex/vision/IDataset.hpp"
7#include "reusex/vision/IModel.hpp"
8#include "reusex/vision/IVideoModel.hpp"
9
10#include <filesystem>
11#include <stdexcept>
12
13namespace reusex::vision {
14
15enum class Model { yolo, sam3, sam3p1 };
16
18 public:
19 /* The destructor is declared as virtual to ensure that the correct destructor
20 * is called when an object of a derived class is deleted through a pointer to
21 * the base class. This is important for proper resource management and to
22 * avoid memory leaks. By declaring the destructor as virtual, we allow for
23 * polymorphic behavior, enabling the correct cleanup of resources allocated
24 * by derived classes when they are destroyed through a base class pointer. */
25 virtual ~IMLBackend() = default;
26
27 /* Creates a model of the given type from the specified path.
28 *
29 * @param type The type of model to create, specified as an enum value.
30 * @param modelPath The filesystem path to the model file.
31 * @param use_cuda Whether to use CUDA for inference (defaults to false).
32 * @return A unique pointer to the created IModel object.
33 */
34 virtual std::unique_ptr<IModel>
35 create_model(const Model type, const std::filesystem::path &modelPath,
36 bool use_cuda = false) = 0;
37
38 /* Creates a stateful video model (IVideoModel) of the given type. Unlike
39 * create_model, this returns a temporally-stateful tracker that MUST be
40 * driven in frame order (see IVideoModel). The default implementation throws,
41 * so backends without a video path compile unchanged; backends that support
42 * it (e.g. TensorRT/SAM 3.1) override this.
43 *
44 * @param type The type of video model to create.
45 * @param modelPath The filesystem path to the model directory.
46 * @param use_cuda Whether to use CUDA for inference (defaults to false).
47 * @return A unique pointer to the created IVideoModel object.
48 */
49 virtual std::unique_ptr<IVideoModel>
50 create_video_model(const Model type, const std::filesystem::path &modelPath,
51 bool use_cuda = false) {
52 (void)type;
53 (void)modelPath;
54 (void)use_cuda;
55 throw std::runtime_error("backend has no video model");
56 }
57
58 /* Creates a dataset from the specified path.
59 * @param datasetPath The filesystem path to the dataset.
60 * @return A unique pointer to the created IDataset object.
61 */
62 virtual std::unique_ptr<IDataset>
63 create_dataset(const std::filesystem::path &datasetPath) = 0;
64};
65} // namespace reusex::vision
virtual std::unique_ptr< IModel > create_model(const Model type, const std::filesystem::path &modelPath, bool use_cuda=false)=0
virtual ~IMLBackend()=default
virtual std::unique_ptr< IDataset > create_dataset(const std::filesystem::path &datasetPath)=0
virtual std::unique_ptr< IVideoModel > create_video_model(const Model type, const std::filesystem::path &modelPath, bool use_cuda=false)