13#include <mitkTestingMacros.h>
14#include <mitkTestFixture.h>
15#include <mitkIOUtil.h>
20#include <usModuleContext.h>
21#include <usGetModuleContext.h>
22#include <usServiceReference.h>
33 CPPUNIT_TEST_SUITE_END();
38 std::string m_PathToDepthData;
39 float* m_DistanceArray;
45 us::ModuleContext* context = us::GetModuleContext();
48 std::string filter =
"(ToFDeviceName=MITK Player)";
49 us::ServiceReference<mitk::ToFCameraDevice> serviceRefDevice = context->GetServiceReferences<
mitk::ToFCameraDevice>(filter).front();
54 m_PathToDepthData = GetTestDataFilePath(
"ToF-Data/Kinect_Lego_Phantom_DistanceImage.nrrd");
55 m_PlayerDevice->
SetProperty(
"DistanceImageFileName",mitk::StringProperty::New(m_PathToDepthData));
58 unsigned int numberOfPixels = 640*480;
59 m_DistanceArray =
new float[numberOfPixels];
65 itksys::SystemTools::Delay(10);
72 delete[] m_DistanceArray;
77 CPPUNIT_ASSERT_MESSAGE(
"The device (player) should not be active before starting.", m_PlayerDevice->
IsCameraActive()==
false);
82 CPPUNIT_ASSERT_MESSAGE(
"ConnectCamera() should return true in case of success.", m_PlayerDevice->
ConnectCamera()==
true);
89 CPPUNIT_ASSERT_MESSAGE(
"After starting the device, the device should be active.", m_PlayerDevice->
IsCameraActive()==
true);
98 unsigned int dimension[2];
99 dimension[0] = m_PlayerDevice->GetCaptureWidth();
100 dimension[1] = m_PlayerDevice->GetCaptureHeight();
101 int imageSequence = 0;
104 m_PlayerDevice->
GetDistances(m_DistanceArray,imageSequence);
107 mitk::Image::Pointer resultDepthImage = mitk::Image::New();
108 resultDepthImage->Initialize(mitk::PixelType(mitk::MakeScalarPixelType<float>()), 2, dimension,1);
109 resultDepthImage->SetSlice(m_DistanceArray);
111 mitk::Image::Pointer expectedDepthImage = mitk::IOUtil::Load<mitk::Image>(m_PathToDepthData);
113 MITK_ASSERT_EQUAL( expectedDepthImage, resultDepthImage,
114 "Image from the player should be the same as loaded from the harddisk, because we just load one slice.");
116 catch(std::exception &e)
118 MITK_ERROR <<
"Unknown exception occured: " << e.what();
126 int imageSequence = 0;
129 m_PlayerDevice->
GetDistances(m_DistanceArray,imageSequence);
131 CPPUNIT_ASSERT_MESSAGE(
"After stopping the device, the device should be inactive.", m_PlayerDevice->
IsCameraActive()==
false);
132 CPPUNIT_ASSERT_MESSAGE(
"DisconnectCamera() should return true in case of success.", m_PlayerDevice->
DisconnectCamera()==
true);
134 catch(std::exception &e)
136 MITK_ERROR <<
"Unknown exception occured: " << e.what();
141MITK_TEST_SUITE_REGISTRATION(mitkToFCameraMITKPlayerDevice)
void StartCamera_ValidData_DeviceIsConnected()
void DeviceNotConnected_NotActive()
void ConnectCamera_ValidData_ReturnsTrue()
void GetDistances_ValidData_ImagesEqual()
void DisconnectCamera_ValidData_ReturnsTrue()
Virtual interface and base class for all Time-of-Flight devices.
virtual bool ConnectCamera()
ConnectCamera Internally calls OnConnectCamera() of the respective device implementation.
virtual bool IsCameraActive()
returns true if the camera is connected and started
virtual bool IsCameraConnected()
returns true if the camera is connected
virtual void StopCamera()
stops the continuous updating of the camera
Device class representing a player for MITK-ToF images.
void SetProperty(const char *propertyKey, BaseProperty *propertyValue) override
set a BaseProperty
void GetDistances(float *distanceArray, int &imageSequence) override
gets the distance data from the ToF camera measuring the distance between the camera and the differen...
void StartCamera() override
starts the continuous updating of the camera. A separate thread updates the source data,...
bool DisconnectCamera() override
closes the connection to the camera