Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkToFCameraPMDController.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
13 #include <pmdsdk2.h>
14 #include <string.h>
15 
16 // vnl includes
17 #include "vnl/vnl_matrix.h"
18 
19 PMDHandle m_PMDHandle;
20 PMDDataDescription m_DataDescription;
21 
22 struct SourceDataStruct {
23  PMDDataDescription dataDescription;
24  char sourceData;
25 };
26 
27 namespace mitk
28 {
29  ToFCameraPMDController::ToFCameraPMDController(): m_PMDRes(0), m_PixelNumber(40000), m_NumberOfBytes(0),
30  m_CaptureWidth(200), m_CaptureHeight(200),m_InternalCaptureWidth(m_CaptureWidth),m_InternalCaptureHeight(m_CaptureHeight), m_SourceDataSize(0), m_SourceDataStructSize(0), m_ConnectionCheck(false),
31  m_InputFileName("")
32  {
33  }
34 
36  {
37  }
38 
40  {
41  m_PMDRes = pmdClose(m_PMDHandle);
43  m_PMDHandle = 0;
44  return m_ConnectionCheck;
45  }
46 
48  {
49  if(error != PMD_OK)
50  {
51  pmdGetLastError (m_PMDHandle, m_PMDError, 128);
52  MITK_ERROR << "PMD Error " << m_PMDError;
53  mitkThrow() << "PMD Error " << m_PMDError;
54  return false;
55  }
56  else return true;
57  }
58 
60  {
61  m_PMDRes = pmdUpdate(m_PMDHandle);
62  return ErrorText(m_PMDRes);
63  }
64 
65  bool ToFCameraPMDController::GetAmplitudes(float* amplitudeArray)
66  {
67  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
68  this->m_PMDRes = pmdGetAmplitudes(m_PMDHandle, tempArray, this->m_NumberOfBytes);
69  TransformCameraOutput(tempArray, amplitudeArray, false);
70  delete[] tempArray;
71  return ErrorText(this->m_PMDRes);
72  }
73 
74  bool ToFCameraPMDController::GetAmplitudes(char* sourceData, float* amplitudeArray)
75  {
76  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
77  this->m_PMDRes = pmdCalcAmplitudes(m_PMDHandle, tempArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData);
78  TransformCameraOutput(tempArray, amplitudeArray, false);
79  delete[] tempArray;
80  return ErrorText(this->m_PMDRes);
81  }
82 
83  bool ToFCameraPMDController::GetIntensities(float* intensityArray)
84  {
85  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
86  this->m_PMDRes = pmdGetIntensities(m_PMDHandle, tempArray, this->m_NumberOfBytes);
87  TransformCameraOutput(tempArray, intensityArray, false);
88  delete[] tempArray;
89  return ErrorText(this->m_PMDRes);
90  }
91 
92  bool ToFCameraPMDController::GetIntensities(char* sourceData, float* intensityArray)
93  {
94  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
95  this->m_PMDRes = pmdCalcIntensities(m_PMDHandle, tempArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData);
96  TransformCameraOutput(tempArray, intensityArray, false);
97  delete[] tempArray;
98  return ErrorText(this->m_PMDRes);
99  }
100 
101  bool ToFCameraPMDController::GetDistances(float* distanceArray)
102  {
103  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
104  this->m_PMDRes = pmdGetDistances(m_PMDHandle, tempArray, this->m_NumberOfBytes);
105  TransformCameraOutput(tempArray, distanceArray, true);
106  delete[] tempArray;
107  return ErrorText(this->m_PMDRes);
108  }
109 
110  bool ToFCameraPMDController::GetDistances(char* sourceData, float* distanceArray)
111  {
112  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
113  this->m_PMDRes = pmdCalcDistances(m_PMDHandle, tempArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData);
114  TransformCameraOutput(tempArray, distanceArray, true);
115  delete[] tempArray;
116  return ErrorText(this->m_PMDRes);
117  }
118 
119  bool ToFCameraPMDController::GetSourceData(char* sourceDataArray)
120  {
121  this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription);
122  if (!ErrorText(this->m_PMDRes))
123  {
124  return false;
125  }
126  memcpy(&((SourceDataStruct*)sourceDataArray)->dataDescription, &m_DataDescription, sizeof(m_DataDescription));
127  this->m_PMDRes = pmdGetSourceData(m_PMDHandle, &((SourceDataStruct*)sourceDataArray)->sourceData, this->m_SourceDataSize);
128  return ErrorText(this->m_PMDRes);
129  }
130 
132  {
133  this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle,&m_DataDescription);
134  ErrorText( this->m_PMDRes);
135  this->m_PMDRes = pmdGetSourceData(m_PMDHandle,sourceData,m_DataDescription.size);
136  return ErrorText( this->m_PMDRes);
137  }
138 
139  int ToFCameraPMDController::SetIntegrationTime(unsigned int integrationTime)
140  {
141  if(!m_ConnectionCheck)
142  {
143  return integrationTime;
144  }
145  unsigned int result;
146  this->m_PMDRes = pmdGetValidIntegrationTime(m_PMDHandle, &result, 0, CloseTo, integrationTime);
147  MITK_INFO << "Valid Integration Time = " << result;
148  ErrorText(this->m_PMDRes);
149  if (this->m_PMDRes != 0)
150  {
151  return 0;
152  }
153  this->m_PMDRes = pmdSetIntegrationTime(m_PMDHandle, 0, result);
154  ErrorText(this->m_PMDRes);
155  return result;
156  }
157 
159  {
160  unsigned int integrationTime = 0;
161  this->m_PMDRes = pmdGetIntegrationTime(m_PMDHandle, &integrationTime, 0);
162  ErrorText(this->m_PMDRes);
163  return integrationTime;
164  }
165 
166  int ToFCameraPMDController::SetModulationFrequency(unsigned int modulationFrequency)
167  {
168  if(!m_ConnectionCheck)
169  {
170  return modulationFrequency;
171  }
172  unsigned int result;
173  this->m_PMDRes = pmdGetValidModulationFrequency(m_PMDHandle, &result, 0, AtLeast, (modulationFrequency*1000000));
174  MITK_INFO << "Valid Modulation Frequency = " << result;
175  ErrorText(this->m_PMDRes);
176  if (this->m_PMDRes != 0)
177  {
178  return 0;
179  }
180  this->m_PMDRes = pmdSetModulationFrequency(m_PMDHandle, 0, result);
181  ErrorText(this->m_PMDRes);
182  return (result/1000000);;
183  }
184 
186  {
187  unsigned int modulationFrequency = 0;
188  this->m_PMDRes = pmdGetModulationFrequency (m_PMDHandle, &modulationFrequency, 0);
189  ErrorText(this->m_PMDRes);
190  return (modulationFrequency/1000000);
191  }
192 
193  void ToFCameraPMDController::SetInputFileName(std::string inputFileName)
194  {
195  this->m_InputFileName = inputFileName;
196  }
197 }
virtual void TransformCameraOutput(float *in, float *out, bool isDist)=0
virtual bool GetSourceData(char *sourceDataArray)
Gets the PMD raw data from the ToF device.
#define MITK_INFO
Definition: mitkLogMacros.h:18
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
#define MITK_ERROR
Definition: mitkLogMacros.h:20
virtual bool CloseCameraConnection()
closes the connection to the camera
virtual void SetInputFileName(std::string inputFileName)
set input file name used by PMD player classes
virtual int SetIntegrationTime(unsigned int integrationTime)
Sets the integration time of the ToF device. The method automatically calculates a valid value from t...
DataCollection - Class to facilitate loading/accessing structured data.
PMDHandle m_PMDHandle
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
virtual int GetIntegrationTime()
Returns the currently set integration time.
unsigned int m_CaptureHeight
holds the height of the image in pixel as it is originally acquired by the camera ...
PMDDataDescription m_DataDescription
#define mitkThrow()
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...
unsigned int m_CaptureWidth
holds the width of the image in pixel as it is originally acquired by the camera
std::string m_InputFileName
input file name used by PMD player classes
int m_PMDRes
holds the current result message provided by PMD
char m_PMDError[128]
member holding the current error text
virtual bool GetDistances(float *distanceArray)
Gets the current distance array from the device.
virtual bool GetAmplitudes(float *amplitudeArray)
Gets the current amplitude array from the device.
virtual int SetModulationFrequency(unsigned int modulationFrequency)
Sets the modulation frequency of the ToF device. The method automatically calculates a valid value fr...
bool GetShortSourceData(short *sourceData)
Convenience method to get the PMD raw data from the ToF device as short array.
virtual bool GetIntensities(float *intensityArray)
Gets the current intensity array from the device.
int m_SourceDataSize
size of the original PMD source data