IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_afl_search_algorithm.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
11
13
14#include <memory>
15
16namespace peak
17{
18namespace pipeline
19{
20namespace modules
21{
22namespace autofeature
23{
35{
43 Auto PEAK_AFL_DEPRECATED_ENUM_ATTR,
52};
53
66PEAK_COMMON_NO_DISCARD inline std::string ToString(FocusSearchAlgorithm algorithm)
67{
68 // clang-format off
69 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
70 switch (algorithm)
71 {
73 return "Auto";
75 return "GoldenRatio";
77 return "HillClimbing";
79 return "GlobalSearch";
81 return "FullScan";
82 }
83 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
84 // clang-format on
85
87 "The given focus search algorithm is unknown!", PEAK_AFL_STATUS_INVALID_PARAMETER);
88}
89
108inline std::ostream& operator<<(std::ostream& os, FocusSearchAlgorithm algorithm)
109{
110 return os << ToString(algorithm);
111}
112
113namespace features
114{
115namespace detail
116{
117PEAK_COMMON_NO_DISCARD inline FocusSearchAlgorithm ToFocusSearchAlgorithm(const std::string& name)
118{
119 if (name == "Auto")
120 {
121 // clang-format off
122 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
124 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
125 // clang-format on
126 }
127 if (name == "GoldenRatio")
128 {
130 }
131 if (name == "HillClimbing")
132 {
134 }
135 if (name == "GlobalSearch")
136 {
138 }
139 if (name == "FullScan")
140 {
142 }
143
144 throw peak::afl::error::InternalErrorException("Invalid focus search algorithm!", PEAK_AFL_STATUS_ERROR);
145}
146
147PEAK_COMMON_NO_DISCARD inline peak_afl_controller_algorithm ToCType(FocusSearchAlgorithm algorithm)
148{
149 // clang-format off
150 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
151 switch (algorithm)
152 {
163 }
164 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
165 // clang-format on
166
167 throw peak::afl::error::InternalErrorException("Invalid focus search algorithm!", PEAK_AFL_STATUS_ERROR);
168}
169
170PEAK_COMMON_NO_DISCARD inline FocusSearchAlgorithm ToFocusSearchAlgorithm(peak_afl_controller_algorithm algorithm)
171{
172 // clang-format off
173 PEAK_AFL_BEGIN_DISABLE_DEPRECATED_WARNINGS
174 switch (algorithm)
175 {
186 }
187 PEAK_AFL_END_DISABLE_DEPRECATED_WARNINGS
188 // clang-format on
189
190 throw peak::afl::error::InternalErrorException("Invalid focus search algorithm!", PEAK_AFL_STATUS_ERROR);
191}
192} // namespace detail
193
223class SearchAlgorithm : public IListFeature<FocusSearchAlgorithm>
224{
225public:
238 explicit SearchAlgorithm(std::shared_ptr<peak::afl::Controller> controller)
239 : m_controller{ std::move(controller) }
240 {}
241
262 void Set(const FocusSearchAlgorithm& value) override
263 {
264 m_controller->SetAlgorithm(detail::ToCType(value));
265 }
266
284 PEAK_COMMON_NO_DISCARD FocusSearchAlgorithm Get() const override
285 {
286 return detail::ToFocusSearchAlgorithm(m_controller->GetAlgorithm());
287 }
288
307 PEAK_COMMON_NO_DISCARD std::vector<FocusSearchAlgorithm> GetList() const override
308 {
309 const auto cAlgorithms = m_controller->GetAlgorithmList();
310
311 std::vector<FocusSearchAlgorithm> algorithms;
312 algorithms.reserve(cAlgorithms.size());
313
314 std::transform(std::cbegin(cAlgorithms), std::cend(cAlgorithms), std::back_inserter(algorithms),
315 [](const auto& value) { return detail::ToFocusSearchAlgorithm(value); });
316 return algorithms;
317 }
318
334 {
335 archive.SetString("SearchAlgorithm", ToString(Get()));
336 }
337
354 {
355 Set(detail::ToFocusSearchAlgorithm(archive.GetString("SearchAlgorithm")));
356 }
357
358private:
366 std::shared_ptr<peak::afl::Controller> m_controller;
367};
368} // namespace features
369} // namespace autofeature
370} // namespace modules
371} // namespace pipeline
372} // namespace peak
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:436
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:54
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:165
SearchAlgorithm(std::shared_ptr< peak::afl::Controller > controller)
Constructs a SearchAlgorithm feature with the specified controller.
Definition peak_afl_search_algorithm.hpp:238
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current search algorithm to an archive.
Definition peak_afl_search_algorithm.hpp:333
FocusSearchAlgorithm Get() const override
Gets the current focus search algorithm.
Definition peak_afl_search_algorithm.hpp:284
std::vector< FocusSearchAlgorithm > GetList() const override
Gets the list of supported focus search algorithms.
Definition peak_afl_search_algorithm.hpp:307
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the search algorithm from an archive.
Definition peak_afl_search_algorithm.hpp:353
void Set(const FocusSearchAlgorithm &value) override
Sets the focus search algorithm.
Definition peak_afl_search_algorithm.hpp:262
peak_afl_controller_algorithm
Focus search algorithms.
Definition peak_afl.h:692
@ PEAK_AFL_CONTROLLER_ALGORITHM_GOLDEN_RATIO_SEARCH
Golden ratio search algorithm.
Definition peak_afl.h:713
@ PEAK_AFL_CONTROLLER_ALGORITHM_HILL_CLIMBING_SEARCH
Hill climbing search algorithm.
Definition peak_afl.h:726
@ PEAK_AFL_CONTROLLER_ALGORITHM_FULL_SCAN
Full range scan algorithm.
Definition peak_afl.h:754
@ PEAK_AFL_CONTROLLER_ALGORITHM_AUTO
Automatic algorithm selection.
Definition peak_afl.h:700
@ PEAK_AFL_CONTROLLER_ALGORITHM_GLOBAL_SEARCH
Global search algorithm.
Definition peak_afl.h:740
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:416
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:396
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:74
FocusSearchAlgorithm
Focus search algorithm enumeration.
Definition peak_afl_search_algorithm.hpp:35
@ Auto
Automatic algorithm selection - default algorithm.
Definition peak_afl_search_algorithm.hpp:43
@ GlobalSearch
Global search - comprehensive but slower search.
Definition peak_afl_search_algorithm.hpp:49
@ HillClimbing
Hill climbing search - good for local optimization.
Definition peak_afl_search_algorithm.hpp:47
@ GoldenRatio
Golden ratio search - efficient for unimodal focus curves.
Definition peak_afl_search_algorithm.hpp:45
@ FullScan
Full scan - scans entire focus range for maximum accuracy.
Definition peak_afl_search_algorithm.hpp:51
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:35
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:33