Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkRenderingManagerTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkProperties.h"
18 #include "mitkRenderingManager.h"
20 #include "mitkVtkPropRenderer.h"
21 #include "vtkRenderWindow.h"
22 
23 #include "mitkTestingMacros.h"
24 
25 #include "mitkSurface.h"
26 #include <vtkCubeSource.h>
27 
28 // Propertylist Test
29 
38 class mitkRenderingManagerTestClass
39 {
40 public:
41  static void TestPropertyList(mitk::RenderingManager::Pointer renderingManager)
42  {
43  mitk::PropertyList::Pointer propertyList = renderingManager->GetPropertyList();
44 
45  MITK_TEST_CONDITION(renderingManager->GetPropertyList().IsNotNull(),
46  "Testing if the constructor set the propertylist")
47 
48  // check if the default properties are set
49  renderingManager->SetProperty("booltest", mitk::BoolProperty::New(true));
50 
51  mitk::BoolProperty *prop = dynamic_cast<mitk::BoolProperty *>(renderingManager->GetProperty("booltest"));
52 
53  MITK_TEST_CONDITION(prop->GetValue(), "Testing if getting the bool property")
54 
55  MITK_TEST_CONDITION(propertyList == renderingManager->GetPropertyList(),
56  "Testing if the propertylist has changed during the last tests")
57  }
58 
59  static void TestSurfaceLoading(mitk::RenderingManager::Pointer renderingManager)
60  {
61  // create and render two dimensional surface
62  vtkCubeSource *plane = vtkCubeSource::New();
63 
64  double planeBounds[] = {-1.0, 1.0, -1.0, 1.0, 0.0, 0.0};
65  double cubeBounds[] = {-0.5, 0.5, -0.5, 0.5, -0.5, 0.5};
66  plane->SetBounds(planeBounds);
67  plane->SetCenter(0.0, 0.0, 0.0);
68 
69  vtkPolyData *polys = plane->GetOutput();
71  mitkPlane->SetVtkPolyData(polys);
72  plane->Delete();
73 
75  planeNode->SetData(mitkPlane);
76 
77  renderingManager->GetDataStorage()->Add(planeNode);
78 
80  planeGeometry->SetFloatBounds(planeBounds);
81 
82  MITK_TEST_CONDITION(renderingManager->InitializeViews(planeGeometry),
83  "Testing if two dimensional Geometry3Ds can be displayed")
84 
85  // clear rendering
86  renderingManager->GetDataStorage()->Remove(planeNode);
87 
88  renderingManager->InitializeViews();
89 
90  // create and render three dimensional surface
91  vtkCubeSource *cube = vtkCubeSource::New();
92  cube->SetBounds(cubeBounds);
93  cube->SetCenter(0.0, 0.0, 0.0);
94 
95  vtkPolyData *polyCube = cube->GetOutput();
97  mitkCube->SetVtkPolyData(polyCube);
98  cube->Delete();
99 
101  cubeNode->SetData(mitkCube);
102 
103  renderingManager->GetDataStorage()->Add(cubeNode);
104 
106  cubeGeometry->SetFloatBounds(cubeBounds);
107 
108  MITK_TEST_CONDITION(renderingManager->InitializeViews(cubeGeometry),
109  "Testing if three dimensional Geometry3Ds can be displayed")
110 
111  // clear rendering
112  renderingManager->GetDataStorage()->Remove(cubeNode);
113 
114  renderingManager->InitializeViews();
115  }
116 
117  static void TestAddRemoveRenderWindow()
118  {
120 
121  // mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New();
122 
123  // myRenderingManager->SetDataStorage(ds);
124 
125  {
126  vtkRenderWindow *vtkRenWin = vtkRenderWindow::New();
127 
128  MITK_TEST_CONDITION_REQUIRED(myRenderingManager->GetAllRegisteredRenderWindows().size() == 0,
129  "Render window list must be empty")
130 
131  // Add Render Window
132  myRenderingManager->AddRenderWindow(vtkRenWin);
133 
134  MITK_TEST_CONDITION_REQUIRED(myRenderingManager->GetAllRegisteredRenderWindows().size() == 1,
135  "Render window list must contain one item")
136 
137  // Remove Render Window
138  myRenderingManager->RemoveRenderWindow(vtkRenWin);
139 
140  MITK_TEST_CONDITION_REQUIRED(myRenderingManager->GetAllRegisteredRenderWindows().size() == 0,
141  "Render window list must be empty")
142 
143  // Test if the Render Window was removed properly. This should not do anything
144  MITK_TEST_OUTPUT(<< "Call RequestUpdate on removed render window")
145  myRenderingManager->RequestUpdate(vtkRenWin);
146  MITK_TEST_OUTPUT(<< "Call ForceImmediateUpdate on removed render window")
147  myRenderingManager->ForceImmediateUpdate(vtkRenWin);
148 
149  MITK_TEST_CONDITION_REQUIRED(myRenderingManager->GetAllRegisteredRenderWindows().size() == 0,
150  "Render window list must be empty")
151 
152  // Delete vtk variable correctly
153  vtkRenWin->Delete();
154  }
155 
156  // Check that the previous calls to RequestUpdate and ForceImmediateUpdate
157  // did not modify the internal vtkRenderWindow list. This should not crash.
158  MITK_TEST_OUTPUT(<< "Call RequestUpdateAll after deleting render window")
159  myRenderingManager->RequestUpdateAll();
160  MITK_TEST_OUTPUT(<< "Call ForceImmediateUpdateAll after deleting render window")
161  myRenderingManager->ForceImmediateUpdateAll();
162  }
163 
164 }; // mitkDataNodeTestClass
165 int mitkRenderingManagerTest(int /* argc */, char * /*argv*/ [])
166 {
167  // always start with this!
168  MITK_TEST_BEGIN("RenderingManager")
169 
170  mitkRenderingManagerTestClass::TestAddRemoveRenderWindow();
171 
173 
174  MITK_TEST_CONDITION_REQUIRED(globalRenderingManager.IsNotNull(), "Testing instantiation of global static instance")
175 
177 
178  MITK_TEST_CONDITION_REQUIRED(myRenderingManager.IsNotNull(), "Testing instantiation of second 'local' instance")
179 
180  MITK_TEST_CONDITION_REQUIRED(myRenderingManager != globalRenderingManager,
181  "Testing whether global instance equals new local instance (must not be!)")
182 
185 
186  myRenderingManager->SetDataStorage(ds);
187 
188  vtkRenderWindow *vtkRenWin = vtkRenderWindow::New();
189  mitk::VtkPropRenderer::Pointer br = mitk::VtkPropRenderer::New("testingBR", vtkRenWin, myRenderingManager);
190 
191  mitk::BaseRenderer::AddInstance(vtkRenWin, br);
192  myRenderingManager->AddRenderWindow(vtkRenWin);
193 
194  MITK_TEST_CONDITION_REQUIRED(br->GetDataStorage() == ds,
195  "Testing if internal DataStorage has been set correctly for registered BaseRenderer")
196  myRenderingManager->SetDataStorage(ds2);
198  br->GetDataStorage() == ds2,
199  "Testing if change of internal DataStorage has been forwarded correctly to registered BaseRenderer")
200 
201  mitkRenderingManagerTestClass::TestPropertyList(myRenderingManager);
202 
203  mitkRenderingManagerTestClass::TestSurfaceLoading(myRenderingManager);
204 
205  // write your own tests here and use the macros from mitkTestingMacros.h !!!
206  // do not write to std::cout and do not return from this function yourself!
207 
208  // Remove Render Window
209  myRenderingManager->RemoveRenderWindow(vtkRenWin);
210 
211  // Delete vtk variable correctly
212  vtkRenWin->Delete();
213 
214  // always end with this!
215  MITK_TEST_END()
216 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkRenderingManagerTest(int, char *[])
static Pointer New()
#define MITK_TEST_OUTPUT(x)
Output some text.
static Pointer New()
static Pointer New()
#define MITK_TEST_CONDITION(COND, MSG)
static RenderingManager * GetInstance()
static Pointer New(const char *_arga, vtkRenderWindow *_argb, mitk::RenderingManager *_argc)
and MITK_TEST_END()
static Pointer New()
static void AddInstance(vtkRenderWindow *renWin, BaseRenderer *baseRenderer)
virtual T GetValue() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.