Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkToFCameraPMDCamBoardController.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 <pmdsdk2.h>
19 #include "mitkToFPMDConfig.h"
20 
21 // vnl includes
22 #include "vnl/vnl_matrix.h"
23 
24 //Plugin defines for CamBoard
25 #define SOURCE_PARAM ""
26 #define PROC_PARAM ""
27 
28 extern PMDHandle m_PMDHandle;
29 extern PMDDataDescription m_DataDescription;
30 
31 namespace mitk
32 {
34  {
39  }
40 
42  {
43  }
44 
46  {
48  {
51  if (!m_ConnectionCheck)
52  {
53  return m_ConnectionCheck;
54  }
55  // get image properties from camera
56  this->UpdateCamera();
57  this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription);
59  this->m_CaptureWidth = m_DataDescription.img.numColumns;
60  this->m_InternalCaptureWidth = 200;
61  this->m_CaptureHeight = m_DataDescription.img.numRows;
62  this->m_InternalCaptureHeight = 200;
64 
65  this->m_NumberOfBytes = m_PixelNumber * sizeof(float);
67  this->m_SourceDataStructSize = m_DataDescription.size + sizeof(PMDDataDescription);
68  MITK_INFO << "Datasource size: " << this->m_SourceDataSize <<std::endl;
69  MITK_INFO << "Integration Time: " << this->GetIntegrationTime();
70  MITK_INFO << "Modulation Frequency: " << this->GetModulationFrequency();
71  return m_ConnectionCheck;
72  }
73  else return m_ConnectionCheck;
74  }
75 
77  {
78  std::stringstream command;
79  command<<"SetSoftOffset "<<offset;
80  this->m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str());
81  return ErrorText(this->m_PMDRes);
82  }
83 
85  {
86  char offset[16];
87  this->m_PMDRes = pmdSourceCommand(m_PMDHandle, offset, 16, "GetSoftOffset");
88  ErrorText(this->m_PMDRes);
89  return atof(offset);
90  }
91 
92  bool mitk::ToFCameraPMDCamBoardController::SetRegionOfInterest( unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height )
93  {
94  // CAVE: This function does not work properly, don't use unless you know what you're doing!!
95  // check if leftUpperCornerX and width are divisible by 3 otherwise round to the next value divisible by 3
96  unsigned int factor = leftUpperCornerX/3;
97  leftUpperCornerX = 3*factor;
98  factor = width/3;
99  width = 3*factor;
100  std::stringstream command;
101  command<<"SetROI "<<leftUpperCornerX<<" "<<leftUpperCornerY<<" "<<width<<" "<<height;
102  this->m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str());
103  return ErrorText(this->m_PMDRes);
104  }
105 
107  {
108  return this->SetRegionOfInterest(roi[0],roi[1],roi[2],roi[3]);
109  }
110 
112  {
113  /*
114  char result[64];
115  this->m_PMDRes = pmdSourceCommand(m_PMDHandle, result, 64, "GetROI");
116  ErrorText(this->m_PMDRes);
117  // convert char array to uint array
118  unsigned int roi[4];
119  std::stringstream currentValue;
120  int counter = 0;
121  std::string resultString = result;
122  char blank = ' ';
123  for (int i=0; i<64; i++)
124  {
125  if (result[i]!=blank)
126  {
127  currentValue<<result[i];
128  }
129  else
130  {
131  if (counter<4)
132  {
133  roi[counter] = atoi(currentValue.str().c_str());
134  counter++;
135  // empty the stream
136  currentValue.str("");
137  currentValue.clear();
138  }
139  }
140  }
141  return roi;
142  */
143  return NULL;
144  }
145 
147  {
148  //return true;
149  std::stringstream commandStream;
150  commandStream<<"SetFOV "<<fov;
151  this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, commandStream.str().c_str());
152  return ErrorText(this->m_PMDRes);
153  }
154 
155  void ToFCameraPMDCamBoardController::TransformCameraOutput( float* in, float* out, bool isDist)
156  {
157  vnl_matrix<float> inMat = vnl_matrix<float>(m_CaptureHeight,m_CaptureWidth);
158  inMat.copy_in(in);
159  vnl_matrix<float> outMat = vnl_matrix<float>(m_InternalCaptureHeight, m_InternalCaptureWidth);
160  vnl_matrix<float> temp = vnl_matrix<float>(m_InternalCaptureHeight, m_InternalCaptureWidth);
161  temp = inMat.extract(m_InternalCaptureHeight, m_InternalCaptureWidth, 0,1);
162  outMat = temp.transpose();
163  if(isDist)
164  {
165  outMat*=1000;
166  }
167  outMat.copy_out(out);
168  inMat.clear();
169  outMat.clear();
170  temp.clear();
171  }
172 }
unsigned int m_InternalCaptureHeight
holds the height of the image in pixel as is it requested by the user (cf. TransformCameraOutput()) D...
#define MITK_INFO
Definition: mitkLogMacros.h:22
virtual bool UpdateCamera()
calls update on the camera -> a new ToF-image is aquired
PMDDataDescription m_DataDescription
virtual void TransformCameraOutput(float *in, float *out, bool isDist)
unsigned int * GetRegionOfInterest()
returns the region of interest currently set
#define MITK_TOF_PMDCAMBOARD_PROCESSING_PLUGIN
char * m_ProcParam
holds processing parameter(s)
int m_PixelNumber
holds the number of pixels contained in the image
DataCollection - Class to facilitate loading/accessing structured data.
PMDHandle m_PMDHandle
bool m_ConnectionCheck
flag showing whether the camera is connected (true) or not (false)
#define MITK_TOF_PMDCAMBOARD_SOURCE_PLUGIN
int m_NumberOfBytes
holds the number of bytes contained in the image
virtual int GetIntegrationTime()
Returns the currently set integration time.
unsigned int m_CaptureHeight
holds the height of the image in pixel as it is originally acquired by the camera ...
bool SetDistanceOffset(float offset)
sets an additional distance offset which will be added to all distance values.
static Vector3D offset
bool SetFieldOfView(float fov)
Sets the field of view of the camera lens.
float GetDistanceOffset()
returns the currently applied distance offset in m
virtual int GetModulationFrequency()
Returns the currently set modulation frequency.
bool ErrorText(int error)
Method printing the current error message to the console and returning whether the previous command w...
char * m_ProcPlugin
holds name of processing plugin to be loaded (e.g. camcubeproc.W64.pap for CamCube 3...
virtual bool OpenCameraConnection()
opens a connection to the ToF camera and initializes the hardware specific members ...
unsigned int m_CaptureWidth
holds the width of the image in pixel as it is originally acquired by the camera
int m_PMDRes
holds the current result message provided by PMD
int m_SourceDataStructSize
size of the PMD source data struct and the PMD source data
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
unsigned int m_InternalCaptureWidth
holds the width of the image in pixel as it is requested by the user (cf. TransformCameraOutput()) De...
bool SetRegionOfInterest(unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height)
Setting the region of interest, the camera is configured to only output a certain area of the image...
char * m_SourceParam
holds source parameter(s)
int m_SourceDataSize
size of the original PMD source data
char * m_SourcePlugin
holds name of source plugin to be loaded (e.g. camcube3.W64.pap for CamCube 3.0 on Win64 platform) ...