IDS peak AFL v1.8.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{
28
52
66{
67 switch (algorithm)
68 {
70 return "Auto";
72 return "GoldenRatio";
74 return "HillClimbing";
76 return "GlobalSearch";
78 return "FullScan";
79 }
80
81 throw peak::common::InvalidParameterException("The given focus search algorithm is unknown!");
82}
83
102inline std::ostream& operator<<(std::ostream& os, FocusSearchAlgorithm algorithm)
103{
104 return os << ToString(algorithm);
105}
106
107namespace features
108{
109
110namespace detail
111{
112
113PEAK_COMMON_NO_DISCARD inline FocusSearchAlgorithm ToFocusSearchAlgorithm(const std::string& name)
114{
115 if (name == "Auto")
116 {
118 }
119 if (name == "GoldenRatio")
120 {
122 }
123 if (name == "HillClimbing")
124 {
126 }
127 if (name == "GlobalSearch")
128 {
130 }
131 if (name == "FullScan")
132 {
134 }
135
136 throw peak::common::InternalErrorException("Invalid focus search algorithm!");
137}
138
140{
141 switch (algorithm)
142 {
153 }
154
155 throw peak::common::InternalErrorException("Invalid focus search algorithm!");
156}
157
159{
160 switch (algorithm)
161 {
172 }
173
174 throw peak::common::InternalErrorException("Invalid focus search algorithm!");
175}
176
177} // namespace detail
178
208class SearchAlgorithm : public IListFeature<FocusSearchAlgorithm>
209{
210public:
223 explicit SearchAlgorithm(std::shared_ptr<peak::afl::Controller> controller)
224 : m_controller{ std::move(controller) }
225 {}
226
247 void Set(const FocusSearchAlgorithm& value) override
248 {
249 m_controller->SetAlgorithm(detail::ToCType(value));
250 }
251
270 {
271 return detail::ToFocusSearchAlgorithm(m_controller->GetAlgorithm());
272 }
273
292 PEAK_COMMON_NO_DISCARD std::vector<FocusSearchAlgorithm> GetList() const override
293 {
294 const auto cAlgorithms = m_controller->GetAlgorithmList();
295
296 std::vector<FocusSearchAlgorithm> algorithms;
297 algorithms.reserve(cAlgorithms.size());
298
299 std::transform(std::cbegin(cAlgorithms), std::cend(cAlgorithms), std::back_inserter(algorithms),
300 [](const auto& value) { return detail::ToFocusSearchAlgorithm(value); });
301 return algorithms;
302 }
303
319 {
320 archive.SetString("SearchAlgorithm", ToString(Get()));
321 }
322
339 {
340 Set(detail::ToFocusSearchAlgorithm(archive.GetString("SearchAlgorithm")));
341 }
342
343private:
351 std::shared_ptr<peak::afl::Controller> m_controller;
352};
353
354} // namespace features
355} // namespace autofeature
356} // namespace modules
357} // namespace pipeline
358} // namespace peak
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:50
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual PEAK_COMMON_NO_DISCARD 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:171
SearchAlgorithm(std::shared_ptr< peak::afl::Controller > controller)
Constructs a SearchAlgorithm feature with the specified controller.
Definition peak_afl_search_algorithm.hpp:223
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current search algorithm to an archive.
Definition peak_afl_search_algorithm.hpp:318
PEAK_COMMON_NO_DISCARD std::vector< FocusSearchAlgorithm > GetList() const override
Gets the list of supported focus search algorithms.
Definition peak_afl_search_algorithm.hpp:292
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the search algorithm from an archive.
Definition peak_afl_search_algorithm.hpp:338
void Set(const FocusSearchAlgorithm &value) override
Sets the focus search algorithm.
Definition peak_afl_search_algorithm.hpp:247
PEAK_COMMON_NO_DISCARD FocusSearchAlgorithm Get() const override
Gets the current focus search algorithm.
Definition peak_afl_search_algorithm.hpp:269
PEAK_COMMON_NO_DISCARD std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:79
FocusSearchAlgorithm
Focus search algorithm enumeration.
Definition peak_afl_search_algorithm.hpp:40
@ Auto
Automatic algorithm selection - default algorithm.
Definition peak_afl_search_algorithm.hpp:42
@ GlobalSearch
Global search - comprehensive but slower search.
Definition peak_afl_search_algorithm.hpp:48
@ HillClimbing
Hill climbing search - good for local optimization.
Definition peak_afl_search_algorithm.hpp:46
@ GoldenRatio
Golden ratio search - efficient for unimodal focus curves.
Definition peak_afl_search_algorithm.hpp:44
@ FullScan
Full scan - scans entire focus range for maximum accuracy.
Definition peak_afl_search_algorithm.hpp:50
peak_afl_controller_algorithm
Focus search algorithms.
Definition peak_afl.h:429
@ PEAK_AFL_CONTROLLER_ALGORITHM_GOLDEN_RATIO_SEARCH
Golden ratio search algorithm.
Definition peak_afl.h:449
@ PEAK_AFL_CONTROLLER_ALGORITHM_HILL_CLIMBING_SEARCH
Hill climbing search algorithm.
Definition peak_afl.h:462
@ PEAK_AFL_CONTROLLER_ALGORITHM_FULL_SCAN
Full range scan algorithm.
Definition peak_afl.h:490
@ PEAK_AFL_CONTROLLER_ALGORITHM_AUTO
Automatic algorithm selection.
Definition peak_afl.h:436
@ PEAK_AFL_CONTROLLER_ALGORITHM_GLOBAL_SEARCH
Global search algorithm.
Definition peak_afl.h:476
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
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