18#include <itksys/SystemTools.hxx>
23 m_DistanceDataBuffer(nullptr), m_AmplitudeDataBuffer(nullptr), m_IntensityDataBuffer(nullptr), m_RGBDataBuffer(nullptr)
77 this->
m_Controller->GetAmplitudes(this->m_AmplitudeDataBuffer[this->m_FreePos]);
78 this->
m_Controller->GetIntensities(this->m_IntensityDataBuffer[this->m_FreePos]);
79 this->
m_Controller->GetRgb(this->m_RGBDataBuffer[this->m_FreePos]);
80 this->m_FreePos = (this->m_FreePos+1) % this->
m_BufferSize;
90 itksys::SystemTools::Delay(10);
94 MITK_INFO<<
"Camera not connected";
105 mitk::RealTimeClock::Pointer realTimeClock;
109 t1 = realTimeClock->GetCurrentStamp();
110 bool overflow =
false;
111 bool printStatus =
false;
142 t2 = realTimeClock->GetCurrentStamp() - t1;
143 MITK_INFO <<
" Framerate (fps): " << n / (t2/1000) <<
" Sequence: " <<
m_ImageSequence;
144 t1 = realTimeClock->GetCurrentStamp();
156 amplitudeArray[i] = this->m_AmplitudeDataBuffer[this->
m_CurrentPos][i];
168 intensityArray[i] = this->m_IntensityDataBuffer[this->
m_CurrentPos][i];
180 distanceArray[i] = this->m_DistanceDataBuffer[this->
m_CurrentPos][i];
192 rgbArray[i] = this->m_RGBDataBuffer[this->
m_CurrentPos][i];
199 int requiredImageSequence,
int& capturedImageSequence,
unsigned char* rgbDataArray)
207 MITK_INFO <<
"Buffer empty!! ";
214 if ((requiredImageSequence < 0) || (requiredImageSequence > this->
m_ImageSequence))
226 capturedImageSequence = requiredImageSequence;
230 if(this->m_DistanceDataBuffer&&this->m_AmplitudeDataBuffer&&this->m_IntensityDataBuffer&&this->m_RGBDataBuffer)
233 memcpy(distanceArray, this->m_DistanceDataBuffer[pos], this->
m_PixelNumber *
sizeof(
float));
234 memcpy(amplitudeArray, this->m_AmplitudeDataBuffer[pos], this->
m_PixelNumber *
sizeof(
float));
235 memcpy(intensityArray, this->m_IntensityDataBuffer[pos], this->
m_PixelNumber *
sizeof(
float));
236 memcpy(rgbDataArray, this->m_RGBDataBuffer[pos], this->
m_RGBPixelNumber * 3 *
sizeof(
unsigned char));
253 std::string strValue;
255 if (
strcmp(propertyKey,
"DistanceImageFileName") == 0)
257 myController->SetDistanceImageFileName(strValue);
259 else if (
strcmp(propertyKey,
"AmplitudeImageFileName") == 0)
261 std::ifstream amplitudeImage(strValue.c_str());
265 myController->SetAmplitudeImageFileName(strValue);
269 MITK_WARN <<
"File " << strValue <<
" does not exist!";
272 else if (
strcmp(propertyKey,
"IntensityImageFileName") == 0)
274 std::ifstream intensityImage(strValue.c_str());
278 myController->SetIntensityImageFileName(strValue);
282 MITK_WARN <<
"File " << strValue <<
" does not exist!";
285 else if (
strcmp(propertyKey,
"RGBImageFileName") == 0)
287 std::ifstream intensityImage(strValue.c_str());
291 myController->SetRGBImageFileName(strValue);
295 MITK_WARN <<
"File " << strValue <<
" does not exist!";
302 if (m_DistanceDataBuffer)
306 delete[] this->m_DistanceDataBuffer[i];
308 delete[] this->m_DistanceDataBuffer;
310 if (m_AmplitudeDataBuffer)
314 delete[] this->m_AmplitudeDataBuffer[i];
316 delete[] this->m_AmplitudeDataBuffer;
318 if (m_IntensityDataBuffer)
322 delete[] this->m_IntensityDataBuffer[i];
324 delete[] this->m_IntensityDataBuffer;
330 delete[] this->m_RGBDataBuffer[i];
332 delete[] this->m_RGBDataBuffer;
344 this->m_DistanceDataBuffer[i] =
new float[this->
m_PixelNumber];
349 this->m_AmplitudeDataBuffer[i] =
new float[this->
m_PixelNumber];
354 this->m_IntensityDataBuffer[i] =
new float[this->
m_PixelNumber];
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.
int m_ImageSequence
counter for acquired images
PropertyList::Pointer m_PropertyList
a list of the corresponding properties
int m_CaptureWidth
width of the range image (x dimension)
void SetBoolProperty(const char *propertyKey, bool boolValue)
set a bool property in the property list
int m_FreePos
current position in the buffer which will be filled with data acquired from the hardware
bool GetStringProperty(const char *propertyKey, std::string &string)
get a string from the property list
int m_RGBImageWidth
width of the RGB image (x dimension)
virtual bool IsCameraActive()
returns true if the camera is connected and started
virtual void AllocatePixelArrays()
method for allocating memory for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray
int m_CurrentPos
current position in the buffer which will be retrieved by the Get methods
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!
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
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.
Controller for playing ToF images saved in NRRD format.
void SetProperty(const char *propertyKey, BaseProperty *propertyValue) override
set a BaseProperty
ToFCameraMITKPlayerDevice()
void Acquire()
Thread method continuously acquiring images from the specified input file.
virtual void SetInputFileName(std::string inputFileName)
Set file name where the data is recorded.
~ToFCameraMITKPlayerDevice() override
void GetIntensities(float *intensityArray, int &imageSequence) override
gets the intensity data from the ToF camera as a greyscale image. Caution! The user is responsible fo...
void CleanUpDataBuffers()
Clean up memory (pixel buffers)
ToFCameraMITKPlayerController::Pointer m_Controller
member holding the corresponding controller
void AllocateDataBuffers()
Allocate pixel buffers.
std::string m_InputFileName
member holding the file name of the current input file
virtual void GetRgb(unsigned char *rgbArray, int &imageSequence)
gets the rgb data from the ToF camera. Caution! The user is responsible for allocating and deleting t...
void GetAmplitudes(float *amplitudeArray, int &imageSequence) override
gets the amplitude data from the ToF camera as the strength of the active illumination of every pixel...
bool OnConnectCamera() override
opens a connection to the ToF camera
void GetDistances(float *distanceArray, int &imageSequence) override
gets the distance data from the ToF camera measuring the distance between the camera and the differen...
void StartCamera() override
starts the continuous updating of the camera. A separate thread updates the source data,...
void GetAllImages(float *distanceArray, float *amplitudeArray, float *intensityArray, char *sourceDataArray, int requiredImageSequence, int &capturedImageSequence, unsigned char *rgbDataArray=nullptr) override
gets the 3 images (distance, amplitude, intensity) from the ToF camera. Caution! The user is responsi...
void UpdateCamera() override
updates the camera for image acquisition
bool DisconnectCamera() override
closes the connection to the camera
int strcmp(const String &s1, const String &s2)