MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkPlayerLoadAndRenderDepthDataTest.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============================================================================*/
12
13//MITK
14#include "mitkTestingMacros.h"
15#include "mitkRenderingTestHelper.h"
17
18//VTK
19#include <vtkRegressionTestImage.h>
20
21#include <mitkToFConfig.h>
22#include <mitkPixelType.h>
23#include <itksys/SystemTools.hxx>
24
25
26int mitkPlayerLoadAndRenderDepthDataTest(int argc, char* argv[])
27{
28 MITK_TEST_BEGIN("mitkPlayerLoadAndRenderDepthDataTest");
29
30 try
31 {
32 mitk::ToFCameraMITKPlayerDevice::Pointer playerDevice = mitk::ToFCameraMITKPlayerDevice::New();
33
34 MITK_TEST_CONDITION_REQUIRED(argc >=2, "Testing if enough input parameters are set. Usage: Testname, ImageName (must be in MITK_TOF_DATA_DIR), -V /path/to/reference/screenshot");
35 std::string dirname = MITK_TOF_DATA_DIR;
36 std::string distanceFileName = dirname + "/" + argv[1];
37 playerDevice->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName));
38
39 for (int i = 0; i < argc; ++i)
40 MITK_INFO << argv[i];
41
42 MITK_TEST_CONDITION_REQUIRED(playerDevice->IsCameraActive()==false,"The device (player) should not be active before starting.");
43 MITK_TEST_CONDITION_REQUIRED(playerDevice->ConnectCamera()==true,"ConnectCamera() should return true in case of success.");
44 MITK_TEST_OUTPUT(<< "Device connected");
45 playerDevice->StartCamera();
46 MITK_TEST_OUTPUT(<< "Device started");
47 MITK_TEST_CONDITION_REQUIRED(playerDevice->IsCameraActive()==true,"After starting the device, the device should be active.");
48
49 //initialize an array with the correct size
50 unsigned int captureWidth = playerDevice->GetCaptureWidth();
51 unsigned int captureHeight = playerDevice->GetCaptureHeight();
52 unsigned int numberOfPixels = captureWidth*captureHeight;
53 float* distances = new float[numberOfPixels];
54 int imageSequence = 0;
55
56 //fill the array with the device output
57 playerDevice->GetDistances(distances,imageSequence);
58
59 //initialize an image and fill it with the array
60 unsigned int dimension[2];
61 dimension[0] = captureWidth;
62 dimension[1] = captureHeight;
63 mitk::Image::Pointer mitkDepthImage = mitk::Image::New();
64 mitkDepthImage->Initialize(mitk::PixelType(mitk::MakeScalarPixelType<float>()), 2, dimension,1);
65 mitkDepthImage->SetSlice(distances);
66
67 //create a node to pass it to the mitkRenderingTestHelper
68 mitk::DataNode::Pointer node = mitk::DataNode::New();
69 node->SetData(mitkDepthImage);
70
71 // load all arguments into a datastorage, take last argument as reference rendering
72 // setup a renderwindow of fixed size X*Y
73 // render the datastorage
74 // compare rendering to reference image
75 mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
76 renderingHelper.AddNodeToStorage(node);
77
78 //use this to generate a reference screenshot or save the file:
79 bool generateReferenceScreenshot = false;
80 if(generateReferenceScreenshot)
81 {
82 renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/output.png");
83 }
84
85 //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
86 MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" );
87
88 //Wait some time to avoid threading issues.
89 itksys::SystemTools::Delay(1000);
90 playerDevice->StopCamera();
91 MITK_TEST_OUTPUT(<< "Device stopped");
92 MITK_TEST_CONDITION_REQUIRED(playerDevice->IsCameraActive()==false,"After stopping the device, the device should be inactive.");
93 MITK_TEST_CONDITION_REQUIRED(playerDevice->DisconnectCamera()==true, "DisconnectCamera() should return true in case of success.");
94 MITK_TEST_OUTPUT(<< "Device disconnected");
95 delete[] distances;
96 }
97 catch(std::exception &e)
98 {
99 MITK_ERROR << "Unknown exception occured: " << e.what();
100 }
101
102 MITK_TEST_END();
103}
int mitkPlayerLoadAndRenderDepthDataTest(int argc, char *argv[])