forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkSlicerViewControllersLogic.cxx
159 lines (140 loc) · 5.6 KB
/
vtkSlicerViewControllersLogic.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*==============================================================================
Program: 3D Slicer
Portions (c) Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
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 Csaba Pinter, PerkLab, Queen's University
and was supported through the Applied Cancer Research Unit program of Cancer Care
Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
==============================================================================*/
// SliceViewControllers Logic includes
#include "vtkSlicerViewControllersLogic.h"
// MRML includes
#include <vtkMRMLPlotViewNode.h>
#include <vtkMRMLScene.h>
#include <vtkMRMLSliceNode.h>
#include <vtkMRMLViewNode.h>
// VTK includes
#include <vtkNew.h>
#include <vtkObjectFactory.h>
// STD includes
#include <cassert>
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkSlicerViewControllersLogic);
//----------------------------------------------------------------------------
vtkSlicerViewControllersLogic::vtkSlicerViewControllersLogic() = default;
//----------------------------------------------------------------------------
vtkSlicerViewControllersLogic::~vtkSlicerViewControllersLogic() = default;
//----------------------------------------------------------------------------
void vtkSlicerViewControllersLogic::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
void vtkSlicerViewControllersLogic::RegisterNodes()
{
vtkMRMLScene *scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("vtkSlicerViewControllersLogic::RegisterNodes failed: invalid scene");
return;
}
}
//-----------------------------------------------------------------------------
vtkMRMLSliceNode* vtkSlicerViewControllersLogic::GetDefaultSliceViewNode()
{
vtkMRMLScene *scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("vtkSlicerViewControllersLogic::GetDefaultSliceViewNode failed: invalid scene");
return nullptr;
}
vtkMRMLNode* defaultNode = scene->GetDefaultNodeByClass("vtkMRMLSliceNode");
if (!defaultNode)
{
defaultNode = scene->CreateNodeByClass("vtkMRMLSliceNode");
scene->AddDefaultNode(defaultNode);
defaultNode->Delete(); // scene owns it now
}
return vtkMRMLSliceNode::SafeDownCast(defaultNode);
}
//-----------------------------------------------------------------------------
vtkMRMLViewNode* vtkSlicerViewControllersLogic::GetDefaultThreeDViewNode()
{
vtkMRMLScene *scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("vtkSlicerViewControllersLogic::GetDefaultThreeDViewNode failed: invalid scene");
return nullptr;
}
vtkMRMLNode* defaultNode = scene->GetDefaultNodeByClass("vtkMRMLViewNode");
if (!defaultNode)
{
defaultNode = scene->CreateNodeByClass("vtkMRMLViewNode");
scene->AddDefaultNode(defaultNode);
defaultNode->Delete(); // scene owns it now
}
return vtkMRMLViewNode::SafeDownCast(defaultNode);
}
//-----------------------------------------------------------------------------
vtkMRMLPlotViewNode *vtkSlicerViewControllersLogic::GetDefaultPlotViewNode()
{
vtkMRMLScene *scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("vtkSlicerViewControllersLogic::GetDefaultPlotViewNode failed: invalid scene");
return nullptr;
}
vtkMRMLNode* defaultNode = scene->GetDefaultNodeByClass("vtkMRMLPlotViewNode");
if (!defaultNode)
{
defaultNode = scene->CreateNodeByClass("vtkMRMLPlotViewNode");
scene->AddDefaultNode(defaultNode);
defaultNode->Delete(); // scene owns it now
}
return vtkMRMLPlotViewNode::SafeDownCast(defaultNode);
}
//-----------------------------------------------------------------------------
void vtkSlicerViewControllersLogic::ResetAllViewNodesToDefault()
{
vtkMRMLScene *scene = this->GetMRMLScene();
if (!scene)
{
vtkErrorMacro("vtkSlicerViewControllersLogic::ResetAllViewNodesToDefault failed: invalid scene");
return;
}
scene->StartState(vtkMRMLScene::BatchProcessState);
vtkMRMLSliceNode* defaultSliceViewNode = GetDefaultSliceViewNode();
std::vector< vtkMRMLNode* > viewNodes;
scene->GetNodesByClass("vtkMRMLSliceNode", viewNodes);
for (std::vector< vtkMRMLNode* >::iterator it = viewNodes.begin(); it != viewNodes.end(); ++it)
{
vtkMRMLSliceNode* sliceNode = vtkMRMLSliceNode::SafeDownCast(*it);
if (!sliceNode)
{
continue;
}
sliceNode->Reset(defaultSliceViewNode);
sliceNode->SetOrientationToDefault();
}
viewNodes.clear();
vtkMRMLViewNode* defaultThreeDViewNode = GetDefaultThreeDViewNode();
scene->GetNodesByClass("vtkMRMLViewNode", viewNodes);
for (std::vector< vtkMRMLNode* >::iterator it = viewNodes.begin(); it != viewNodes.end(); ++it)
{
(*it)->Reset(defaultThreeDViewNode);
}
viewNodes.clear();
vtkMRMLPlotViewNode* defaultPlotViewNode = GetDefaultPlotViewNode();
scene->GetNodesByClass("vtkMRMLPlotViewNode", viewNodes);
for (std::vector< vtkMRMLNode* >::iterator it = viewNodes.begin(); it != viewNodes.end(); ++it)
{
(*it)->Reset(defaultPlotViewNode);
}
scene->EndState(vtkMRMLScene::BatchProcessState);
}