1 #ifndef NUITRACK_DEPTHSENSOR_H_
2 #define NUITRACK_DEPTHSENSOR_H_
6 #include "nuitrack/modules/HeaderOnlyAPI_Module.h"
7 #include "nuitrack/types/Export.h"
8 #include "nuitrack/utils/ExceptionTranslator.h"
9 #include "nuitrack/types/DepthFrame.h"
10 #include "nuitrack/types/Vector3.h"
11 #include "nuitrack/types/OutputMode.h"
12 #include "nuitrack/capi/Nuitrack_CAPI.h"
13 #include "nuitrack/capi/DepthSensor_CAPI.h"
14 #include "nuitrack/utils/CallbackStruct.h"
36 class DepthSensor :
public tdv::nuitrack::HeaderOnlyAPI_Module
44 typedef std::shared_ptr<DepthSensor>
Ptr;
52 typedef std::function<void (DepthFrame::Ptr)>
OnNewFrame;
63 NuitrackModule* pimpl = NULL;
64 ExceptionType exception_code = nuitrack_CreateDepthSensor(&pimpl);
65 char exception_message[1024];
66 nuitrack_GetExceptionMessage(pimpl, exception_message, 1024);
67 ExceptionTranslator::generateExceptionByErrorCode(exception_code, exception_message);
68 return std::shared_ptr<DepthSensor>(
new DepthSensor(pimpl));
76 _callbackStruct =
new CallbackStruct<DepthFrame::Ptr>();
77 _callbackWrapper.setDepthSensor(
this);
78 _callbackWrapper.setFunctionAddress(&onNewFrameCallback);
79 nuitrack_registerDepthSensorCallback(_pimpl, &_callbackWrapper);
84 nuitrack_DestroyDepthSensor(_pimpl);
86 delete _callbackStruct;
95 nuitrack_GetDepthSensorOutputMode(_pimpl, &mode);
105 return nuitrack_IsDepthSensorMirror(_pimpl);
122 nuitrack_SetDepthSensorMirror(_pimpl, mirror);
134 return _callbackStruct->addCallback(callback);
145 _callbackStruct->deleteCallback(handler);
154 DepthSensorDataPtr data = nuitrack_GetDepthSensorData(_pimpl);
155 DepthFrame::Ptr newFrame(
new DepthFrame(data));
167 return Vector3(nuitrack_ctypes_ConvertProjToRealCoordsVector3(_pimpl, c_vec));
178 return Vector3(nuitrack_ctypes_ConvertProjToRealCoordsXYZ(_pimpl, x, y, depth));
189 return Vector3(nuitrack_ctypes_ConvertRealToProjCoordsVector3(_pimpl, c_vec));
199 return Vector3(nuitrack_ctypes_ConvertRealToProjCoordsXYZ(_pimpl, x, y, z));
202 bool canUpdate()
const
204 return nuitrack_GetNuitrackModuleCanUpdate(_pimpl);
215 return nuitrack_GetNuitrackModuleTimestamp(_pimpl);
220 static void onNewFrameCallback(DepthSensorData* depthFrameImpl,
DepthSensor* sensor)
222 DepthFrame::Ptr newFrame(
new DepthFrame(depthFrameImpl));
223 sensor->_callbackStruct->executeAllCallbacks(newFrame);
226 NuitrackModule* _pimpl;
228 DepthSensorCallbackWrapper _callbackWrapper;
230 CallbackStruct<DepthFrame::Ptr>* _callbackStruct;
ExceptionType
Possible error codes for Nuitrack internal functions.
Definition: Error.h:20
void disconnectOnNewFrame(uint64_t handler)
Remove a callback of the new depth frame request.
Definition: DepthSensor.h:143
void setMirror(bool mirror)
Set mirror mode state.
Definition: DepthSensor.h:120
static DepthSensor::Ptr create()
Create the DepthSensor module object.
Definition: DepthSensor.h:61
std::function< void(DepthFrame::Ptr)> OnNewFrame
The callback type of the new depth frame request.
Definition: DepthSensor.h:52
virtual uint64_t getTimestamp()
Returns the last processed data timestamp in microseconds.
Definition: DepthSensor.h:213
Stores a frame depth map.
Definition: DepthFrame.h:15
Vector3 convertProjToRealCoords(const Vector3 &p) const
Convert projective coordinates to real world coordinates from Vector3 point.
Definition: DepthSensor.h:164
Stores sensor data properties.
Definition: OutputMode.h:13
Represents the interface to the capabilities of the Nuitrack Depth Sensor module. ...
Definition: DepthSensor.h:36
std::shared_ptr< DepthSensor > Ptr
Smart pointer to access the DepthSensor instance.
Definition: DepthSensor.h:44
bool isMirror() const
Returns true if mirror mode is enabled, false otherwise.
Definition: DepthSensor.h:103
DepthFrame::Ptr getDepthFrame()
Returns smart pointer to the last available DepthFrame.
Definition: DepthSensor.h:152
uint64_t connectOnNewFrame(const OnNewFrame &callback)
Add a callback for the new depth frame request.
Definition: DepthSensor.h:132
DepthSensor(NuitrackModule *pimpl)
Definition: DepthSensor.h:72
virtual Vector3 convertRealToProjCoords(const Vector3 &p) const
Convert real world coordinates to projective coordinates from Vector3 point.
Definition: DepthSensor.h:186
virtual Vector3 convertRealToProjCoords(float x, float y, float z) const
Convert real world coordinates to projective coordinates from x, y, z.
Definition: DepthSensor.h:197
virtual Vector3 convertProjToRealCoords(size_t x, size_t y, DepthFrame::DataType depth) const
Convert projective coordinates to real world coordinates from x, y and depth map. ...
Definition: DepthSensor.h:176
const OutputMode getOutputMode() const
Returns output mode of depth sensor.
Definition: DepthSensor.h:92