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