Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkToFCameraPMDCamCubeController.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
17 #include "mitkToFConfig.h"
18 #include "mitkToFPMDConfig.h"
19 #include <pmdsdk2.h>
20 
21 #include "vnl/vnl_matrix.h"
22 
23 //Plugin defines for CamCube
24 #define SOURCE_PARAM ""
25 #define PROC_PARAM ""
26 
27 extern PMDHandle m_PMDHandle;
28 
29 extern PMDDataDescription m_DataDescription;
30 
31 
32 namespace mitk
33 {
35  {
40  }
41 
43  {
44  }
45 
47  {
49  {
52  if (!m_ConnectionCheck)
53  {
54  return m_ConnectionCheck;
55  }
56 
57  // get image properties from camera
58  this->UpdateCamera();
59  m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription);
61  m_CaptureWidth = m_DataDescription.img.numColumns;
62  m_CaptureHeight = m_DataDescription.img.numRows;
66  m_NumberOfBytes = m_PixelNumber * sizeof(float);
68  m_SourceDataStructSize = m_DataDescription.size + sizeof(PMDDataDescription);
69 
70  char serial[16];
71  m_PMDRes = pmdSourceCommand (m_PMDHandle, serial, 16, "GetSerialNumber");
73 
74  MITK_INFO << "Serial-No: " << serial <<std::endl;
75  MITK_INFO << "Datasource size: " << this->m_SourceDataSize <<std::endl;
76  MITK_INFO << "Integration Time: " << this->GetIntegrationTime();
77  MITK_INFO << "Modulation Frequence: " << this->GetModulationFrequency();
78 
79  return m_ConnectionCheck;
80  }
81  else return m_ConnectionCheck;
82  }
83 
85  {
86  std::stringstream command;
87  command<<"SetSoftOffset "<<offset;
88  this->m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str());
89  return ErrorText(this->m_PMDRes);
90  }
91 
93  {
94  char offset[16];
95  this->m_PMDRes = pmdSourceCommand(m_PMDHandle, offset, 16, "GetSoftOffset");
96  ErrorText(this->m_PMDRes);
97  return atof(offset);
98  }
99 
100  bool mitk::ToFCameraPMDCamCubeController::SetRegionOfInterest( unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height )
101  {
102  // check if leftUpperCornerX and width are divisible by 3 otherwise round to the next value divisible by 3
103  unsigned int factor = leftUpperCornerX/3;
104  leftUpperCornerX = 3*factor;
105  factor = width/3;
106  width = 3*factor;
107  std::stringstream command;
108  command<<"SetROI "<<leftUpperCornerX<<" "<<leftUpperCornerY<<" "<<width<<" "<<height;
109  this->m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str());
110  return ErrorText(this->m_PMDRes);
111  }
112 
114  {
115  return this->SetRegionOfInterest(roi[0],roi[1],roi[2],roi[3]);
116  }
117 
119  {
120  /*
121  char result[64];
122  this->m_PMDRes = pmdSourceCommand(m_PMDHandle, result, 64, "GetROI");
123  ErrorText(this->m_PMDRes);
124  // convert char array to uint array
125  unsigned int roi[4];
126  std::stringstream currentValue;
127  int counter = 0;
128  std::string resultString = result;
129  char blank = ' ';
130  for (int i=0; i<64; i++)
131  {
132  if (result[i]!=blank)
133  {
134  currentValue<<result[i];
135  }
136  else
137  {
138  if (counter<4)
139  {
140  roi[counter] = atoi(currentValue.str().c_str());
141  counter++;
142  // empty the stream
143  currentValue.str("");
144  currentValue.clear();
145  }
146  }
147  }
148  return roi;
149  */
150  return NULL;
151  }
152 
154  {
155  if (mode==0) // normal mode
156  {
157  this->m_PMDRes = pmdSourceCommand(m_PMDHandle, 0, 0, "SetExposureMode Normal");
158  return ErrorText(this->m_PMDRes);
159  }
160  else if (mode==1) // SMB mode
161  {
162  this->m_PMDRes = pmdSourceCommand(m_PMDHandle, 0, 0, "SetExposureMode SMB");
163  return ErrorText(this->m_PMDRes);
164  }
165  else
166  {
167  MITK_ERROR<<"Specified exposure mode not supported. Exposure mode must be 0 (Normal) or 1 (SMB)";
168  return false;
169  }
170  }
171 
173  {
174  std::stringstream commandStream;
175  commandStream<<"SetFOV "<<fov;
176  this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, commandStream.str().c_str());
177  return ErrorText(this->m_PMDRes);
178  }
179 
181  {
182  if(on)
183  {
184  this->m_PMDRes=pmdSourceCommand(m_PMDHandle,0,0,"SetFPNCalibration On");
185  return this->ErrorText(this->m_PMDRes);
186  }
187  else
188  {
189  this->m_PMDRes=pmdSourceCommand(m_PMDHandle,0,0,"SetFPNCalibration Off");
190  return this->ErrorText(this->m_PMDRes);
191  }
192  }
193 
195  {
196  if(on)
197  {
198  this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetFPPNCalibration On");
199  return this->ErrorText(this->m_PMDRes);
200  }
201  else
202  {
203  this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetFPPNCalibration Off");
204  return this->ErrorText(this->m_PMDRes);
205  }
206  }
207 
209  {
210  if(on)
211  {
212  this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetLinearityCalibration On");
213  return this->ErrorText(this->m_PMDRes);
214  }
215  else
216  {
217  this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetLinearityCalibration Off");
218  return this->ErrorText(this->m_PMDRes);
219  }
220  }
221 
223  {
224  if (on)
225  {
226  this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, "SetLensCalibration On");
227  return ErrorText(this->m_PMDRes);
228  }
229  else
230  {
231  this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, "SetLensCalibration Off");
232  return ErrorText(this->m_PMDRes);
233  }
234  }
235 
236  void ToFCameraPMDCamCubeController::TransformCameraOutput( float* in, float* out, bool isDist )
237  {
238  vnl_matrix<float> inMat = vnl_matrix<float>(m_CaptureHeight,m_CaptureWidth);
239  inMat.copy_in(in);
240  vnl_matrix<float> outMat = vnl_matrix<float>(m_InternalCaptureHeight, m_InternalCaptureWidth);
241  outMat = inMat.extract(m_InternalCaptureHeight, m_InternalCaptureWidth, 0,0);
242  outMat.fliplr();
243  if(isDist)
244  {
245  outMat*=1000;
246  }
247  outMat.copy_out(out);
248  inMat.clear();
249  outMat.clear();
250  }
251 }
bool SetFPPNCalibration(bool on)
Enable/Disable PMD fixed pattern phase noise (FPPN) calibration.
unsigned int m_InternalCaptureHeight
holds the height of the image in pixel as is it requested by the user (cf. TransformCameraOutput()) D...
bool SetLinearityCalibration(bool on)
Enable/Disable PMD linearity calibration.
#define MITK_TOF_PMDCAMCUBE_SOURCE_PLUGIN
PMDHandle m_PMDHandle
#define MITK_INFO
Definition: mitkLogMacros.h:22
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
bool SetFPNCalibration(bool on)
Enable/Disable PMD fixed pattern noise (FPN) calibration.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
char * m_ProcParam
holds processing parameter(s)
int m_PixelNumber
holds the number of pixels contained in the image
DataCollection - Class to facilitate loading/accessing structured data.
bool SetExposureMode(int mode)
sets the exposure mode of the CamCube
#define MITK_TOF_PMDCAMCUBE_PROCESSING_PLUGIN
bool m_ConnectionCheck
flag showing whether the camera is connected (true) or not (false)
int m_NumberOfBytes
holds the number of bytes contained in the image
bool SetLensCalibration(bool on)
Enable/Disable PMD lens calibration.
PMDDataDescription m_DataDescription
bool SetFieldOfView(float fov)
Sets the field of view of the camera lens.
virtual int GetIntegrationTime()
Returns the currently set integration time.
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...
virtual void TransformCameraOutput(float *in, float *out, bool isDist)
unsigned int m_CaptureHeight
holds the height of the image in pixel as it is originally acquired by the camera ...
static Vector3D offset
virtual int GetModulationFrequency()
Returns the currently set modulation frequency.
bool ErrorText(int error)
Method printing the current error message to the console and returning whether the previous command w...
char * m_ProcPlugin
holds name of processing plugin to be loaded (e.g. camcubeproc.W64.pap for CamCube 3...
unsigned int m_CaptureWidth
holds the width of the image in pixel as it is originally acquired by the camera
virtual bool OpenCameraConnection()
opens a connection to the ToF camera and initializes the hardware specific members ...
int m_PMDRes
holds the current result message provided by PMD
int m_SourceDataStructSize
size of the PMD source data struct and the PMD source data
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
unsigned int m_InternalCaptureWidth
holds the width of the image in pixel as it is requested by the user (cf. TransformCameraOutput()) De...
float GetDistanceOffset()
returns the currently applied distance offset in m
char * m_SourceParam
holds source parameter(s)
bool SetDistanceOffset(float offset)
sets an additional distance offset which will be added to all distance values.
int m_SourceDataSize
size of the original PMD source data
unsigned int * GetRegionOfInterest()
returns the region of interest currently set
char * m_SourcePlugin
holds name of source plugin to be loaded (e.g. camcube3.W64.pap for CamCube 3.0 on Win64 platform) ...