MITK-IGT
IGT Extension of MITK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mitkToFCameraPMDCamCubeController.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============================================================================*/
13#include "mitkToFConfig.h"
14#include "mitkToFPMDConfig.h"
15#include <pmdsdk2.h>
16
17#include "vnl/vnl_matrix.h"
18
19//Plugin defines for CamCube
20#define SOURCE_PARAM ""
21#define PROC_PARAM ""
22
23extern PMDHandle m_PMDHandle;
24
25extern PMDDataDescription m_DataDescription;
26
27
28namespace mitk
29{
31 {
32 m_SourcePlugin = MITK_TOF_PMDCAMCUBE_SOURCE_PLUGIN;
34 m_ProcPlugin = MITK_TOF_PMDCAMCUBE_PROCESSING_PLUGIN;
36 }
37
41
43 {
45 {
49 {
50 return m_ConnectionCheck;
51 }
52
53 // get image properties from camera
54 this->UpdateCamera();
55 m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription);
57 m_CaptureWidth = m_DataDescription.img.numColumns;
62 m_NumberOfBytes = m_PixelNumber * sizeof(float);
64 m_SourceDataStructSize = m_DataDescription.size + sizeof(PMDDataDescription);
65
66 char serial[16];
67 m_PMDRes = pmdSourceCommand (m_PMDHandle, serial, 16, "GetSerialNumber");
69
70 MITK_INFO << "Serial-No: " << serial <<std::endl;
71 MITK_INFO << "Datasource size: " << this->m_SourceDataSize <<std::endl;
72 MITK_INFO << "Integration Time: " << this->GetIntegrationTime();
73 MITK_INFO << "Modulation Frequence: " << this->GetModulationFrequency();
74
75 return m_ConnectionCheck;
76 }
77 else return m_ConnectionCheck;
78 }
79
81 {
82 std::stringstream command;
83 command<<"SetSoftOffset "<<offset;
84 this->m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str());
85 return ErrorText(this->m_PMDRes);
86 }
87
89 {
90 char offset[16];
91 this->m_PMDRes = pmdSourceCommand(m_PMDHandle, offset, 16, "GetSoftOffset");
92 ErrorText(this->m_PMDRes);
93 return atof(offset);
94 }
95
96 bool mitk::ToFCameraPMDCamCubeController::SetRegionOfInterest( unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height )
97 {
98 // check if leftUpperCornerX and width are divisible by 3 otherwise round to the next value divisible by 3
99 unsigned int factor = leftUpperCornerX/3;
100 leftUpperCornerX = 3*factor;
101 factor = width/3;
102 width = 3*factor;
103 std::stringstream command;
104 command<<"SetROI "<<leftUpperCornerX<<" "<<leftUpperCornerY<<" "<<width<<" "<<height;
105 this->m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str());
106 return ErrorText(this->m_PMDRes);
107 }
108
110 {
111 return this->SetRegionOfInterest(roi[0],roi[1],roi[2],roi[3]);
112 }
113
115 {
116 /*
117 char result[64];
118 this->m_PMDRes = pmdSourceCommand(m_PMDHandle, result, 64, "GetROI");
119 ErrorText(this->m_PMDRes);
120 // convert char array to uint array
121 unsigned int roi[4];
122 std::stringstream currentValue;
123 int counter = 0;
124 std::string resultString = result;
125 char blank = ' ';
126 for (int i=0; i<64; i++)
127 {
128 if (result[i]!=blank)
129 {
130 currentValue<<result[i];
131 }
132 else
133 {
134 if (counter<4)
135 {
136 roi[counter] = atoi(currentValue.str().c_str());
137 counter++;
138 // empty the stream
139 currentValue.str("");
140 currentValue.clear();
141 }
142 }
143 }
144 return roi;
145 */
146 return nullptr;
147 }
148
150 {
151 if (mode==0) // normal mode
152 {
153 this->m_PMDRes = pmdSourceCommand(m_PMDHandle, 0, 0, "SetExposureMode Normal");
154 return ErrorText(this->m_PMDRes);
155 }
156 else if (mode==1) // SMB mode
157 {
158 this->m_PMDRes = pmdSourceCommand(m_PMDHandle, 0, 0, "SetExposureMode SMB");
159 return ErrorText(this->m_PMDRes);
160 }
161 else
162 {
163 MITK_ERROR<<"Specified exposure mode not supported. Exposure mode must be 0 (Normal) or 1 (SMB)";
164 return false;
165 }
166 }
167
169 {
170 std::stringstream commandStream;
171 commandStream<<"SetFOV "<<fov;
172 this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, commandStream.str().c_str());
173 return ErrorText(this->m_PMDRes);
174 }
175
177 {
178 if(on)
179 {
180 this->m_PMDRes=pmdSourceCommand(m_PMDHandle,0,0,"SetFPNCalibration On");
181 return this->ErrorText(this->m_PMDRes);
182 }
183 else
184 {
185 this->m_PMDRes=pmdSourceCommand(m_PMDHandle,0,0,"SetFPNCalibration Off");
186 return this->ErrorText(this->m_PMDRes);
187 }
188 }
189
191 {
192 if(on)
193 {
194 this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetFPPNCalibration On");
195 return this->ErrorText(this->m_PMDRes);
196 }
197 else
198 {
199 this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetFPPNCalibration Off");
200 return this->ErrorText(this->m_PMDRes);
201 }
202 }
203
205 {
206 if(on)
207 {
208 this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetLinearityCalibration On");
209 return this->ErrorText(this->m_PMDRes);
210 }
211 else
212 {
213 this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetLinearityCalibration Off");
214 return this->ErrorText(this->m_PMDRes);
215 }
216 }
217
219 {
220 if (on)
221 {
222 this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, "SetLensCalibration On");
223 return ErrorText(this->m_PMDRes);
224 }
225 else
226 {
227 this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, "SetLensCalibration Off");
228 return ErrorText(this->m_PMDRes);
229 }
230 }
231
232 void ToFCameraPMDCamCubeController::TransformCameraOutput( float* in, float* out, bool isDist )
233 {
234 vnl_matrix<float> inMat = vnl_matrix<float>(m_CaptureHeight,m_CaptureWidth);
235 inMat.copy_in(in);
236 vnl_matrix<float> outMat = vnl_matrix<float>(m_InternalCaptureHeight, m_InternalCaptureWidth);
237 outMat = inMat.extract(m_InternalCaptureHeight, m_InternalCaptureWidth, 0,0);
238 outMat.fliplr();
239 if(isDist)
240 {
241 outMat*=1000;
242 }
243 outMat.copy_out(out);
244 inMat.clear();
245 outMat.clear();
246 }
247}
unsigned int * GetRegionOfInterest()
returns the region of interest currently set
bool SetDistanceOffset(float offset)
sets an additional distance offset which will be added to all distance values.
bool SetLensCalibration(bool on)
Enable/Disable PMD lens calibration.
bool SetRegionOfInterest(unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height)
Setting the region of interest, the camera is configured to only output a certain area of the image.
bool SetFPNCalibration(bool on)
Enable/Disable PMD fixed pattern noise (FPN) calibration.
virtual void TransformCameraOutput(float *in, float *out, bool isDist)
bool SetExposureMode(int mode)
sets the exposure mode of the CamCube
virtual bool OpenCameraConnection()
opens a connection to the ToF camera and initializes the hardware specific members
float GetDistanceOffset()
returns the currently applied distance offset in m
bool SetLinearityCalibration(bool on)
Enable/Disable PMD linearity calibration.
bool SetFPPNCalibration(bool on)
Enable/Disable PMD fixed pattern phase noise (FPPN) calibration.
bool SetFieldOfView(float fov)
Sets the field of view of the camera lens.
virtual int GetIntegrationTime()
Returns the currently set integration time.
int m_PMDRes
holds the current result message provided by PMD
int m_SourceDataSize
size of the original PMD source data
char * m_SourceParam
holds source parameter(s)
int m_SourceDataStructSize
size of the PMD source data struct and the PMD source data
bool m_ConnectionCheck
flag showing whether the camera is connected (true) or not (false)
unsigned int m_CaptureHeight
holds the height of the image in pixel as it is originally acquired by the camera
char * m_ProcParam
holds processing parameter(s)
char * m_ProcPlugin
holds name of processing plugin to be loaded (e.g. camcubeproc.W64.pap for CamCube 3....
bool ErrorText(int error)
Method printing the current error message to the console and returning whether the previous command w...
int m_NumberOfBytes
holds the number of bytes contained in the image
int m_PixelNumber
holds the number of pixels contained in the image
unsigned int m_InternalCaptureHeight
holds the height of the image in pixel as is it requested by the user (cf. TransformCameraOutput()) D...
virtual int GetModulationFrequency()
Returns the currently set modulation frequency.
char * m_SourcePlugin
holds name of source plugin to be loaded (e.g. camcube3.W64.pap for CamCube 3.0 on Win64 platform)
unsigned int m_CaptureWidth
holds the width of the image in pixel as it is originally acquired by the camera
unsigned int m_InternalCaptureWidth
holds the width of the image in pixel as it is requested by the user (cf. TransformCameraOutput()) De...
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
PMDHandle m_PMDHandle
PMDDataDescription m_DataDescription
PMDHandle m_PMDHandle
PMDDataDescription m_DataDescription
IGT Exceptions.