1 #ifndef NUITRACK_COLORSENSOR_H_
2 #define NUITRACK_COLORSENSOR_H_
6 #include "nuitrack/modules/HeaderOnlyAPI_Module.h"
7 #include "nuitrack/types/Export.h"
8 #include "nuitrack/utils/ExceptionTranslator.h"
9 #include "nuitrack/types/RGBFrame.h"
10 #include "nuitrack/types/Vector3.h"
11 #include "nuitrack/types/OutputMode.h"
12 #include "nuitrack/capi/Nuitrack_CAPI.h"
13 #include "nuitrack/capi/ColorSensor_CAPI.h"
14 #include "nuitrack/utils/CallbackStruct.h"
33 class ColorSensor :
public tdv::nuitrack::HeaderOnlyAPI_Module
41 typedef std::shared_ptr<ColorSensor>
Ptr;
60 NuitrackModule* pimpl = NULL;
61 ExceptionType exception_code = nuitrack_CreateColorSensor(&pimpl);
62 ExceptionTranslator::generateExceptionByErrorCode(exception_code);
63 return std::shared_ptr<ColorSensor>(
new ColorSensor(pimpl));
71 _callbackStruct =
new CallbackStruct<RGBFrame::Ptr>();
72 _callbackWrapper.setColorSensor(
this);
73 _callbackWrapper.setFunctionAddress(&onNewFrameCallback);
74 nuitrack_registerColorSensorCallback(_pimpl, &_callbackWrapper);
79 nuitrack_DestroyColorSensor(_pimpl);
81 delete _callbackStruct;
90 nuitrack_GetColorSensorOutputMode(_pimpl, &mode);
103 return _callbackStruct->addCallback(callback);
114 _callbackStruct->deleteCallback(handler);
122 ColorSensorDataPtr data = nuitrack_GetColorSensorData(_pimpl);
123 RGBFrame::Ptr newFrame(
new RGBFrame(data));
127 bool canUpdate()
const
129 return nuitrack_GetNuitrackModuleCanUpdate(_pimpl);
140 return nuitrack_GetNuitrackModuleTimestamp(_pimpl);
145 static void onNewFrameCallback(ColorSensorData* colorFrameImpl,
ColorSensor* sensor)
147 RGBFrame::Ptr newFrame(
new RGBFrame(colorFrameImpl));
148 sensor->_callbackStruct->executeAllCallbacks(newFrame);
151 NuitrackModule* _pimpl;
153 ColorSensorCallbackWrapper _callbackWrapper;
155 CallbackStruct<RGBFrame::Ptr>* _callbackStruct;
RGBFrame::Ptr getColorFrame()
Returns smart pointer to the last available RGBFrame.
Definition: ColorSensor.h:120
ColorSensor(NuitrackModule *pimpl)
Definition: ColorSensor.h:67
ExceptionType
Possible error codes for Nuitrack internal functions.
Definition: Error.h:20
uint64_t connectOnNewFrame(const OnNewFrame &callback)
Add a callback for the new color frame request.
Definition: ColorSensor.h:101
Stores sensor data properties.
Definition: OutputMode.h:13
const OutputMode getOutputMode() const
Returns output mode of color sensor.
Definition: ColorSensor.h:87
void disconnectOnNewFrame(uint64_t handler)
Remove a callback of the new color frame request.
Definition: ColorSensor.h:112
std::function< void(RGBFrame::Ptr)> OnNewFrame
The callback type of the new color frame request.
Definition: ColorSensor.h:49
std::shared_ptr< ColorSensor > Ptr
Smart pointer to access the ColorSensor instance.
Definition: ColorSensor.h:41
Stores a frame color map.
Definition: RGBFrame.h:16
Represents the interface to the capabilities of the Nuitrack Color Sensor module. ...
Definition: ColorSensor.h:33
virtual uint64_t getTimestamp()
Returns the last processed data timestamp in microseconds.
Definition: ColorSensor.h:138
static ColorSensor::Ptr create()
Create the ColorSensor module object.
Definition: ColorSensor.h:58