forked from Slicer/SlicerGitSVNArchive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vtkMRMLSceneViewNodeImportSceneTest.cxx
131 lines (101 loc) · 4.4 KB
/
vtkMRMLSceneViewNodeImportSceneTest.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
123
124
125
126
127
128
129
130
131
/*==============================================================================
Program: 3D Slicer
Copyright (c) Kitware Inc.
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.
This file was originally developed by Julien Finet, Kitware Inc.
and was partially funded by NIH grant 3P41RR013218-12S1
==============================================================================*/
// MRML includes
#include "vtkMRMLCoreTestingMacros.h"
#include "vtkMRMLScalarVolumeDisplayNode.h"
#include "vtkMRMLScalarVolumeNode.h"
#include "vtkMRMLScene.h"
#include "vtkMRMLSceneViewNode.h"
// VTK includes
#include <vtkNew.h>
#include <vtkSmartPointer.h>
namespace
{
int populateScene(vtkMRMLScene* scene, bool saveInSceneView)
{
vtkNew<vtkMRMLSceneViewNode> sceneViewtoRegister;
scene->RegisterNodeClass(sceneViewtoRegister.GetPointer());
vtkNew<vtkMRMLScalarVolumeNode> displayableNode;
scene->AddNode(displayableNode.GetPointer());
vtkNew<vtkMRMLScalarVolumeDisplayNode> displayNode;
scene->AddNode(displayNode.GetPointer());
displayableNode->SetAndObserveDisplayNodeID(displayNode->GetID());
if (saveInSceneView)
{
vtkNew<vtkMRMLSceneViewNode> sceneViewNode;
scene->AddNode(sceneViewNode.GetPointer());
sceneViewNode->StoreScene();
}
scene->RemoveNode(displayableNode.GetPointer());
return EXIT_SUCCESS;
}
} // end of anonymous namespace
//---------------------------------------------------------------------------
int vtkMRMLSceneViewNodeImportSceneTest(int vtkNotUsed(argc),
char * vtkNotUsed(argv)[] )
{
// Save a scene containing a viewnode and a sceneview node.
vtkNew<vtkMRMLScene> scene;
CHECK_EXIT_SUCCESS(populateScene(scene.GetPointer(), true));
// scene
// + vtkMRMLScalarVolumeDisplayNode1
// + vtkMRMLSceneViewNode1
// + vtkMRMLScalarVolumeNode1
// -> ref: vtkMRMLScalarVolumeDisplayNode1
// + vtkMRMLScalarVolumeDisplayNode1
scene->SetSaveToXMLString(1);
scene->Commit();
std::string xmlScene = scene->GetSceneXMLString();
std::cout << xmlScene << std::endl;
// Simulate another scene
vtkNew<vtkMRMLScene> scene2;
CHECK_EXIT_SUCCESS(populateScene(scene2.GetPointer(), false));
// scene2
// + vtkMRMLScalarVolumeDisplayNode1
scene2->SetLoadFromXMLString(1);
scene2->SetSceneXMLString(xmlScene);
scene2->Import();
// scene2
// + vtkMRMLScalarVolumeDisplayNode1 (original)
// + vtkMRMLScalarVolumeDisplayNode2 (imported)
// + vtkMRMLSceneViewNode1 (imported)
// + vtkMRMLScalarVolumeNode1
// -> ref: vtkMRMLScalarVolumeDisplayNode2
// + vtkMRMLScalarVolumeDisplayNode2
// Check scene node IDs
vtkMRMLNode* displayNode =
scene2->GetFirstNodeByClass("vtkMRMLScalarVolumeDisplayNode");
vtkMRMLNode* displayNode2 = scene2->GetNthNodeByClass(1, "vtkMRMLScalarVolumeDisplayNode");
vtkMRMLSceneViewNode* sceneViewNode = vtkMRMLSceneViewNode::SafeDownCast(
scene2->GetFirstNodeByClass("vtkMRMLSceneViewNode"));
CHECK_NOT_NULL(displayNode);
CHECK_NOT_NULL(displayNode2);
CHECK_NOT_NULL(sceneViewNode);
CHECK_STRING(displayNode->GetID(), "vtkMRMLScalarVolumeDisplayNode1");
CHECK_STRING(displayNode2->GetID(), "vtkMRMLScalarVolumeDisplayNode2");
CHECK_STRING(sceneViewNode->GetID(), "vtkMRMLSceneViewNode1");
// Check sceneViewNode node IDs.
vtkMRMLNode* sceneViewDisplayNode =
sceneViewNode->GetStoredScene()->GetFirstNodeByClass("vtkMRMLScalarVolumeDisplayNode");
vtkMRMLDisplayableNode* sceneViewDisplayableNode = vtkMRMLDisplayableNode::SafeDownCast(
sceneViewNode->GetStoredScene()->GetFirstNodeByClass("vtkMRMLScalarVolumeNode"));
CHECK_INT(sceneViewNode->GetStoredScene()->GetNumberOfNodes(), 3);
CHECK_NOT_NULL(sceneViewDisplayNode);
CHECK_NOT_NULL(sceneViewDisplayableNode);
CHECK_STRING(sceneViewDisplayNode->GetID(), "vtkMRMLScalarVolumeDisplayNode2");
CHECK_STRING(sceneViewDisplayableNode->GetID(), "vtkMRMLScalarVolumeNode1");
// Check references
CHECK_STRING(sceneViewDisplayableNode->GetNthDisplayNodeID(0), sceneViewDisplayNode->GetID());
return EXIT_SUCCESS;
}