MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkToFCameraMESASR4000Controller.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 <libMesaSR.h>
15
16extern CMesaDevice* m_MESAHandle;
17
18namespace mitk
19{
21 {
22 this->m_Lambda = new float[MF_LAST];
23 this->m_Frequency = new float[MF_LAST];
24 this->m_Lambda[0] = 3.75f;
25 this->m_Lambda[1] = 5.0f;
26 this->m_Lambda[2] = 7.142857f;
27 this->m_Lambda[3] = 7.5f;
28 this->m_Lambda[4] = 7.894737f;
29 this->m_Lambda[5] = 2.5f;
30 this->m_Lambda[6] = 10.0f;
31 this->m_Lambda[7] = 15.0f;
32 this->m_Lambda[8] = 5.172414f;
33 this->m_Lambda[9] = 4.838710f;
34 this->m_Lambda[10] = 10.344828f;
35 this->m_Lambda[11] = 9.677419f;
36 this->m_Frequency[0] = 40.0f;
37 this->m_Frequency[1] = 30.0f;
38 this->m_Frequency[2] = 21.0f;
39 this->m_Frequency[3] = 20.0f;
40 this->m_Frequency[4] = 19.0f;
41 this->m_Frequency[5] = 60.0f;
42 this->m_Frequency[6] = 15.0f;
43 this->m_Frequency[7] = 10.0f;
44 this->m_Frequency[8] = 29.0f;
45 this->m_Frequency[9] = 31.0f;
46 this->m_Frequency[10] = 14.5f;
47 this->m_Frequency[11] = 15.5f;
48 }
49
53
55 {
57 {
58 /*
59 m_PMDRes = pmdOpen (&m_PMDHandle , m_SourcePlugin , m_SourceParam , m_ProcPlugin , m_ProcParam );
60 m_ConnectionCheck = ErrorText(m_PMDRes);
61 if (!m_ConnectionCheck)
62 {
63 return m_ConnectionCheck;
64 }
65
66 // get image properties from camera
67 this->UpdateCamera();
68 m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription);
69 ErrorText(m_PMDRes);
70 m_CaptureWidth = m_DataDescription.img.numColumns;
71 m_CaptureHeight = m_DataDescription.img.numRows;
72 m_PixelNumber = m_CaptureWidth*m_CaptureHeight;
73 m_NumberOfBytes = m_PixelNumber * sizeof(float);
74 m_SourceDataSize = m_DataDescription.size;
75 m_SourceDataStructSize = m_DataDescription.size + sizeof(PMDDataDescription);
76
77 char serial[16];
78 m_PMDRes = pmdSourceCommand (m_PMDHandle, serial, 16, "GetSerialNumber");
79 ErrorText(m_PMDRes);
80
81 MITK_INFO << "Serial-No: " << serial <<std::endl;
82 MITK_INFO << "Datasource size: " << this->m_SourceDataSize <<std::endl;
83 MITK_INFO << "Integration Time: " << this->GetIntegrationTime();
84 MITK_INFO << "Modulation Frequence: " << this->GetModulationFrequency();
85 return m_ConnectionCheck;
86 */
87 //m_MESARes = SR_OpenDlg(&m_MESAHandle, 3, 0);
88 this->m_MESARes = SR_OpenUSB(&m_MESAHandle, 0);
90 if (m_MESARes <= 0)
91 {
92 this->m_ConnectionCheck = false;
93 return this->m_ConnectionCheck;
94 }
95
96 this->m_MESARes = SR_GetRows(m_MESAHandle);
97 this->m_CaptureHeight = this->m_MESARes;
98 this->m_MESARes = SR_GetCols(m_MESAHandle);
99 this->m_CaptureWidth = this->m_MESARes;
100 this->m_PixelNumber = this->m_CaptureWidth*this->m_CaptureHeight;
101 this->m_NumberOfBytes = this->m_PixelNumber * sizeof(float);
102
103 ImgEntry* imgEntryArray;
104 this->m_NumImg = SR_GetImageList(m_MESAHandle, &imgEntryArray);
105
106 //float lambda[MF_LAST]={3.75f, 5.f, 7.142857f, 7.5f, 7.894737f, 2.5f, 10.f, 15.f, 5.172414f, 4.838710f, 10.344828f, 9.677419f};//MF_40MHz,MF_30MHz,MF_21MHz,MF_20MHz,MF_19MHz,...
107 //float frequency[MF_LAST]={40.00f, 30.00f, 21.00f, 20.00f, 19.00f, 60.00f, 15.00f, 10.00f, 29.00f, 31.00f, 14.50f, 15.50f};
108 ModulationFrq frq = SR_GetModulationFrequency(m_MESAHandle);
109
110 this->m_MaxRangeFactor = (this->m_Lambda[frq] * 1000.00) / (float)0xffff;
111
112 unsigned char integrationTime8bit = SR_GetIntegrationTime(m_MESAHandle);
113 float integrationTime = (0.3 + ((int)integrationTime8bit) * 0.1) * 1000; // for MESA4000
114
115 char deviceText[1024];
116 this->m_MESARes = SR_GetDeviceString(m_MESAHandle, deviceText, _countof(deviceText));//returns the device ID used in other calls
117 MITK_INFO << "Device ID: " << deviceText <<std::endl;
118 MITK_INFO << "Number of Images: " << this->m_NumImg <<std::endl;
119 MITK_INFO << "Resolution: " << this->m_CaptureWidth << " x " << this->m_CaptureHeight <<std::endl;
120 MITK_INFO << "Modulationfrequency: " << this->m_Frequency[frq] << " MHz" <<std::endl;
121 MITK_INFO << "Max range: " << this->m_Lambda[frq] << " m" <<std::endl;
122 MITK_INFO << "Integration time: " << integrationTime << " microsec" <<std::endl;
123 return m_ConnectionCheck;
124 }
125 else return m_ConnectionCheck;
126 }
127
129 {
130 float intTime = ((integrationTime / 1000.0) - 0.3) / 0.1;
131 this->m_MESARes = SR_SetIntegrationTime(m_MESAHandle, intTime);
132 MITK_INFO << "New integration time: " << integrationTime << " microsec" <<std::endl;
133 return integrationTime;
134 }
135
137 {
138 unsigned char integrationTime8bit = SR_GetIntegrationTime(m_MESAHandle);
139 float integrationTime = (0.3 + ((int)integrationTime8bit) * 0.1) * 1000;
140 return (int)integrationTime;
141 }
142
143 int ToFCameraMESASR4000Controller::SetModulationFrequency(unsigned int modulationFrequency)
144 {
145 ModulationFrq frq;
146 switch(modulationFrequency)
147 {
148 case 29: frq = MF_29MHz; break;
149 case 30: frq = MF_30MHz; break;
150 case 31: frq = MF_31MHz; break;
151 default: frq = MF_30MHz;
152 MITK_WARN << "Invalid modulation frequency: " << modulationFrequency << " MHz, reset to default (30MHz)" <<std::endl;
153 }
154 this->m_MESARes = SR_SetModulationFrequency (m_MESAHandle, frq);
155 if (this->m_MESARes == 0)
156 {
157 this->m_MaxRangeFactor = (this->m_Lambda[frq] * 1000.00) / (float)0xffff;
158 MITK_INFO << "New modulation frequency: " << this->m_Frequency[frq] << " MHz" <<std::endl;
159 return modulationFrequency;
160 }
161 else
162 {
163 return this->m_MESARes;
164 }
165 }
166
168 {
169 ModulationFrq frq = SR_GetModulationFrequency(m_MESAHandle);
170 this->m_MaxRangeFactor = (this->m_Lambda[frq] * 1000.00) / (float)0xffff;
171 float frequency = this->m_Frequency[frq];
172 return (int)frequency; // Attetntion frequency is converted to int to be consistent with MITK-ToF structure!!
173 }
174
176 {
177 int acquireMode;
178 acquireMode = SR_GetMode(m_MESAHandle);
179 acquireMode &= ~AM_COR_FIX_PTRN;
180 if (fpn)
181 {
182 acquireMode |= AM_COR_FIX_PTRN;
183 }
184 this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode);
185 }
186
188 {
189 int acquireMode;
190 acquireMode = SR_GetMode(m_MESAHandle);
191 acquireMode &= ~AM_CONV_GRAY;
192 if (ConvGray)
193 {
194 acquireMode |= AM_CONV_GRAY;
195 }
196 this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode);
197 }
198
200 {
201 int acquireMode;
202 acquireMode = SR_GetMode(m_MESAHandle);
203 acquireMode &= ~AM_MEDIAN;
204 if (median)
205 {
206 acquireMode |= AM_MEDIAN;
207 }
208 this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode);
209 }
210
212 {
213 int acquireMode;
214 acquireMode = SR_GetMode(m_MESAHandle);
215 acquireMode &= ~AM_DENOISE_ANF;
216 if (anf)
217 {
218 acquireMode |= AM_DENOISE_ANF;
219 }
220 this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode);
221 }
222
223}
bool m_ConnectionCheck
flag showing whether the camera is connected (true) or not (false)
unsigned int m_CaptureWidth
holds the width of the image in pixel
unsigned int m_CaptureHeight
holds the height of the image in pixel
int m_PixelNumber
holds the number of pixels contained in the image
int m_NumImg
holds the number of images the camera provided (distance, intensity, etc)
int m_NumberOfBytes
holds the number of bytes contained in the image
float m_MaxRangeFactor
holds the factor to calculate the real distance depends on the modulation frequency
int m_MESARes
holds the current result message provided by MESA
bool ErrorText(int error)
Method printing the current error message to the console and returning whether the previous command w...
virtual void SetFPN(bool fpn)
Sets the acquire mode of the MESA SR4000 camera. The method sets some parameter supported by the MESA...
virtual int SetModulationFrequency(unsigned int modulationFrequency)
Sets the modulation frequency of the ToF device. The method automatically calculates a valid value fr...
virtual int GetModulationFrequency()
Returns the currently set modulation frequency.
virtual int GetIntegrationTime()
Returns the currently set integration time.
virtual bool OpenCameraConnection()
opens a connection to the ToF camera and initializes the hardware specific members
virtual void SetANF(bool anf)
Sets the acquire mode of the MESA SR4000 camera. The method sets some parameter supported by the MESA...
virtual void SetMedian(bool median)
Sets the acquire mode of the MESA SR4000 camera. The method sets some parameter supported by the MESA...
virtual void SetConvGray(bool convGray)
Sets the acquire mode of the MESA SR4000 camera. The method sets some parameter supported by the MESA...
virtual int SetIntegrationTime(unsigned int integrationTime)
Sets the integration time of the ToF device. The method automatically calculates a valid value from t...
CMesaDevice * m_MESAHandle
CMesaDevice * m_MESAHandle
IGT Exceptions.