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