IDS peak AFL v2.0.0
Loading...
Searching...
No Matches
peak_afl_search_algorithm.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
15
17
18#include <memory>
19
20namespace peak
21{
22namespace pipeline
23{
24namespace modules
25{
26namespace autofeature
27{
39{
47 Auto PEAK_AFL_DEPRECATED_ENUM_ATTR,
56};
57
71{
72 // clang-format off
73 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
74 switch (algorithm)
75 {
77 return "Auto";
79 return "GoldenRatio";
81 return "HillClimbing";
83 return "GlobalSearch";
85 return "FullScan";
86 }
87 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
88 // clang-format on
89
91 "The given focus search algorithm is unknown!", PEAK_AFL_STATUS_INVALID_PARAMETER);
92}
93
112inline std::ostream& operator<<(std::ostream& os, FocusSearchAlgorithm algorithm)
113{
114 return os << ToString(algorithm);
115}
116
117namespace features
118{
119namespace detail
120{
121PEAK_COMMON_NO_DISCARD inline FocusSearchAlgorithm ToFocusSearchAlgorithm(const std::string& name)
122{
123 if (name == "Auto")
124 {
125 // clang-format off
126 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
128 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
129 // clang-format on
130 }
131 if (name == "GoldenRatio")
132 {
134 }
135 if (name == "HillClimbing")
136 {
138 }
139 if (name == "GlobalSearch")
140 {
142 }
143 if (name == "FullScan")
144 {
146 }
147
148 throw peak::afl::error::InternalErrorException("Invalid focus search algorithm!", PEAK_AFL_STATUS_ERROR);
149}
150
152{
153 // clang-format off
154 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
155 switch (algorithm)
156 {
167 }
168 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
169 // clang-format on
170
171 throw peak::afl::error::InternalErrorException("Invalid focus search algorithm!", PEAK_AFL_STATUS_ERROR);
172}
173
175{
176 // clang-format off
177 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
178 switch (algorithm)
179 {
190 }
191 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
192 // clang-format on
193
194 throw peak::afl::error::InternalErrorException("Invalid focus search algorithm!", PEAK_AFL_STATUS_ERROR);
195}
196} // namespace detail
197
227class SearchAlgorithm : public IListFeature<FocusSearchAlgorithm>
228{
229public:
242 explicit SearchAlgorithm(std::shared_ptr<peak::afl::Controller> controller)
243 : m_controller{ std::move(controller) }
244 {}
245
266 void Set(const FocusSearchAlgorithm& value) override
267 {
268 m_controller->SetAlgorithm(detail::ToCType(value));
269 }
270
289 {
290 return detail::ToFocusSearchAlgorithm(m_controller->GetAlgorithm());
291 }
292
311 PEAK_COMMON_NO_DISCARD std::vector<FocusSearchAlgorithm> GetList() const override
312 {
313 const auto cAlgorithms = m_controller->GetAlgorithmList();
314
315 std::vector<FocusSearchAlgorithm> algorithms;
316 algorithms.reserve(cAlgorithms.size());
317
318 std::transform(std::cbegin(cAlgorithms), std::cend(cAlgorithms), std::back_inserter(algorithms),
319 [](const auto& value) { return detail::ToFocusSearchAlgorithm(value); });
320 return algorithms;
321 }
322
338 {
339 archive.SetString("SearchAlgorithm", ToString(Get()));
340 }
341
358 {
359 Set(detail::ToFocusSearchAlgorithm(archive.GetString("SearchAlgorithm")));
360 }
361
362private:
370 std::shared_ptr<peak::afl::Controller> m_controller;
371};
372} // namespace features
373} // namespace autofeature
374} // namespace modules
375} // namespace pipeline
376} // namespace peak
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:391
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual std::string GetString(const std::string &key) const =0
Retrieves a string value by key.
virtual void SetString(const std::string &key, const std::string &value)=0
Stores a UTF-8 string.
Interface for features that have a list of valid values.
Definition peak_afl_ifeature.hpp:169
SearchAlgorithm(std::shared_ptr< peak::afl::Controller > controller)
Constructs a SearchAlgorithm feature with the specified controller.
Definition peak_afl_search_algorithm.hpp:242
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current search algorithm to an archive.
Definition peak_afl_search_algorithm.hpp:337
FocusSearchAlgorithm Get() const override
Gets the current focus search algorithm.
Definition peak_afl_search_algorithm.hpp:288
std::vector< FocusSearchAlgorithm > GetList() const override
Gets the list of supported focus search algorithms.
Definition peak_afl_search_algorithm.hpp:311
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the search algorithm from an archive.
Definition peak_afl_search_algorithm.hpp:357
void Set(const FocusSearchAlgorithm &value) override
Sets the focus search algorithm.
Definition peak_afl_search_algorithm.hpp:266
peak_afl_controller_algorithm
Focus search algorithms.
Definition peak_afl.h:695
@ PEAK_AFL_CONTROLLER_ALGORITHM_GOLDEN_RATIO_SEARCH
Golden ratio search algorithm.
Definition peak_afl.h:716
@ PEAK_AFL_CONTROLLER_ALGORITHM_HILL_CLIMBING_SEARCH
Hill climbing search algorithm.
Definition peak_afl.h:729
@ PEAK_AFL_CONTROLLER_ALGORITHM_FULL_SCAN
Full range scan algorithm.
Definition peak_afl.h:757
@ PEAK_AFL_CONTROLLER_ALGORITHM_AUTO
Automatic algorithm selection.
Definition peak_afl.h:703
@ PEAK_AFL_CONTROLLER_ALGORITHM_GLOBAL_SEARCH
Global search algorithm.
Definition peak_afl.h:743
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:419
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:399
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:78
FocusSearchAlgorithm
Focus search algorithm enumeration.
Definition peak_afl_search_algorithm.hpp:39
@ Auto
Automatic algorithm selection - default algorithm.
Definition peak_afl_search_algorithm.hpp:47
@ GlobalSearch
Global search - comprehensive but slower search.
Definition peak_afl_search_algorithm.hpp:53
@ HillClimbing
Hill climbing search - good for local optimization.
Definition peak_afl_search_algorithm.hpp:51
@ GoldenRatio
Golden ratio search - efficient for unimodal focus curves.
Definition peak_afl_search_algorithm.hpp:49
@ FullScan
Full scan - scans entire focus range for maximum accuracy.
Definition peak_afl_search_algorithm.hpp:55
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:39
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:37