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