IDS peak AFL v1.8.0
Loading...
Searching...
No Matches
peak_afl_basic_auto_brightness.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
22
25
26#include <utility>
27#include <vector>
28
29namespace peak
30{
31namespace pipeline
32{
33namespace modules
34{
35namespace autofeature
36{
37
57
71{
72 switch (policy)
73 {
75 return "ExposureAndGain";
77 return "ExposureOnly";
79 return "GainOnly";
80 }
81
82 throw peak::common::InvalidParameterException("The given policy is unknown!");
83}
84
85inline std::ostream& operator<<(std::ostream& os, AutoBrightnessPolicy policy)
86{
87 return os << ToString(policy);
88}
89
90namespace detail
91{
92
93PEAK_COMMON_NO_DISCARD inline AutoBrightnessPolicy ToAutoBrightnessPolicy(const std::string& name)
94{
95 if (name == "ExposureAndGain")
96 {
98 }
99 if (name == "ExposureOnly")
100 {
102 }
103 if (name == "GainOnly")
104 {
106 }
107
108 throw peak::common::InternalErrorException("Invalid brightness policy!");
109}
110} // namespace detail
147{
148 using ProcessingCallback = std::function<void()>;
149
150public:
151 friend BrightnessComponent;
152
169 explicit BasicAutoBrightness(peak::afl::Manager& manager, ProcessingCallback callback)
170 : IController(manager)
171 , m_genericController{ manager, std::move(callback), { BrightnessComponentType::Exposure, BrightnessComponentType::Gain } }
172 {}
173
180 ~BasicAutoBrightness() override = default;
181
201 void SetMode(ControllerMode mode) override
202 {
203 auto* exposureComponent = GetExposureComponent();
204 if (exposureComponent != nullptr)
205 {
206 const auto controllerMode = (m_policy == AutoBrightnessPolicy::ExposureOnly
208 mode :
210
211 exposureComponent->SetMode(controllerMode);
212 }
213
214 auto* gainComponent = GetGainComponent();
215 if (gainComponent != nullptr)
216 {
217 const auto controllerMode = (m_policy == AutoBrightnessPolicy::GainOnly || m_policy == AutoBrightnessPolicy::ExposureAndGain) ?
218 mode :
220
221 gainComponent->SetMode(controllerMode);
222 }
223
224 m_cachedMode = mode;
225 }
226
245 {
246 auto* const exposureComponent = GetExposureComponent();
247 if (exposureComponent != nullptr)
248 {
249 if (exposureComponent->GetMode() == ControllerMode::Continuous)
250 {
252 }
253 }
254
255 auto* const gainComponent = GetGainComponent();
256 if (gainComponent != nullptr)
257 {
258 return gainComponent->GetMode();
259 }
260
261 return ControllerMode::Off;
262 }
263
275 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
276 {
277 return GetMode() != ControllerMode::Off;
278 }
279
295 {
296 m_genericController.AnalysisAlgorithm().Set(algorithm);
297 }
298
311 {
312 return m_genericController.AnalysisAlgorithm().Get();
313 }
314
330 void SetAutoPercentile(double value)
331 {
332 m_genericController.AutoPercentile().Set(value);
333 }
334
347 {
348 return m_genericController.AutoPercentile().Get();
349 }
350
363 {
364 return m_genericController.AutoPercentile().GetRange();
365 }
366
382 void SetAutoTarget(uint32_t value)
383 {
384 m_genericController.AutoTarget().Set(value);
385 }
386
399 {
400 return m_genericController.AutoTarget().Get();
401 }
402
415 {
416 return m_genericController.AutoTarget().GetRange();
417 }
418
435 void SetAutoTolerance(uint32_t value)
436 {
437 m_genericController.AutoTolerance().Set(value);
438 }
439
452 {
453 return m_genericController.AutoTolerance().Get();
454 }
455
468 {
469 return m_genericController.AutoTolerance().GetRange();
470 }
471
488 void SetSkipFrames(uint32_t value)
489 {
490 m_genericController.SkipFrames().Set(value);
491 }
492
505 {
506 return m_genericController.SkipFrames().Get();
507 }
508
521 {
522 return m_genericController.SkipFrames().GetRange();
523 }
524
541 {
542 m_genericController.Roi().Set(roi);
543 }
544
557 {
558 return m_genericController.Roi().Get();
559 }
560
579 {
580 m_policy = policy;
581 SetMode(m_cachedMode);
582 }
583
596 {
597 return m_policy;
598 }
599
617 void ResetToDefault() override
618 {
620 m_cachedMode = ControllerMode::Off;
621 m_genericController.ResetToDefault();
622 }
623
641 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
642 {
643 return m_genericController.RegisterFinishedCallback(callback);
644 }
645
658 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
659 {
660 m_genericController.UnregisterFinishedCallback(callbackHandle);
661 }
662
680 void SetExposureLimit(const IntervalD& interval)
681 {
682 auto* component = GetExposureComponent();
683 if (component == nullptr)
684 {
685 throw peak::common::NotSupportedException("Exposure component is not supported for the current device!");
686 }
687
688 component->SetLimit(interval);
689 }
690
705 {
706 auto* component = GetExposureComponent();
707 if (component != nullptr)
708 {
709 return component->GetLimit();
710 }
711
712 throw peak::common::NotSupportedException("Exposure component is not supported for the current device!");
713 }
714
732 void SetGainLimit(const IntervalD& interval)
733 {
734 auto* component = GetGainComponent();
735 if (component == nullptr)
736 {
737 throw peak::common::NotSupportedException("Gain component is not supported for the current device!");
738 }
739
740 component->SetLimit(interval);
741 }
742
757 {
758 auto* component = GetGainComponent();
759 if (component != nullptr)
760 {
761 return component->GetLimit();
762 }
763
764 throw peak::common::NotSupportedException("Gain component is not supported for the current device!");
765 }
766
767private:
769 detail::GenericAutoBrightness m_genericController;
770 ControllerMode m_cachedMode{ ControllerMode::Off };
771
780 BrightnessComponent* GetExposureComponent() const
781 {
782 return m_genericController.GetComponent(BrightnessComponentType::Exposure);
783 }
784
793 BrightnessComponent* GetGainComponent() const
794 {
795 return m_genericController.GetComponent(BrightnessComponentType::Gain);
796 }
797
806 PEAK_COMMON_NO_DISCARD std::string GetName() const override
807 {
808 return "BasicAutoBrightness";
809 }
810
823 void Serialize(peak::common::serialization::IArchive& archive) const override
824 {
825 m_genericController.Serialize(archive);
826
827 archive.SetString("Policy", ToString(m_policy));
828 }
829
843 void Deserialize(const peak::common::serialization::IArchive& archive) override
844 {
845 m_genericController.Deserialize(archive);
846
847 m_cachedMode = GetMode();
848 SetPolicy(detail::ToAutoBrightnessPolicy(archive.GetString("Policy")));
849 }
850
859 PEAK_COMMON_NO_DISCARD ControllerType GetType() const override
860 {
861 return m_genericController.GetType();
862 }
863};
864
865} // namespace autofeature
866} // namespace modules
867} // namespace pipeline
868} // namespace peak
The autofeature manager.
Definition peak_afl.hpp:306
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:50
Thrown when an unsupported operation or feature is used.
Definition peak_common_exceptions.hpp:150
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.
PEAK_COMMON_NO_DISCARD peak::common::RangeU GetAutoTargetRange() const
Gets the valid range for target brightness values.
Definition peak_afl_basic_auto_brightness.hpp:414
void SetRoi(const peak::common::Rectangle &roi)
Sets the region of interest (ROI) for selective brightness analysis.
Definition peak_afl_basic_auto_brightness.hpp:540
void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
Unregisters a previously registered completion callback.
Definition peak_afl_basic_auto_brightness.hpp:658
PEAK_COMMON_NO_DISCARD RangeD GetAutoPercentileRange() const
Gets the valid range for percentile values.
Definition peak_afl_basic_auto_brightness.hpp:362
PEAK_COMMON_NO_DISCARD peak::common::Rectangle GetRoi()
Gets the current region of interest (ROI) for brightness analysis.
Definition peak_afl_basic_auto_brightness.hpp:556
PEAK_COMMON_NO_DISCARD IntervalD GetGainLimit() const
Gets the current gain limits for the gain component.
Definition peak_afl_basic_auto_brightness.hpp:756
PEAK_COMMON_NO_DISCARD uint32_t GetAutoTarget() const
Gets the current target brightness value.
Definition peak_afl_basic_auto_brightness.hpp:398
PEAK_COMMON_NO_DISCARD AutoBrightnessPolicy GetPolicy() const
Gets the current brightness adjustment policy.
Definition peak_afl_basic_auto_brightness.hpp:595
PEAK_COMMON_NO_DISCARD peak::common::RangeU GetSkipFramesRange() const
Gets the valid range for skip frames values.
Definition peak_afl_basic_auto_brightness.hpp:520
PEAK_COMMON_NO_DISCARD BrightnessAnalysisAlgorithm GetAnalysisAlgorithm() const
Gets the current brightness analysis algorithm.
Definition peak_afl_basic_auto_brightness.hpp:310
PEAK_COMMON_NO_DISCARD bool IsRunning() const override
Checks if the brightness controller is currently running.
Definition peak_afl_basic_auto_brightness.hpp:275
BasicAutoBrightness(peak::afl::Manager &manager, ProcessingCallback callback)
Constructs a BasicAutoBrightness controller with the specified manager and callback.
Definition peak_afl_basic_auto_brightness.hpp:169
PEAK_COMMON_NO_DISCARD uint32_t GetSkipFrames() const
Gets the current number of frames to skip.
Definition peak_afl_basic_auto_brightness.hpp:504
void SetAutoTarget(uint32_t value)
Sets the target brightness value.
Definition peak_afl_basic_auto_brightness.hpp:382
void SetGainLimit(const IntervalD &interval)
Sets the gain limits for the gain component.
Definition peak_afl_basic_auto_brightness.hpp:732
void SetAutoTolerance(uint32_t value)
Sets the tolerance value for brightness stability control.
Definition peak_afl_basic_auto_brightness.hpp:435
PEAK_COMMON_NO_DISCARD ControllerMode GetMode() const override
Gets the current operation mode of the brightness controller.
Definition peak_afl_basic_auto_brightness.hpp:244
PEAK_COMMON_NO_DISCARD double GetAutoPercentile() const
Gets the current percentile value for brightness calculation.
Definition peak_afl_basic_auto_brightness.hpp:346
PEAK_COMMON_NO_DISCARD IntervalD GetExposureLimit() const
Gets the current exposure time limits for the exposure component.
Definition peak_afl_basic_auto_brightness.hpp:704
PEAK_COMMON_NO_DISCARD uint32_t GetAutoTolerance() const
Gets the current tolerance value for brightness stability control.
Definition peak_afl_basic_auto_brightness.hpp:451
void SetExposureLimit(const IntervalD &interval)
Sets the exposure time limits for the exposure component.
Definition peak_afl_basic_auto_brightness.hpp:680
PEAK_COMMON_NO_DISCARD peak::common::RangeU GetAutoToleranceRange() const
Gets the valid range for tolerance values.
Definition peak_afl_basic_auto_brightness.hpp:467
IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback &callback)
Registers a callback function to be invoked when brightness adjustment completes.
Definition peak_afl_basic_auto_brightness.hpp:641
void SetPolicy(AutoBrightnessPolicy policy)
Sets the brightness adjustment policy.
Definition peak_afl_basic_auto_brightness.hpp:578
void SetMode(ControllerMode mode) override
Sets the operation mode for the brightness controller.
Definition peak_afl_basic_auto_brightness.hpp:201
void SetAutoPercentile(double value)
Sets the percentile value for brightness calculation.
Definition peak_afl_basic_auto_brightness.hpp:330
void SetSkipFrames(uint32_t value)
Sets the number of frames to skip for performance optimization.
Definition peak_afl_basic_auto_brightness.hpp:488
void ResetToDefault() override
Resets all controller settings to their default values.
Definition peak_afl_basic_auto_brightness.hpp:617
void SetAnalysisAlgorithm(BrightnessAnalysisAlgorithm algorithm)
Sets the brightness analysis algorithm.
Definition peak_afl_basic_auto_brightness.hpp:294
~BasicAutoBrightness() override=default
Destructor for BasicAutoBrightness.
Abstract base interface for all automatic controllers.
Definition peak_afl_icontroller.hpp:228
ControllerMode
Controller operation mode enumeration.
Definition peak_afl_icontroller.hpp:60
PEAK_COMMON_NO_DISCARD std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:79
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:41
@ Continuous
Continuous operation - automatic processing on every frame.
Definition peak_afl_icontroller.hpp:64
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:62
AutoBrightnessPolicy
Auto brightness control policy enumeration.
Definition peak_afl_basic_auto_brightness.hpp:49
BrightnessAnalysisAlgorithm
Brightness analysis algorithm enumeration.
Definition peak_afl_brightness_algorithm.hpp:41
@ GainOnly
Use only gain adjustments, keeping exposure time constant.
Definition peak_afl_basic_auto_brightness.hpp:55
@ ExposureOnly
Use only exposure time adjustments, keeping gain constant.
Definition peak_afl_basic_auto_brightness.hpp:53
@ ExposureAndGain
Use both exposure time and gain adjustments for optimal brightness control.
Definition peak_afl_basic_auto_brightness.hpp:51
@ Gain
Automatic gain component - automatic gain control.
Definition peak_afl_brightness_component.hpp:53
@ Exposure
Exposure time component - controls sensor integration time.
Definition peak_afl_brightness_component.hpp:43
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:235
detail::RangeT< uint32_t > RangeU
Alias for a range of 32-bit unsigned integers.
Definition peak_common_range.hpp:132
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
peak::common::detail::RangeT< double > RangeD
Type alias for double-precision range values.
Definition peak_afl_ifeature.hpp:27
peak::common::detail::IntervalT< double > IntervalD
Type alias for double-precision interval values.
Definition peak_afl_ifeature.hpp:29