MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkToFCameraPMDController.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 <pmdsdk2.h>
14#include <string.h>
15
16// vnl includes
17#include "vnl/vnl_matrix.h"
18
19PMDHandle m_PMDHandle;
20PMDDataDescription m_DataDescription;
21
23 PMDDataDescription dataDescription;
25};
26
27namespace 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
38
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 {
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 {
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 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
bool m_ConnectionCheck
flag showing whether the camera is connected (true) or not (false)
virtual bool GetAmplitudes(float *amplitudeArray)
Gets the current amplitude array from the device.
unsigned int m_CaptureHeight
holds the height of the image in pixel as it is originally acquired by the camera
virtual bool GetIntensities(float *intensityArray)
Gets the current intensity 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...
virtual bool CloseCameraConnection()
closes the connection to the camera
bool ErrorText(int error)
Method printing the current error message to the console and returning whether the previous command w...
std::string m_InputFileName
input file name used by PMD player classes
int m_NumberOfBytes
holds the number of bytes contained in the image
virtual bool GetSourceData(char *sourceDataArray)
Gets the PMD raw data from the ToF device.
virtual int SetIntegrationTime(unsigned int integrationTime)
Sets the integration time of the ToF device. The method automatically calculates a valid value from t...
bool GetShortSourceData(short *sourceData)
Convenience method to get the PMD raw data from the ToF device as short array.
virtual int GetModulationFrequency()
Returns the currently set modulation frequency.
virtual bool GetDistances(float *distanceArray)
Gets the current distance array from the device.
char m_PMDError[128]
member holding the current error text
unsigned int m_CaptureWidth
holds the width of the image in pixel as it is originally acquired by the camera
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
virtual void TransformCameraOutput(float *in, float *out, bool isDist)=0
virtual void SetInputFileName(std::string inputFileName)
set input file name used by PMD player classes
PMDHandle m_PMDHandle
PMDDataDescription m_DataDescription
PMDHandle m_PMDHandle
PMDDataDescription m_DataDescription
IGT Exceptions.
PMDDataDescription dataDescription