24#if defined(__has_include)
25# if __has_include(<peak_icv/types/peak_icv_image.hpp>)
26# include <peak_icv/types/peak_icv_image.hpp>
27# define HAS_PEAK_ICV_IMAGE 1
31#include <peak_ipl/types/peak_ipl_image.hpp>
32#include <peak/device/peak_device.hpp>
33#include <peak/node_map/peak_node_map.hpp>
49class GenericAutoFeatures :
public IAutoFeature
51 static constexpr int moduleVersion = 1;
54 friend class autofeature::BrightnessComponent;
56 explicit GenericAutoFeatures(
const std::shared_ptr<peak::core::Device>& device,
bool advanced =
true)
57 : m_remoteDeviceNodeMap{ device ?
58 device->RemoteDevice()->NodeMaps().at(0) :
59 throw peak::afl::error::InvalidParameterException(
"The given device is not valid!",
PEAK_AFL_STATUS_ERROR) }
60 , m_manager{ m_remoteDeviceNodeMap }
62 const auto isColorCamera = [
this]() {
63 const auto pixelFormatNode = m_remoteDeviceNodeMap->TryFindNode<peak::core::nodes::EnumerationNode>(
"PixelFormat");
64 if (pixelFormatNode ==
nullptr || !pixelFormatNode->IsReadable())
69 for (
const auto& entry : pixelFormatNode->AvailableEntries())
73 const auto pixelformat = peak::ipl::PixelFormat(
static_cast<peak::ipl::PixelFormatName
>(entry->Value()));
75 if (pixelformat.IsBayered())
80 catch (
const std::exception&)
89 for (
const auto& controllerType :
97 if (m_manager.IsControllerSupported(autofeature::detail::ToCType(controllerType)))
99 auto controller = CreateController(m_manager, controllerType, advanced);
100 m_controllers.emplace_back(std::move(controller));
104 m_manager.SetGainIPL(m_gain);
109 ~GenericAutoFeatures()
override =
default;
113 return "GenericAutoFeatures";
116 void SetEnabled(
bool enabled)
override
121 void Serialize(peak::common::serialization::IArchive& archive)
const override
123 archive.
SetInt(
"Version", moduleVersion);
124 archive.
SetBool(
"Enabled", m_enabled);
126 for (
const auto& controller : m_controllers)
129 controller->Serialize(*controllerArchive);
131 archive.
SetArchive(controller->GetName(), std::move(controllerArchive));
135 void Deserialize(
const peak::common::serialization::IArchive& archive)
override
137 const auto version{ archive.
GetInt(
"Version") };
140 throw peak::afl::error::CorruptedDataException(
144 m_enabled = archive.
GetBool(
"Enabled");
145 for (
const auto& controller : m_controllers)
147 auto controllerArchive = archive.
GetArchive(controller->GetName());
148 controller->Deserialize(*controllerArchive);
159 std::vector<autofeature::detail::IController*> controllers;
161 m_controllers.begin(), m_controllers.end(), std::back_inserter(controllers), [](
const auto& elem) { return elem.get(); });
167 const auto& controllers = GetControllers();
168 const auto result = std::find_if(
169 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
170 if (result != controllers.end())
180 const auto& controllers = GetControllers();
181 const auto result = std::find_if(
182 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
183 return result != controllers.end();
188 for (
auto* controller : GetControllers())
190 controller->ResetToDefault();
194 void SetGainModule(std::shared_ptr<peak::pipeline::modules::IGain> gainModule)
override
196 m_gainModule = gainModule;
199 void SetColorCorrectionMatrix(
const std::array<float, 9>& ccm)
override
201 m_manager.SetCCM(ccm);
211 const auto isProcessing = m_manager.Status();
217#if defined(HAS_PEAK_ICV_IMAGE) && defined(WITH_peak_ipl)
218 if (input.
GetType() ==
typeid(peak::icv::Image))
220 m_manager.Process(input.
AnyCast<peak::icv::Image>());
224 if (input.
GetType() ==
typeid(peak::ipl::Image))
226 m_manager.Process(input.
AnyCast<peak::ipl::Image>());
240 switch (controllerType)
245 return std::make_unique<autofeature::AdvancedAutoFocus>(manager);
247 return std::make_unique<autofeature::BasicAutoFocus>(manager);
250 auto callback = [
this]() {
255 m_gainModule->SetMaster(m_gain.MasterGainValue());
260 return std::make_unique<autofeature::AdvancedAutoBrightness>(manager, callback);
262 return std::make_unique<autofeature::BasicAutoBrightness>(manager, callback);
266 auto callback = [
this]() {
272 m_gainModule->SetRed(m_gain.RedGainValue());
273 m_gainModule->SetGreen(m_gain.GreenGainValue());
274 m_gainModule->SetBlue(m_gain.BlueGainValue());
279 return std::make_unique<autofeature::AdvancedAutoWhiteBalance>(manager, callback);
281 return std::make_unique<autofeature::BasicAutoWhiteBalance>(manager, callback);
286 std::shared_ptr<peak::core::NodeMap> m_remoteDeviceNodeMap{};
288 std::vector<std::unique_ptr<autofeature::detail::IController>> m_controllers{};
289 peak::afl::Manager m_manager;
291 std::shared_ptr<modules::IGain> m_gainModule{};
292 peak::ipl::Gain m_gain{};
294 bool m_enabled{
true };
const std::type_info & GetType() const
Gets the type of the stored value.
Definition peak_common_any.hpp:164
T & AnyCast()
Casts the stored value to the specified type.
Definition peak_common_any.hpp:179
virtual void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
virtual std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive by key.
virtual void SetInt(const std::string &key, int64_t value)=0
Stores a 64-bit signed integer.
virtual int64_t GetInt(const std::string &key) const =0
Retrieves a 64-bit signed integer by key.
virtual bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
virtual std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
virtual void SetArchive(const std::string &key, const std::shared_ptr< IArchive > &value)=0
Stores a nested archive object.
virtual void ResetToDefault()=0
Resets the module to its default state. The enabled state is not reset.
virtual bool IsEnabled() const =0
Checks whether the module is currently enabled.
virtual const char * GetType() const =0
Returns the type identifier of the module.
@ 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
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:40
@ WhiteBalance
Automatic white balance controller - manages color correction.
Definition peak_afl_icontroller.hpp:46
@ Brightness
Automatic brightness controller - manages exposure and gain.
Definition peak_afl_icontroller.hpp:44
@ Focus
Automatic focus controller - manages lens focus positioning.
Definition peak_afl_icontroller.hpp:42
#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