MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkPlayerLoadAndRenderRGBDataTest.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 mitkPlayerLoadAndRenderRGBDataTest(int argc, char* argv[])
27{
28 MITK_TEST_BEGIN("mitkPlayerLoadAndRenderRGBDataTest");
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 rgbFileName = dirname + "/" + argv[1];
37 playerDevice->SetProperty("RGBImageFileName",mitk::StringProperty::New(rgbFileName));
38
39 MITK_TEST_CONDITION_REQUIRED(playerDevice->IsCameraActive()==false,"The device (player) should not be active before starting.");
40 MITK_TEST_CONDITION_REQUIRED(playerDevice->ConnectCamera()==true,"ConnectCamera() should return true in case of success.");
41 MITK_TEST_OUTPUT(<< "Device connected");
42 playerDevice->StartCamera();
43 MITK_TEST_OUTPUT(<< "Device started");
44 MITK_TEST_CONDITION_REQUIRED(playerDevice->IsCameraActive()==true,"After starting the device, the device should be active.");
45
46 //initialize an array with the correct size
47 unsigned int captureWidth = playerDevice->GetCaptureWidth();
48 unsigned int captureHeight = playerDevice->GetCaptureHeight();
49 unsigned int numberOfPixels = captureWidth*captureHeight;
50 unsigned char* rgbDataArray = new unsigned char[numberOfPixels*3];
51 int imageSequence = 0;
52
53 //fill the array with the device output
54 playerDevice->GetRgb(rgbDataArray, imageSequence);
55
56 //initialize an image and fill it with the array
57 unsigned int dimension[2];
58 dimension[0] = captureWidth;
59 dimension[1] = captureHeight;
60 mitk::Image::Pointer rgbImage = mitk::Image::New();
61 rgbImage->Initialize(mitk::PixelType(mitk::MakePixelType<unsigned char, itk::RGBPixel<unsigned char>, 3>()), 2, dimension,1);
62 rgbImage->SetSlice(rgbDataArray);
63
64 //create a node to pass it to the mitkRenderingTestHelper
65 mitk::DataNode::Pointer node = mitk::DataNode::New();
66 node->SetData(rgbImage);
67
68 // load all arguments into a datastorage, take last argument as reference rendering
69 // setup a renderwindow of fixed size X*Y
70 // render the datastorage
71 // compare rendering to reference image
72 mitk::RenderingTestHelper renderingHelper(640, 480, argc, argv);
73 renderingHelper.AddNodeToStorage(node);
74 renderingHelper.Render();
75
76 //use this to generate a reference screenshot or save the file:
77 bool generateReferenceScreenshot = false;
78 if(generateReferenceScreenshot)
79 {
80 renderingHelper.SaveReferenceScreenShot("/home/kilgus/Pictures/output.png");
81 }
82
83 //### Usage of CompareRenderWindowAgainstReference: See docu of mitkRrenderingTestHelper
84 MITK_TEST_CONDITION( renderingHelper.CompareRenderWindowAgainstReference(argc, argv) == true, "CompareRenderWindowAgainstReference test result positive?" );
85
86 //Wait some time to avoid threading issues.
87 itksys::SystemTools::Delay(1000);
88 playerDevice->StopCamera();
89 MITK_TEST_OUTPUT(<< "Device stopped");
90 MITK_TEST_CONDITION_REQUIRED(playerDevice->IsCameraActive()==false,"After stopping the device, the device should be inactive.");
91 MITK_TEST_CONDITION_REQUIRED(playerDevice->DisconnectCamera()==true, "DisconnectCamera() should return true in case of success.");
92 MITK_TEST_OUTPUT(<< "Device disconnected");
93 delete[] rgbDataArray;
94 }
95 catch(std::exception &e)
96 {
97 MITK_ERROR << "Unknown exception occured: " << e.what();
98 }
99
100 MITK_TEST_END();
101}
int mitkPlayerLoadAndRenderRGBDataTest(int argc, char *argv[])