Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDispatcherTest.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 "itkLightObject.h"
18 #include "mitkBaseRenderer.h"
19 #include "mitkDataInteractor.h"
20 #include "mitkDataNode.h"
21 #include "mitkDispatcher.h"
23 #include "mitkTestingMacros.h"
24 #include "mitkVtkPropRenderer.h"
25 
26 int mitkDispatcherTest(int /*argc*/, char * /*argv*/ [])
27 {
28  MITK_TEST_BEGIN("Dispatcher")
29 
30  /*
31  * Tests the process of creating Interactors and assigning DataNodes to them.
32  * Test checks if these Interactors are added to the Dispatcher under different conditions,
33  * and in different call order.
34  */
35 
36  // Here BindDispatcherInteractor and Dispatcher should be created automatically
37  vtkRenderWindow *renWin = vtkRenderWindow::New();
40 
43 
44  dn = mitk::DataNode::New();
48 
49  MITK_TEST_CONDITION_REQUIRED(renderer->GetDispatcher()->GetNumberOfInteractors() == 0,
50  "01 Check Existence of Dispatcher.");
51 
52  ei->SetDataNode(dn);
53  renderer->SetDataStorage(ds);
54  ds->Add(dn);
55 
56  int num = renderer->GetDispatcher()->GetNumberOfInteractors();
57  MITK_TEST_CONDITION_REQUIRED(num == 1, "02 Number of registered Interactors " << num << " , expected 1");
58 
59  // This _must not_ result in additionally registered interactors.
60  ei->SetDataNode(dn);
61  ei->SetDataNode(dn);
62 
63  num = renderer->GetDispatcher()->GetNumberOfInteractors();
64  MITK_TEST_CONDITION_REQUIRED(num == 1, "03 Number of registered Interactors " << num << " , expected 1");
65 
66  // Switching the DataNode of an Interactor also must not result in extra registered Interactors in Dispatcher
67  // since dn2 is not connected to DataStorage
68  // ei will be dropped from dispatcher
69  ei->SetDataNode(dn2);
70 
71  num = renderer->GetDispatcher()->GetNumberOfInteractors();
72  MITK_TEST_CONDITION_REQUIRED(num == 0, "04 Number of registered Interactors " << num << " , expected 0");
73 
74  // DataNode Added to DataStorage, now Interactor entry in Dispatcher should be replaced,
75  // hence we restore Interactor in the Dispatcher
76  ds->Add(dn2);
77 
78  num = renderer->GetDispatcher()->GetNumberOfInteractors();
79  MITK_TEST_CONDITION_REQUIRED(num == 1, "05 Number of registered Interactors " << num << " , expected 1");
80 
81  // New DataNode and new interactor, this should result in additional Interactor in the Dispatcher.
82 
83  ei2->SetDataNode(dn);
84 
85  num = renderer->GetDispatcher()->GetNumberOfInteractors();
86  MITK_TEST_CONDITION_REQUIRED(num == 2, "06 Number of registered Interactors " << num << " , expected 2");
87 
88  // Here ei and ei2 point to the same dn2; dn2 now only points to ei2, so ei is abandoned,
89  // therefore ei1 is expected to be removed
90 
91  ei2->SetDataNode(dn2);
92  num = renderer->GetDispatcher()->GetNumberOfInteractors();
93  MITK_TEST_CONDITION_REQUIRED(num == 1, "07 Number of registered Interactors " << num << " , expected 1");
94 
95  // Setting DataNode in Interactor to NULL, should remove Interactor from Dispatcher
96  ei2->SetDataNode(NULL);
97  num = renderer->GetDispatcher()->GetNumberOfInteractors();
98  MITK_TEST_CONDITION_REQUIRED(num == 0, "08 Number of registered Interactors " << num << " , expected 0");
99 
100  // Add DN again check if it is registered
101 
102  ei2->SetDataNode(dn);
103 
104  num = renderer->GetDispatcher()->GetNumberOfInteractors();
105  MITK_TEST_CONDITION_REQUIRED(num == 1, "09 Number of registered Interactors " << num << " , expected 1");
106 
107  // If DN is removed Interactors should be too
108  ds->Remove(dn);
109  num = renderer->GetDispatcher()->GetNumberOfInteractors();
110  MITK_TEST_CONDITION_REQUIRED(num == 0, "10 Number of registered Interactors " << num << " , expected 0");
111 
112  // after DN is removed from DS its reference count must be back to one
113 
114  MITK_TEST_CONDITION_REQUIRED(dn->GetReferenceCount() == 1,
115  "10 Number of references of DataNode " << num << " , expected 1");
116 
117  MITK_TEST_CONDITION_REQUIRED(ei->GetReferenceCount() == 1,
118  "11 Number of references of Interactors " << num << " , expected 1");
119 
120  renWin->Delete();
121  // always end with this!
122  MITK_TEST_END()
123 }
static Pointer New()
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static Pointer New()
static RenderingManager * GetInstance()
static Pointer New(const char *_arga, vtkRenderWindow *_argb, mitk::RenderingManager *_argc)
int mitkDispatcherTest(int, char *[])
and MITK_TEST_END()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.