Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkToFCameraMESAController.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 <libMesaSR.h>
18 #include <string.h>
19 
20 CMesaDevice* m_MESAHandle=0;
21 
22 namespace mitk
23 {
24  ToFCameraMESAController::ToFCameraMESAController(): m_MESARes(0), m_PixelNumber(40000), m_NumberOfBytes(0),
25  m_CaptureWidth(0), m_CaptureHeight(0), m_NumImg(0), m_MaxRangeFactor(0.0), m_ConnectionCheck(false),
26  m_InputFileName("")
27  {
28  }
29 
31  {
32  }
33 
35  {
36  m_MESARes = SR_Close(m_MESAHandle); //res=SR_Close(srCam);
37  m_ConnectionCheck = !ErrorText(m_MESARes); // if disconnection was successful set connection check to false
38  m_MESAHandle = 0;
39  return m_ConnectionCheck;
40  }
41 
43  {
44  //if(error != MESA_OK)
45  //{
46  // //pmdGetLastError (m_MESAHandle, m_MESAError, 128);
47  // //MITK_ERROR << "Camera Error " << m_MESAError;
48  // return false;
49  //}
50  //else return true;
51  return true;
52  }
53 
55  {
56  m_MESARes = SR_Acquire(m_MESAHandle); //res=SR_Acquire(srCam);
57  //return ErrorText(m_MESARes);
58  return true;
59  }
60 
61  bool ToFCameraMESAController::GetAmplitudes(float* amplitudeArray)
62  {
63  unsigned short* data;
64  data = (unsigned short*)SR_GetImage(m_MESAHandle, 1);
65  for (int i=0; i<this->m_PixelNumber; i++)
66  {
67  if (data[i] & 0x8000) // bit 16 indicates saturation
68  {
69  amplitudeArray[i] = 0;
70  }
71  else
72  {
73  unsigned short value = data[i] & 0x7fff; // bit 16 indicates saturation
74  unsigned short value2 = value >> 2; // bits 1 and 2 are reserved/unused
75  amplitudeArray[i] = value2;
76  }
77  }
78  return true;
79  }
80 
81  bool ToFCameraMESAController::GetIntensities(float* intensityArray)
82  {
83  unsigned short* data;
84  data = (unsigned short*)SR_GetImage(m_MESAHandle, 1);
85  for (int i=0; i<this->m_PixelNumber; i++)
86  {
87  intensityArray[i] = data[i];
88  }
89  return true;
90  }
91 
92  bool ToFCameraMESAController::GetDistances(float* distanceArray)
93  {
94  //this->m_MESARes = pmdGetDistances(m_MESAHandle, distanceArray, this->m_NumberOfBytes);
95  //return ErrorText(this->m_MESARes);
96  unsigned short* data;
97  /*
98  for(i=0; i<m_NumImg; i++)
99  {
100  data = SR_GetImage(m_MESAHandle, i);
101  }
102  */
103  data = (unsigned short*)SR_GetImage(m_MESAHandle, 0);
104  for (int i=0; i<this->m_PixelNumber; i++)
105  {
106  if (data[i] < 0xFFF8)
107  {
108  distanceArray[i] = data[i] * this->m_MaxRangeFactor;
109  }
110  else
111  {
112  distanceArray[i] = 0.0;
113  }
114  }
115 
116  return true;
117  }
118 
119  void ToFCameraMESAController::SetInputFileName(std::string inputFileName)
120  {
121  this->m_InputFileName = inputFileName;
122  }
123 }
float m_MaxRangeFactor
holds the factor to calculate the real distance depends on the modulation frequency ...
bool ErrorText(int error)
Method printing the current error message to the console and returning whether the previous command w...
CMesaDevice * m_MESAHandle
virtual bool GetAmplitudes(float *amplitudeArray)
Gets the current amplitude array from the device.
int m_MESARes
holds the current result message provided by MESA
DataCollection - Class to facilitate loading/accessing structured data.
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
std::string m_InputFileName
input file name used by MESA player classes
virtual bool GetDistances(float *distanceArray)
Gets the current distance array from the device.
virtual void SetInputFileName(std::string inputFileName)
set input file name used by MESA player classes
virtual bool CloseCameraConnection()
closes the connection to the camera
bool m_ConnectionCheck
flag showing whether the camera is connected (true) or not (false)
int m_PixelNumber
holds the number of pixels contained in the image
virtual bool GetIntensities(float *intensityArray)
Gets the current intensity array from the device.