MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkToFCameraPMDRawDataCamBoardDevice.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============================================================================*/
14
15// vtk includes
16#include "vtkSmartPointer.h"
17
18namespace mitk
19{
21 {
22 m_Controller = ToFCameraPMDCamBoardController::New();
23 }
24
28
30 {
31 bool ok = Superclass::ConnectCamera();
32 if(ok)
33 {
34 this->m_OriginControllerHeight = static_cast<ToFCameraPMDCamBoardController*>(m_Controller.GetPointer())->GetCaptureHeight();
35 this->m_OriginControllerWidth = static_cast<ToFCameraPMDCamBoardController*>(m_Controller.GetPointer())->GetCaptureWidth();
37 this->AllocatePixelArrays();
38 this->AllocateSourceData();
39 }
40 return ok;
41 }
42
43 void ToFCameraPMDRawDataCamBoardDevice::GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray )
44 {
45 int i = 0;
46 //unsigned int channelDataPosition = 0;
47 unsigned int channelSize = (this->m_OriginControllerHeight*this->m_OriginControllerWidth*2);
48 this->SetChannelSize(channelSize);
49 signed short* channel1;
50 signed short* channel2;
51 signed short* channel3;
52 signed short* channel4;
53
55 cvtkChannelArray->SetNumberOfComponents(channelSize);
56 cvtkChannelArray->SetNumberOfTuples(4);
57 cvtkChannelArray->Allocate(1);
58
59 channel1 = sourceData;
60 cvtkChannelArray->InsertTupleValue(0,channel1);
61 sourceData += channelSize;
62 channel2 = sourceData;
63 cvtkChannelArray->InsertTupleValue(1,channel2);
64 sourceData += channelSize;
65 channel3 = sourceData;
66 cvtkChannelArray->InsertTupleValue(2,channel3);
67 sourceData += channelSize;
68 channel4 = sourceData;
69 cvtkChannelArray->InsertTupleValue(3,channel4);
70 vtkChannelArray->DeepCopy(cvtkChannelArray);
71 }
72
73 void ToFCameraPMDRawDataCamBoardDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue )
74 {
76 this->m_PropertyList->SetProperty(propertyKey, propertyValue);
77 }
78
79 void ToFCameraPMDRawDataCamBoardDevice::GetAmplitudes(float* amplitudeArray, int& imageSequence)
80 {
82 {
83 this->ResizeOutputImage(m_AmplitudeArray,amplitudeArray);
84 imageSequence = this->m_ImageSequence;
85 }
86 else
87 {
88 MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active.";
89 }
90 }
91
92 void ToFCameraPMDRawDataCamBoardDevice::GetIntensities(float* intensityArray, int& imageSequence)
93 {
95 {
96 this->ResizeOutputImage(m_IntensityArray, intensityArray);
97 imageSequence = this->m_ImageSequence;
98 }
99 else
100 {
101 MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active.";
102 }
103 }
104
105 void ToFCameraPMDRawDataCamBoardDevice::GetDistances(float* distanceArray, int& imageSequence)
106 {
107 if (m_CameraActive)
108 {
109 this->ResizeOutputImage(m_DistanceArray, distanceArray);
110 imageSequence = this->m_ImageSequence;
111 }
112 else
113 {
114 MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active.";
115 }
116 }
117
118 void ToFCameraPMDRawDataCamBoardDevice::GetAllImages(float* distanceArray, float* amplitudeArray, float* intensityArray, char* sourceDataArray,
119 int requiredImageSequence, int& capturedImageSequence, unsigned char* rgbDataArray)
120 {
121 if (m_CameraActive)
122 {
123 // check for empty buffer
124 if (this->m_ImageSequence < 0)
125 {
126 // buffer empty
127 MITK_INFO << "Buffer empty!! ";
128 capturedImageSequence = this->m_ImageSequence;
129 return;
130 }
131
132 // determine position of image in buffer
133 int pos = 0;
134 if ((requiredImageSequence < 0) || (requiredImageSequence > this->m_ImageSequence))
135 {
136 capturedImageSequence = this->m_ImageSequence;
137 pos = this->m_CurrentPos;
138 //MITK_INFO << "Required image not found! Required: " << requiredImageSequence << " delivered/current: " << this->m_ImageSequence;
139 }
140 else if (requiredImageSequence <= this->m_ImageSequence - this->m_BufferSize)
141 {
142 capturedImageSequence = (this->m_ImageSequence - this->m_BufferSize) + 1;
143 pos = (this->m_CurrentPos + 1) % this->m_BufferSize;
144 //MITK_INFO << "Out of buffer! Required: " << requiredImageSequence << " delivered: " << capturedImageSequence << " current: " << this->m_ImageSequence;
145 }
146 else // (requiredImageSequence > this->m_ImageSequence - this->m_BufferSize) && (requiredImageSequence <= this->m_ImageSequence)
147
148 {
149 capturedImageSequence = requiredImageSequence;
150 pos = (this->m_CurrentPos + (10-(this->m_ImageSequence - requiredImageSequence))) % this->m_BufferSize;
151 }
152
153 this->ResizeOutputImage(m_DistanceArray, distanceArray);
154 this->ResizeOutputImage(m_AmplitudeArray, amplitudeArray);
155 this->ResizeOutputImage(m_IntensityArray, intensityArray);
156 memcpy(sourceDataArray, this->m_SourceDataBuffer[this->m_CurrentPos], this->m_SourceDataSize);
157 }
158 else
159 {
160 MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active.";
161 }
162 }
163
164 void ToFCameraPMDRawDataCamBoardDevice::ResizeOutputImage(float* in, float* out)
165 {
166 vnl_matrix<float> inMat = vnl_matrix<float>(m_OriginControllerHeight, m_OriginControllerWidth);
167 inMat.copy_in(in);
168 vnl_matrix<float> outMat = vnl_matrix<float>(m_CaptureHeight,m_CaptureWidth);
169 vnl_matrix<float> temp = vnl_matrix<float>(m_CaptureHeight,m_CaptureWidth);
170 temp = inMat.extract(m_CaptureHeight,m_CaptureWidth, 0, 4);
171 outMat = temp.transpose(); // rotate the image data
172 outMat.flipud(); // flip image upside down
173 outMat.copy_out(out);
174 inMat.clear(); // clean data
175 outMat.clear();
176 temp.clear();
177 }
178}
int m_ImageSequence
counter for acquired images
PropertyList::Pointer m_PropertyList
a list of the corresponding properties
virtual void SetProperty(const char *propertyKey, BaseProperty *propertyValue)
set a BaseProperty property in the property list
int m_CaptureWidth
width of the range image (x dimension)
int m_CurrentPos
current position in the buffer which will be retrieved by the Get methods
int m_PixelNumber
number of pixels in the range image (m_CaptureWidth*m_CaptureHeight)
int m_CaptureHeight
height of the range image (y dimension)
bool m_CameraActive
flag indicating if the camera is currently active or not. Caution: thread safe access only!
float * m_AmplitudeArray
float array holding the amplitude image
int m_BufferSize
buffer size of the image buffer needed for loss-less acquisition of range data
float * m_IntensityArray
float array holding the intensity image
int m_SourceDataSize
size of the PMD source data
float * m_DistanceArray
float array holding the distance image
Interface to the Time-of-Flight (ToF) camera PMD CamBoard.
void GetIntensities(float *intensityArray, int &imageSequence)
Returns intensity data.
virtual void GetChannelSourceData(short *sourceData, vtkShortArray *vtkChannelArray)
Transforms the sourceData into an array with four tuples holding the channels for raw data reconstruc...
void GetAmplitudes(float *amplitudeArray, int &imageSequence)
Returns amplitude data.
void GetDistances(float *distanceArray, int &imageSequence)
Returns distance data.
void GetAllImages(float *distanceArray, float *amplitudeArray, float *intensityArray, char *sourceDataArray, int requiredImageSequence, int &capturedImageSequence, unsigned char *rgbDataArray=nullptr)
Returns all image data at once.
bool ConnectCamera()
Establishes camera connection and sets the class variables.
ToFCameraPMDController::Pointer m_Controller
corresponding CameraController
virtual void AllocatePixelArrays()
method for allocating memory for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray
unsigned int m_OriginControllerWidth
holds the original controller width
char ** m_SourceDataBuffer
buffer holding the last acquired images
virtual void AllocateSourceData()
method for allocating m_SourceDataArray and m_SourceDataBuffer
virtual void SetProperty(const char *propertyKey, BaseProperty *propertyValue)
set a BaseProperty
unsigned int m_OriginControllerHeight
holds the original controller height
IGT Exceptions.