forked from Slicer/SlicerGitSVNArchive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vtkMRMLDisplayableHierarchyLogicTest1.cxx
123 lines (102 loc) · 3.83 KB
/
vtkMRMLDisplayableHierarchyLogicTest1.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*==============================================================================
Program: 3D Slicer
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
// MRMLLogic includes
#include "vtkMRMLDisplayableHierarchyLogic.h"
// MRML includes
#include "vtkMRMLDisplayableHierarchyNode.h"
#include "vtkMRMLModelNode.h"
#include "vtkMRMLScene.h"
#include "vtkMRMLCoreTestingMacros.h"
int vtkMRMLDisplayableHierarchyLogicTest1(int , char * [] )
{
vtkNew<vtkMRMLScene> scene;
vtkMRMLDisplayableHierarchyLogic* displayableHierarchyLogic = vtkMRMLDisplayableHierarchyLogic::New();
displayableHierarchyLogic->SetDebug(1);
displayableHierarchyLogic->SetMRMLScene(scene.GetPointer());
// test null pointers
char *id = displayableHierarchyLogic->AddDisplayableHierarchyNodeForNode(NULL);
if (id != NULL)
{
std::cerr << "AddDisplayableHierarchyNodeForNode did not return null for a null node" << std::endl;
return EXIT_FAILURE;
}
bool flag = displayableHierarchyLogic->AddChildToParent(NULL, NULL);
if (flag != false)
{
std::cerr << "AddChildToParent did not fail for null nodes" << std::endl;
return EXIT_FAILURE;
}
// make a couple of nodes
vtkMRMLModelNode *m1 = vtkMRMLModelNode::New();
scene->AddNode(m1);
vtkMRMLModelNode *m2 = vtkMRMLModelNode::New();
scene->AddNode(m2);
id = displayableHierarchyLogic->AddDisplayableHierarchyNodeForNode(m1);
if (id == NULL)
{
std::cerr << "AddDisplayableHierarchyNodeForNode returned null for valid node " << m1->GetID() << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Added a displayable hierarchy with id " << id << " for node " << m1->GetID() << std::endl;
}
flag = displayableHierarchyLogic->AddChildToParent(m1, m2);
if (flag == false)
{
std::cerr << "AddChildToParent failed for m1 " << m1->GetID() << ", and m2 " << m2->GetID() << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "AddChildToParent added hierarchies to make m1 " << m1->GetID() << " a child of m2 " << m2->GetID() << std::endl;
}
vtkMRMLHierarchyNode* h1 = vtkMRMLHierarchyNode::GetAssociatedHierarchyNode(scene.GetPointer(), m1->GetID());
if (!h1)
{
std::cerr << "GetAssociatedHierarchyNode failed for m1 " << m1->GetID() << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Found hierarchy node for m1 with id " << h1->GetID() << std::endl;
}
vtkMRMLHierarchyNode* h2 = vtkMRMLHierarchyNode::GetAssociatedHierarchyNode(scene.GetPointer(), m2->GetID());
if (!h2)
{
std::cerr << "GetAssociatedHierarchyNode failed for m2 " << m2->GetID() << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Found hierarchy node for m2 with id " << h2->GetID() << std::endl;
}
int numChildren = h2->GetNumberOfChildrenNodes();
if (numChildren != 1)
{
std::cerr << "GetNumberOfChildrenNodes failed for h2, expected 1 but got " << numChildren << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "m2's hierarchy node has " << numChildren << " children nodes" << std::endl;
}
bool retval = displayableHierarchyLogic->DeleteHierarchyNodeAndChildren(vtkMRMLDisplayableHierarchyNode::SafeDownCast(h2));
if (!retval)
{
std::cerr << "Failed to delete hierarchy node and children!" << std::endl;
return EXIT_FAILURE;
}
m1->Delete();
m2->Delete();
displayableHierarchyLogic->Delete();
return EXIT_SUCCESS;
}