-
Notifications
You must be signed in to change notification settings - Fork 1
/
vtkMRML4DVolumeNode.cxx
191 lines (159 loc) · 5.35 KB
/
vtkMRML4DVolumeNode.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*=auto=========================================================================
Portions (c) Copyright 2009 Brigham and Women's Hospital (BWH) All Rights Reserved.
See Doc/copyright/copyright.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Program: 3D Slicer
Module: $RCSfile: vtkMRMLOsteoPlanNode.cxx,v $
Date: $Date: 2006/03/17 15:10:10 $
Version: $Revision: 1.2 $
=========================================================================auto=*/
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include "vtkObjectFactory.h"
#include "vtkMRML4DVolumeNode.h"
#include "vtkMRMLScene.h"
#include "vtkMRMLNode.h"
#include "vtkMRMLScalarVolumeNode.h"
#include "vtkObjectFactory.h"
#include "vtkCollection.h"
//------------------------------------------------------------------------------
vtkMRML4DVolumeNode* vtkMRML4DVolumeNode::New()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkObjectFactory::CreateInstance("vtkMRML4DVolumeNode");
if(ret)
{
return (vtkMRML4DVolumeNode*)ret;
}
// If the factory was unable to create the object, then create it here.
return new vtkMRML4DVolumeNode;
}
//----------------------------------------------------------------------------
vtkMRMLNode* vtkMRML4DVolumeNode::CreateNodeInstance()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkObjectFactory::CreateInstance("vtkMRML4DVolumeNode");
if(ret)
{
return (vtkMRML4DVolumeNode*)ret;
}
// If the factory was unable to create the object, then create it here.
return new vtkMRML4DVolumeNode;
}
//----------------------------------------------------------------------------
vtkMRML4DVolumeNode::vtkMRML4DVolumeNode()
{
this->VolumeCollection = vtkCollection::New();
this->SerieID = "";
}
//----------------------------------------------------------------------------
vtkMRML4DVolumeNode::~vtkMRML4DVolumeNode()
{
if(this->VolumeCollection)
{
// Do NOT delete nodes inside vtkCollection, because if you load the scene later,
// Slicer will try to delete these nodes too (because it loaded them)
this->VolumeCollection->RemoveAllItems();
this->VolumeCollection->Delete();
}
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::WriteXML(ostream& of, int nIndent)
{
Superclass::WriteXML(of, nIndent);
vtkIndent indent(nIndent);
std::stringstream ss;
ss << this->GetSerieID();
of << indent << " SerieID=\"" << ss.str() << "\"";
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::ReadXMLAttributes(const char** atts)
{
int disableModify = this->StartModify();
Superclass::ReadXMLAttributes(atts);
const char* attName;
const char* attValue;
while(*atts != NULL)
{
attName = *(atts++);
attValue = *(atts++);
if(!strcmp(attName, "SerieID"))
{
std::stringstream sid(attValue);
this->SetSerieID(sid.str().c_str());
}
}
this->EndModify(disableModify);
}
//----------------------------------------------------------------------------
// Copy the node's attributes to this object.
// Does NOT copy: ID, FilePrefix, Name, VolumeID
void vtkMRML4DVolumeNode::Copy(vtkMRMLNode *anode)
{
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::PrintSelf(ostream& os, vtkIndent indent)
{
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::AddVolume(vtkMRMLScalarVolumeNode* NodeToAdd)
{
if(this->VolumeCollection && NodeToAdd)
{
this->VolumeCollection->AddItem(NodeToAdd);
}
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::InsertVolume(int position, vtkMRMLScalarVolumeNode* NodeToInsert)
{
if(this->VolumeCollection && NodeToInsert)
{
if(position >= 0 && position < this->VolumeCollection->GetNumberOfItems())
{
this->VolumeCollection->InsertItem(position, NodeToInsert);
}
}
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::RemoveVolume(vtkMRMLScalarVolumeNode* NodeToRemove)
{
if(this->VolumeCollection && NodeToRemove)
{
this->VolumeCollection->RemoveItem(NodeToRemove);
}
}
//----------------------------------------------------------------------------
void vtkMRML4DVolumeNode::RemoveVolume(int position)
{
if(this->VolumeCollection)
{
if(position >= 0 && position < this->VolumeCollection->GetNumberOfItems())
{
this->VolumeCollection->RemoveItem(position);
}
}
}
//----------------------------------------------------------------------------
int vtkMRML4DVolumeNode::GetNumberOfVolumes()
{
if(this->VolumeCollection)
{
return this->VolumeCollection->GetNumberOfItems();
}
return -1;
}
//----------------------------------------------------------------------------
vtkMRMLScalarVolumeNode* vtkMRML4DVolumeNode::GetItemAsVolume(int position)
{
if(this->VolumeCollection)
{
if(position >= 0 && position < this->VolumeCollection->GetNumberOfItems())
{
vtkMRMLScalarVolumeNode* VolumeSelected = vtkMRMLScalarVolumeNode::SafeDownCast(this->VolumeCollection->GetItemAsObject(position));
return VolumeSelected;
}
}
return NULL;
}