Medical Imaging Interaction Toolkit  2016.11.0
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,
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 <pmdsdk2.h>
18 #include <string.h>
19 
20 // vnl includes
21 #include "vnl/vnl_matrix.h"
22 
23 PMDHandle m_PMDHandle;
24 PMDDataDescription m_DataDescription;
25 
26 struct SourceDataStruct {
27  PMDDataDescription dataDescription;
28  char sourceData;
29 };
30 
31 namespace mitk
32 {
33  ToFCameraPMDController::ToFCameraPMDController(): m_PMDRes(0), m_PixelNumber(40000), m_NumberOfBytes(0),
34  m_CaptureWidth(200), m_CaptureHeight(200),m_InternalCaptureWidth(m_CaptureWidth),m_InternalCaptureHeight(m_CaptureHeight), m_SourceDataSize(0), m_SourceDataStructSize(0), m_ConnectionCheck(false),
35  m_InputFileName("")
36  {
37  }
38 
40  {
41  }
42 
44  {
45  m_PMDRes = pmdClose(m_PMDHandle);
47  m_PMDHandle = 0;
48  return m_ConnectionCheck;
49  }
50 
52  {
53  if(error != PMD_OK)
54  {
55  pmdGetLastError (m_PMDHandle, m_PMDError, 128);
56  MITK_ERROR << "PMD Error " << m_PMDError;
57  mitkThrow() << "PMD Error " << m_PMDError;
58  return false;
59  }
60  else return true;
61  }
62 
64  {
65  m_PMDRes = pmdUpdate(m_PMDHandle);
66  return ErrorText(m_PMDRes);
67  }
68 
69  bool ToFCameraPMDController::GetAmplitudes(float* amplitudeArray)
70  {
71  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
72  this->m_PMDRes = pmdGetAmplitudes(m_PMDHandle, tempArray, this->m_NumberOfBytes);
73  TransformCameraOutput(tempArray, amplitudeArray, false);
74  delete[] tempArray;
75  return ErrorText(this->m_PMDRes);
76  }
77 
78  bool ToFCameraPMDController::GetAmplitudes(char* sourceData, float* amplitudeArray)
79  {
80  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
81  this->m_PMDRes = pmdCalcAmplitudes(m_PMDHandle, tempArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData);
82  TransformCameraOutput(tempArray, amplitudeArray, false);
83  delete[] tempArray;
84  return ErrorText(this->m_PMDRes);
85  }
86 
87  bool ToFCameraPMDController::GetIntensities(float* intensityArray)
88  {
89  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
90  this->m_PMDRes = pmdGetIntensities(m_PMDHandle, tempArray, this->m_NumberOfBytes);
91  TransformCameraOutput(tempArray, intensityArray, false);
92  delete[] tempArray;
93  return ErrorText(this->m_PMDRes);
94  }
95 
96  bool ToFCameraPMDController::GetIntensities(char* sourceData, float* intensityArray)
97  {
98  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
99  this->m_PMDRes = pmdCalcIntensities(m_PMDHandle, tempArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData);
100  TransformCameraOutput(tempArray, intensityArray, false);
101  delete[] tempArray;
102  return ErrorText(this->m_PMDRes);
103  }
104 
105  bool ToFCameraPMDController::GetDistances(float* distanceArray)
106  {
107  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
108  this->m_PMDRes = pmdGetDistances(m_PMDHandle, tempArray, this->m_NumberOfBytes);
109  TransformCameraOutput(tempArray, distanceArray, true);
110  delete[] tempArray;
111  return ErrorText(this->m_PMDRes);
112  }
113 
114  bool ToFCameraPMDController::GetDistances(char* sourceData, float* distanceArray)
115  {
116  float* tempArray = new float[m_CaptureWidth*m_CaptureHeight];
117  this->m_PMDRes = pmdCalcDistances(m_PMDHandle, tempArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData);
118  TransformCameraOutput(tempArray, distanceArray, true);
119  delete[] tempArray;
120  return ErrorText(this->m_PMDRes);
121  }
122 
123  bool ToFCameraPMDController::GetSourceData(char* sourceDataArray)
124  {
125  this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription);
126  if (!ErrorText(this->m_PMDRes))
127  {
128  return false;
129  }
130  memcpy(&((SourceDataStruct*)sourceDataArray)->dataDescription, &m_DataDescription, sizeof(m_DataDescription));
131  this->m_PMDRes = pmdGetSourceData(m_PMDHandle, &((SourceDataStruct*)sourceDataArray)->sourceData, this->m_SourceDataSize);
132  return ErrorText(this->m_PMDRes);
133  }
134 
136  {
137  this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle,&m_DataDescription);
138  ErrorText( this->m_PMDRes);
139  this->m_PMDRes = pmdGetSourceData(m_PMDHandle,sourceData,m_DataDescription.size);
140  return ErrorText( this->m_PMDRes);
141  }
142 
143  int ToFCameraPMDController::SetIntegrationTime(unsigned int integrationTime)
144  {
145  if(!m_ConnectionCheck)
146  {
147  return integrationTime;
148  }
149  unsigned int result;
150  this->m_PMDRes = pmdGetValidIntegrationTime(m_PMDHandle, &result, 0, CloseTo, integrationTime);
151  MITK_INFO << "Valid Integration Time = " << result;
152  ErrorText(this->m_PMDRes);
153  if (this->m_PMDRes != 0)
154  {
155  return 0;
156  }
157  this->m_PMDRes = pmdSetIntegrationTime(m_PMDHandle, 0, result);
158  ErrorText(this->m_PMDRes);
159  return result;
160  }
161 
163  {
164  unsigned int integrationTime = 0;
165  this->m_PMDRes = pmdGetIntegrationTime(m_PMDHandle, &integrationTime, 0);
166  ErrorText(this->m_PMDRes);
167  return integrationTime;
168  }
169 
170  int ToFCameraPMDController::SetModulationFrequency(unsigned int modulationFrequency)
171  {
172  if(!m_ConnectionCheck)
173  {
174  return modulationFrequency;
175  }
176  unsigned int result;
177  this->m_PMDRes = pmdGetValidModulationFrequency(m_PMDHandle, &result, 0, AtLeast, (modulationFrequency*1000000));
178  MITK_INFO << "Valid Modulation Frequency = " << result;
179  ErrorText(this->m_PMDRes);
180  if (this->m_PMDRes != 0)
181  {
182  return 0;
183  }
184  this->m_PMDRes = pmdSetModulationFrequency(m_PMDHandle, 0, result);
185  ErrorText(this->m_PMDRes);
186  return (result/1000000);;
187  }
188 
190  {
191  unsigned int modulationFrequency = 0;
192  this->m_PMDRes = pmdGetModulationFrequency (m_PMDHandle, &modulationFrequency, 0);
193  ErrorText(this->m_PMDRes);
194  return (modulationFrequency/1000000);
195  }
196 
197  void ToFCameraPMDController::SetInputFileName(std::string inputFileName)
198  {
199  this->m_InputFileName = inputFileName;
200  }
201 }
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:22
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
#define MITK_ERROR
Definition: mitkLogMacros.h:24
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