iVS3D v2.0.9
Loading...
Searching...
No Matches
ModelConfig.h
Go to the documentation of this file.
1#pragma once
2
10#include <QColor>
11#include <QDir>
12#include <QMap>
13#include <QMetaType>
14#include <QString>
15#include <QVector>
16#include <cstdint>
17#include <string>
18#include <vector>
19
20#include <tl/expected.hpp>
21
35namespace MCFG {
36
53public:
57 enum class ErrorCode {
58 ConfigFileNotFound = 0,
59 ModelFileNotFound = 1,
60 IoError = 2,
61 ConfigParseError = 3,
62 DuplicateClassIds = 4,
63 };
64
68 struct Error {
72 QString message;
73 };
74
76 using ClassId = uint32_t;
77
81 struct ClassInfo {
85 QString name;
87 QColor color;
89 bool selected = false;
90 };
91
102 static tl::expected<ModelConfig, ModelConfig::Error> loadFromFile(const QString& jsonPath);
103
105 const std::vector<float>& getMean() const noexcept;
106
108 const std::vector<float>& getStd() const noexcept;
109
111 const std::string& getModelPath() const noexcept;
112
114 uint getInputAlignment() const noexcept;
115
117 bool getApplyMeanStd() const noexcept;
118
120 bool getNormalizeTo01() const noexcept;
121
123 const std::vector<ClassInfo>& getClasses() const noexcept;
124
130 const ClassInfo* getClassById(ClassId id) const noexcept;
131
138 bool setClassSelected(ClassId id, bool selected) noexcept;
139
144 void setApplyMeanStd(bool apply) noexcept;
145
150 void setNormalizeTo01(bool normalize) noexcept;
151
156 void setInputAlignment(uint alignment) noexcept;
157
158
159private:
160 // Private members - only accessible via getters
161 std::vector<float> mean_;
162 std::vector<float> std_;
163 std::vector<ClassInfo> classes_;
164 std::string modelPath_;
165 uint inputAlignment_ = 1;
166 bool applyMeanStd_ = true; // Whether to apply mean/std normalization
167 bool normalizeTo01_ = true; // Whether to normalize input to [0,1]
168};
169
170} // namespace MCFG
171
172// Register custom types for use in signals/slots
173Q_DECLARE_METATYPE(MCFG::ModelConfig::ClassInfo)
174Q_DECLARE_METATYPE(QVector<MCFG::ModelConfig::ClassInfo>)
Stores one parsed model configuration and runtime class-selection state.
Definition ModelConfig.h:52
ErrorCode
Error codes returned by loadFromFile().
Definition ModelConfig.h:57
const std::vector< float > & getMean() const noexcept
Get the per-channel mean vector from config.
Definition ModelConfig.cpp:131
bool getApplyMeanStd() const noexcept
Check whether mean/std normalization is enabled.
Definition ModelConfig.cpp:170
bool getNormalizeTo01() const noexcept
Check whether [0,255] -> [0,1] normalization is enabled.
Definition ModelConfig.cpp:174
const std::string & getModelPath() const noexcept
Get the resolved absolute path to the ONNX model file.
Definition ModelConfig.cpp:139
const std::vector< ClassInfo > & getClasses() const noexcept
Get all configured classes.
Definition ModelConfig.cpp:147
const ClassInfo * getClassById(ClassId id) const noexcept
Get class info by ID.
Definition ModelConfig.cpp:151
void setInputAlignment(uint alignment) noexcept
Set the input alignment value.
Definition ModelConfig.cpp:186
static tl::expected< ModelConfig, ModelConfig::Error > loadFromFile(const QString &jsonPath)
Load a model configuration from a JSON file Performs validation:
Definition ModelConfig.cpp:12
void setNormalizeTo01(bool normalize) noexcept
Set whether to normalize input to [0,1].
Definition ModelConfig.cpp:182
uint32_t ClassId
Unsigned integer type used for class identifiers.
Definition ModelConfig.h:76
bool setClassSelected(ClassId id, bool selected) noexcept
Set the selected state of a class.
Definition ModelConfig.cpp:160
void setApplyMeanStd(bool apply) noexcept
Set whether to apply mean/std normalization.
Definition ModelConfig.cpp:178
uint getInputAlignment() const noexcept
Get input alignment requirement (multiple-of value for H/W).
Definition ModelConfig.cpp:143
const std::vector< float > & getStd() const noexcept
Get the per-channel standard deviation vector from config.
Definition ModelConfig.cpp:135
Namespace containing model-configuration components used by iVS3D plugins.
Definition ModelConfig.h:35
Description of one output class.
Definition ModelConfig.h:81
QString name
Definition ModelConfig.h:85
ClassId id
Definition ModelConfig.h:83
QColor color
Definition ModelConfig.h:87
Error object returned on failed config loading.
Definition ModelConfig.h:68
ErrorCode code
Definition ModelConfig.h:70