16#include <mitkSmartPointerProperty.h>
17#include <mitkSurface.h>
19#include <itkMultiThreader.h>
20#include <itksys/SystemTools.hxx>
28 m_DistanceDataBuffer(nullptr),
29 m_AmplitudeDataBuffer(nullptr),
30 m_RGBDataBuffer(nullptr),
31 m_DepthBufferSize(sizeof(float)*512*424),
32 m_RGBBufferSize(3*1920*1080)
44 return "Microsoft Kinect 2 Device ";
128 this->m_FreePos = (this->m_FreePos+1) % this->
m_BufferSize;
136 this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->
Acquire,
this);
138 itksys::SystemTools::Delay(10);
142 MITK_WARN <<
"Camera not connected";
151 itksys::SystemTools::Delay(100);
152 if (m_MultiThreader.IsNotNull())
154 m_MultiThreader->TerminateThread(m_ThreadID);
157 itksys::SystemTools::Delay(10);
179 struct itk::MultiThreader::ThreadInfoStruct * pInfo = (
struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct;
180 if (pInfo ==
nullptr)
182 return ITK_THREAD_RETURN_VALUE;
184 if (pInfo->UserData ==
nullptr)
186 return ITK_THREAD_RETURN_VALUE;
189 if (toFCameraDevice!=
nullptr)
191 mitk::RealTimeClock::Pointer realTimeClock;
194 t1 = realTimeClock->GetCurrentStamp();
196 bool overflow =
false;
197 bool printStatus =
false;
212 toFCameraDevice->Modified();
214 bool generateTriangularMesh =
false;
215 toFCameraDevice->
GetBoolProperty(
"GenerateTriangularMesh", generateTriangularMesh);
216 toFCameraDevice->
m_Controller->SetGenerateTriangularMesh(generateTriangularMesh);
218 float triangulationThreshold =
static_cast<mitk::FloatProperty*
>(toFCameraDevice->
GetProperty(
"TriangulationThreshold"))->GetValue();
219 toFCameraDevice->
m_Controller->SetTriangulationThreshold(triangulationThreshold);
243 t2 = realTimeClock->GetCurrentStamp() - t1;
244 MITK_INFO <<
" Framerate (fps): " << n / (t2/1000) <<
" Sequence: " << toFCameraDevice->
m_ImageSequence;
245 t1 = realTimeClock->GetCurrentStamp();
251 return ITK_THREAD_RETURN_VALUE;
264 MITK_WARN(
"ToF") <<
"Warning: Data can only be acquired if camera is active.";
283 MITK_WARN(
"ToF") <<
"Warning: Data can only be acquired if camera is active.";
289 int requiredImageSequence,
int& capturedImageSequence,
unsigned char* rgbDataArray)
297 MITK_WARN <<
"Buffer empty!! ";
303 if ((requiredImageSequence < 0) || (requiredImageSequence > this->
m_ImageSequence))
315 capturedImageSequence = requiredImageSequence;
327 mitk::Surface::Pointer surface = mitk::Surface::New();
329 this->
SetProperty(
"ToFSurface", mitk::SmartPointerProperty::New( surface ));
335 MITK_WARN(
"ToF") <<
"Warning: Data can only be acquired if camera is active.";
Interface for all representations of Microsoft Kinect V2 devices. Kinect2Device internally holds an i...
int GetRGBCaptureHeight()
returns the height of the RGB image
KinectV2Controller::Pointer m_Controller
corresponding CameraController
KinectV2Controller::Pointer GetController()
returns the corresponding camera controller
unsigned char ** m_RGBDataBuffer
buffer holding the last RGB image
vtkSmartPointer< vtkPolyData > m_PolyData
Surface generated via the Kinect V2 SDK with default/unknown calibration.
static ITK_THREAD_RETURN_TYPE Acquire(void *pInfoStruct)
Thread method continuously acquiring images from the ToF hardware.
virtual bool DisconnectCamera()
closes the connection to the camera
size_t m_DepthBufferSize
Size of depth buffer (i.e. memory size of depth and infrared image)
virtual void StopCamera()
stops the continuous updating of the camera
int GetRGBCaptureWidth()
returns the width of the RGB image
virtual void UpdateCamera()
updates the camera for image acquisition
float ** m_DistanceDataBuffer
buffer holding the last distance images
virtual void StartCamera()
starts the continuous updating of the camera. A separate thread updates the source data,...
virtual void GetAllImages(float *distanceArray, float *amplitudeArray, float *intensityArray, char *sourceDataArray, int requiredImageSequence, int &capturedImageSequence, unsigned char *rgbDataArray=nullptr)
gets the 3 images (distance, amplitude, intensity) from the ToF camera. Caution! The user is responsi...
static bool m_PrintFrameRate
prints the framerate to the console every 100 frames, deactivated by default
float ** m_AmplitudeDataBuffer
buffer holding the last amplitude images
virtual void GetDistances(float *distanceArray, int &imageSequence)
gets the distance data from the ToF camera measuring the distance between the camera and the differen...
virtual void GetAmplitudes(float *amplitudeArray, int &imageSequence)
gets the amplitude data from the ToF camera as the strength of the active illumination of every pixel...
size_t m_RGBBufferSize
Size of RGB buffer (i.e. memory size of RGB image)
virtual void GetIntensities(float *intensityArray, int &imageSequence)
Does nothing for Kinect V2 as there is no intensity data provided by the device.
virtual bool OnConnectCamera()
opens a connection to the ToF camera
virtual bool IsCameraActive()
returns whether the camera is currently active or not
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.
int m_ImageSequence
counter for acquired images
virtual void SetProperty(const char *propertyKey, BaseProperty *propertyValue)
set a BaseProperty property in the property list
int m_CaptureWidth
width of the range image (x dimension)
int m_FreePos
current position in the buffer which will be filled with data acquired from the hardware
virtual BaseProperty * GetProperty(const char *propertyKey)
get a BaseProperty from the property list
int m_RGBImageWidth
width of the RGB image (x dimension)
int m_CurrentPos
current position in the buffer which will be retrieved by the Get methods
bool GetBoolProperty(const char *propertyKey, bool &boolValue)
get a bool from the property list
int m_PixelNumber
number of pixels in the range image (m_CaptureWidth*m_CaptureHeight)
bool m_CameraConnected
flag indicating if the camera is successfully connected or not. Caution: thread safe access only!
int m_CaptureHeight
height of the range image (y dimension)
bool m_CameraActive
flag indicating if the camera is currently active or not. Caution: thread safe access only!
float * m_AmplitudeArray
float array holding the amplitude image
int m_BufferSize
buffer size of the image buffer needed for loss-less acquisition of range data
int m_RGBPixelNumber
number of pixels in the range image (m_RGBImageWidth*m_RGBImageHeight)
std::mutex m_CameraActiveMutex
mutex for the cameraActive flag
std::mutex m_ImageMutex
mutex for images provided by the range camera
float * m_DistanceArray
float array holding the distance image
int m_RGBImageHeight
height of the RGB image (y dimension)
int m_MaxBufferSize
maximal buffer size needed for initialization of data arrays. Default value is 100.
std::string GetDeviceName()