MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkToFCameraDevice.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12#include "mitkToFCameraDevice.h"
13#include <itksys/SystemTools.hxx>
14
15namespace mitk
16{
17 ToFCameraDevice::ToFCameraDevice():m_BufferSize(1),m_MaxBufferSize(100),m_CurrentPos(-1),m_FreePos(0),
18 m_CaptureWidth(204),m_CaptureHeight(204),m_PixelNumber(41616),m_SourceDataSize(0),
19 m_CameraActive(false),m_CameraConnected(false),m_ImageSequence(0)
20 {
21 this->m_AmplitudeArray = nullptr;
22 this->m_IntensityArray = nullptr;
23 this->m_DistanceArray = nullptr;
24 this->m_PropertyList = mitk::PropertyList::New();
25
26 //By default, all devices have no further images (just a distance image)
27 //If a device provides more data (e.g. RGB, Intensity, Amplitde images,
28 //the property has to be true.
29 this->m_PropertyList->SetBoolProperty("HasRGBImage", false);
30 this->m_PropertyList->SetBoolProperty("HasIntensityImage", false);
31 this->m_PropertyList->SetBoolProperty("HasAmplitudeImage", false);
32
33 this->m_RGBImageWidth = this->m_CaptureWidth;
36 }
37
41
42 void ToFCameraDevice::SetBoolProperty( const char* propertyKey, bool boolValue )
43 {
44 SetProperty(propertyKey, mitk::BoolProperty::New(boolValue));
45 }
46
47 void ToFCameraDevice::SetIntProperty( const char* propertyKey, int intValue )
48 {
49 SetProperty(propertyKey, mitk::IntProperty::New(intValue));
50 }
51
52 void ToFCameraDevice::SetFloatProperty( const char* propertyKey, float floatValue )
53 {
54 SetProperty(propertyKey, mitk::FloatProperty::New(floatValue));
55 }
56
57 void ToFCameraDevice::SetStringProperty( const char* propertyKey, const char* stringValue )
58 {
59 SetProperty(propertyKey, mitk::StringProperty::New(stringValue));
60 }
61
62 void ToFCameraDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue )
63 {
64 this->m_PropertyList->SetProperty(propertyKey, propertyValue);
65 }
66
67 BaseProperty* ToFCameraDevice::GetProperty(const char *propertyKey)
68 {
69 return this->m_PropertyList->GetProperty(propertyKey);
70 }
71
72 bool ToFCameraDevice::GetBoolProperty(const char *propertyKey, bool& boolValue)
73 {
74 mitk::BoolProperty::Pointer boolprop = dynamic_cast<mitk::BoolProperty*>(this->GetProperty(propertyKey));
75 if(boolprop.IsNull())
76 return false;
77
78 boolValue = boolprop->GetValue();
79 return true;
80 }
81
82 bool ToFCameraDevice::GetStringProperty(const char *propertyKey, std::string& string)
83 {
84 mitk::StringProperty::Pointer stringProp = dynamic_cast<mitk::StringProperty*>(this->GetProperty(propertyKey));
85 if(stringProp.IsNull())
86 {
87 return false;
88 }
89 else
90 {
91 string = stringProp->GetValue();
92 return true;
93 }
94 }
95 bool ToFCameraDevice::GetIntProperty(const char *propertyKey, int& integer)
96 {
97 mitk::IntProperty::Pointer intProp = dynamic_cast<mitk::IntProperty*>(this->GetProperty(propertyKey));
98 if(intProp.IsNull())
99 {
100 return false;
101 }
102 else
103 {
104 integer = intProp->GetValue();
105 return true;
106 }
107 }
108
110 {
112 {
113 delete [] m_IntensityArray;
114 }
115 if (m_DistanceArray)
116 {
117 delete [] m_DistanceArray;
118 }
120 {
121 delete [] m_AmplitudeArray;
122 }
123 }
124
126 {
127 // free memory if it was already allocated
129 // allocate buffer
130 this->m_IntensityArray = new float[this->m_PixelNumber];
131 for(int i=0; i<this->m_PixelNumber; i++) {this->m_IntensityArray[i]=0.0;}
132 this->m_DistanceArray = new float[this->m_PixelNumber];
133 for(int i=0; i<this->m_PixelNumber; i++) {this->m_DistanceArray[i]=0.0;}
134 this->m_AmplitudeArray = new float[this->m_PixelNumber];
135 for(int i=0; i<this->m_PixelNumber; i++) {this->m_AmplitudeArray[i]=0.0;}
136 }
137
139 {
140 return this->m_RGBImageWidth;
141 }
142
144 {
145 return this->m_RGBImageHeight;
146 }
147
149 {
150 m_CameraActiveMutex.lock();
151 m_CameraActive = false;
152 m_CameraActiveMutex.unlock();
153 itksys::SystemTools::Delay(100);
154 if (m_Thread.joinable())
155 m_Thread.detach();
156 // wait a little to make sure that the thread is terminated
157 itksys::SystemTools::Delay(100);
158 }
159
161 {
162 m_CameraActiveMutex.lock();
163 bool ok = m_CameraActive;
164 m_CameraActiveMutex.unlock();
165 return ok;
166 }
167
169 {
170 // Prepare connection, fail if this fails.
171 if (! this->OnConnectCamera()) return false;
172 return true;
173 }
174
179}
PropertyList::Pointer m_PropertyList
a list of the corresponding properties
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)
virtual bool ConnectCamera()
ConnectCamera Internally calls OnConnectCamera() of the respective device implementation.
void SetBoolProperty(const char *propertyKey, bool boolValue)
set a bool property in the property list
bool GetStringProperty(const char *propertyKey, std::string &string)
get a string from the property list
virtual BaseProperty * GetProperty(const char *propertyKey)
get a BaseProperty from the property list
virtual void CleanupPixelArrays()
method for cleanup memory allocated for pixel arrays m_IntensityArray, m_DistanceArray and m_Amplitud...
void SetIntProperty(const char *propertyKey, int intValue)
set an int property in 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 bool OnConnectCamera()=0
Opens a connection to the ToF camera. Has to be implemented in the specialized inherited classes.
virtual void AllocatePixelArrays()
method for allocating memory for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray
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 GetIntProperty(const char *propertyKey, int &integer)
get an int from the property list
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)
void SetStringProperty(const char *propertyKey, const char *stringValue)
set a string property in the property list
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_RGBPixelNumber
number of pixels in the range image (m_RGBImageWidth*m_RGBImageHeight)
virtual bool IsCameraConnected()
returns true if the camera is connected
void SetFloatProperty(const char *propertyKey, float floatValue)
set a float property in the property list
std::mutex m_CameraActiveMutex
mutex for the cameraActive flag
virtual void StopCamera()
stops the continuous updating of the camera
float * m_IntensityArray
float array holding the intensity image
float * m_DistanceArray
float array holding the distance image
int m_RGBImageHeight
height of the RGB image (y dimension)
IGT Exceptions.