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