IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_afl_generic_auto_focus.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
16
18
19#include <peak/generic/peak_t_callback_manager.hpp>
20
21#include <memory>
22
23namespace peak
24{
25namespace pipeline
26{
27namespace modules
28{
29namespace autofeature
30{
31namespace detail
32{
33class GenericAutoFocus : public IController
34{
35public:
36 explicit GenericAutoFocus(peak::afl::Manager& manager)
37 : IController(manager)
38 , m_controller{ peak::afl::Controller::Create(PEAK_AFL_CONTROLLER_TYPE_AUTOFOCUS) }
39 , m_skipFrames{ std::make_unique<features::SkipFrames>(m_controller) }
40 , m_hysteresis{ std::make_unique<features::Hysteresis>(m_controller) }
41 , m_weightedRois{ std::make_unique<features::WeightedRois>(m_controller) }
42 , m_sharpnessAlgorithm{ std::make_unique<features::SharpnessAlgorithm>(m_controller) }
43 , m_searchAlgorithm{ std::make_unique<features::SearchAlgorithm>(m_controller) }
44 , m_focusLimit{ std::make_unique<features::FocusLimit>(m_controller) }
45 {
46 GetManager().AddController(m_controller);
47
48 m_controller->RegisterFinishedCallback([this]() { m_FinishedCallbackManager.TriggerCallbacks(); });
49 }
50
51 PEAK_COMMON_NO_DISCARD std::string GetName() const override
52 {
53 return "GenericAutoFocus";
54 }
55
56 void Serialize(peak::common::serialization::IArchive& archive) const override
57 {
58 for (const auto& feature : std::initializer_list<const peak::common::serialization::ISerializable*>{ m_skipFrames.get(),
59 m_hysteresis.get(), m_weightedRois.get(), m_sharpnessAlgorithm.get(), m_searchAlgorithm.get(), m_focusLimit.get() })
60 {
61 feature->Serialize(archive);
62 }
63
64 archive.SetString("Mode", ToString(GetMode()));
65 }
66
67 void Deserialize(const peak::common::serialization::IArchive& archive) override
68 {
69 for (const auto& feature : std::initializer_list<peak::common::serialization::ISerializable*>{ m_skipFrames.get(),
70 m_hysteresis.get(), m_weightedRois.get(), m_sharpnessAlgorithm.get(), m_searchAlgorithm.get(), m_focusLimit.get() })
71 {
72 feature->Deserialize(archive);
73 }
74
75 SetMode(detail::ToControllerMode(archive.GetString("Mode")));
76 }
77
78 void SetMode(ControllerMode mode) override
79 {
80 m_controller->SetMode(ToCType(mode));
81 }
82
83 PEAK_COMMON_NO_DISCARD ControllerMode GetMode() const override
84 {
85 return ToControllerMode(m_controller->GetMode());
86 }
87
88 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
89 {
90 return GetMode() != ControllerMode::Off;
91 }
92
93 void ResetToDefault() override
94 {
95 SetMode(ControllerMode::Off);
96 SkipFrames().Set(2);
97 SearchAlgorithm().Set(FocusSearchAlgorithm::GoldenRatio);
98 SharpnessAlgorithm().Set(FocusSharpnessAlgorithm::Tenengrad);
99
100 const auto focusLimit = m_controller->GetDefaultLimit();
101 FocusLimit().Set({ focusLimit.min, focusLimit.max });
102 Hysteresis().Set(8);
103
104 m_controller->SetROIPreset(PEAK_AFL_CONTROLLER_ROI_PRESET_CENTER);
105 }
106
107 PEAK_COMMON_NO_DISCARD features::SkipFrames& SkipFrames() const
108 {
109 return *m_skipFrames;
110 }
111
112 PEAK_COMMON_NO_DISCARD features::Hysteresis& Hysteresis() const
113 {
114 return *m_hysteresis;
115 }
116
117 PEAK_COMMON_NO_DISCARD features::WeightedRois& WeightedROIs() const
118 {
119 return *m_weightedRois;
120 }
121
122 PEAK_COMMON_NO_DISCARD features::SharpnessAlgorithm& SharpnessAlgorithm() const
123 {
124 return *m_sharpnessAlgorithm;
125 }
126
127 PEAK_COMMON_NO_DISCARD features::SearchAlgorithm& SearchAlgorithm() const
128 {
129 return *m_searchAlgorithm;
130 }
131
132 PEAK_COMMON_NO_DISCARD features::FocusLimit& FocusLimit() const
133 {
134 return *m_focusLimit;
135 }
136
137 PEAK_COMMON_NO_DISCARD ControllerType GetType() const override
138 {
140 }
141
142 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
143 {
144 return m_FinishedCallbackManager.RegisterCallback(callback);
145 }
146
147 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
148 {
149 m_FinishedCallbackManager.UnregisterCallback(callbackHandle);
150 }
151
152private:
153 std::shared_ptr<peak::afl::Controller> m_controller;
154 peak::core::TTriggerCallbackManager<IController::FinishedCallbackHandle, IController::FinishedCallback>
155 m_FinishedCallbackManager;
156 std::unique_ptr<features::SkipFrames> m_skipFrames{};
157 std::unique_ptr<features::Hysteresis> m_hysteresis{};
158 std::unique_ptr<features::WeightedRois> m_weightedRois{};
159 std::unique_ptr<features::SharpnessAlgorithm> m_sharpnessAlgorithm{};
160 std::unique_ptr<features::SearchAlgorithm> m_searchAlgorithm{};
161 std::unique_ptr<features::FocusLimit> m_focusLimit{};
162};
163} // namespace detail
164} // namespace autofeature
165} // namespace modules
166} // namespace pipeline
167} // namespace peak
void AddController(const std::shared_ptr< Controller > &controller)
Add a controller to an automanager.
Definition peak_afl.hpp:2299
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.
Abstract base interface for all automatic controllers.
Definition peak_afl_icontroller.hpp:223
std::function< void()> FinishedCallback
Callback function type for operation completion notifications.
Definition peak_afl_icontroller.hpp:229
virtual std::string GetName() const =0
Gets the unique name of this controller.
peak::afl::Manager & GetManager()
Gets a reference to the API manager.
Definition peak_afl_icontroller.hpp:364
virtual bool IsRunning() const =0
Checks if the controller is currently running.
FinishedCallback * FinishedCallbackHandle
Handle type for managing callback registrations.
Definition peak_afl_icontroller.hpp:234
virtual ControllerType GetType() const =0
Gets the type of this controller.
virtual ControllerMode GetMode() const =0
Gets the current operational mode of this controller.
virtual void ResetToDefault()=0
Resets the controller to its default configuration.
@ PEAK_AFL_CONTROLLER_TYPE_AUTOFOCUS
Automatic focus controller.
Definition peak_afl.h:526
@ PEAK_AFL_CONTROLLER_ROI_PRESET_CENTER
Center region preset.
Definition peak_afl.h:1417
ControllerMode
Controller operation mode enumeration.
Definition peak_afl_icontroller.hpp:55
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:36
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:74
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:57
@ Focus
Automatic focus controller - manages lens focus positioning.
Definition peak_afl_icontroller.hpp:38
@ Tenengrad
Tenengrad algorithm - gradient-based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:44
@ GoldenRatio
Golden ratio search - efficient for unimodal focus curves.
Definition peak_afl_search_algorithm.hpp:45
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