MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkCameraVisualizationTest.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
14#include "mitkNavigationData.h"
15#include "mitkTestingMacros.h"
16#include "mitkVtkPropRenderer.h"
17
18#include <vtkRenderer.h>
19#include <vtkRenderWindow.h>
20
21#include <ctime>
22
26int mitkCameraVisualizationTest(int /* argc */, char* /*argv*/[])
27{
28 MITK_TEST_BEGIN("CameraVisualization")
29
30 // let's create an object of our class
31 mitk::CameraVisualization::Pointer myFilter = mitk::CameraVisualization::New();
32
33 // first test: did this work?
34 // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
35 // it makes no sense to continue without an object.
36 MITK_TEST_CONDITION_REQUIRED(myFilter.IsNotNull(),"Testing instantiation");
37
38 /* create helper objects: navigation data with position as origin, zero quaternion, zero error and data valid */
39 srand(time(nullptr));
40 // generate a random position for the navigation data
42 position[0] = rand()%1000;
43 position[1] = rand()%1000;
44 position[2] = rand()%1000;
45
46 // generate a random orientation for the navigation data
48 orientation[0] = (rand()%1000)/1000.0;
49 orientation[1] = (rand()%1000)/1000.0;
50 orientation[2] = (rand()%1000)/1000.0;
51 orientation[3] = (rand()%1000)/1000.0;
52
53 // generate a random error for the navigation data
54 mitk::ScalarType error = rand()%10;
55
56 // data valid flag of navigation data
57 int val = rand()%2;
58 bool valid(false); // this was uninitialized. how was this test ever meant to work??
59 if (val==0)
60 {
61 valid=false;
62 }
63 else if (val==1)
64 {
65 valid=true;
66 }
67
68 // set parameters of navigation data
69 mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New();
70 nd1->SetPosition(position);
71 nd1->SetOrientation(orientation);
72 nd1->SetPositionAccuracy(error);
73 nd1->SetDataValid(valid);
74
75 // create renderer
76 vtkRenderWindow* renderWindow = vtkRenderWindow::New();
77 mitk::VtkPropRenderer::Pointer renderer = mitk::VtkPropRenderer::New( "TestRenderer", renderWindow );
78
79 myFilter->SetInput(nd1);
80 MITK_TEST_CONDITION(myFilter->GetInput() == nd1, "Testing Set-/GetInput() input 1");
81
82 // test for exception if renderer not set
83 MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
84 myFilter->Update();
85 MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)
86
87 // set renderer
88 myFilter->SetRenderer(renderer);
89
90 //Update filter
91 myFilter->Update();
92
93 //Delete renderWindow correctly
94 renderWindow->Delete();
95
96 // always end with this!
97 MITK_TEST_END();
98
99}
100
101
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
mitk::Point3D PositionType
Type that holds the position part of the tracking data.
int mitkCameraVisualizationTest(int, char *[])