forked from Slicer/SlicerGitSVNArchive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vtkMRMLScalarVolumeNode.cxx
175 lines (155 loc) · 5.73 KB
/
vtkMRMLScalarVolumeNode.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
/*=auto=========================================================================
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Program: 3D Slicer
Module: $RCSfile: vtkMRMLVolumeNode.cxx,v $
Date: $Date: 2006/03/17 17:01:53 $
Version: $Revision: 1.14 $
=========================================================================auto=*/
// MRML includes
#include "vtkCodedEntry.h"
#include "vtkMRMLScalarVolumeDisplayNode.h"
#include "vtkMRMLScalarVolumeNode.h"
#include "vtkMRMLScene.h"
#include "vtkMRMLVolumeArchetypeStorageNode.h"
// VTK includes
#include <vtkDataArray.h>
#include <vtkObjectFactory.h>
#include <vtkImageData.h>
#include <vtkNew.h>
#include <vtkPointData.h>
//----------------------------------------------------------------------------
vtkMRMLNodeNewMacro(vtkMRMLScalarVolumeNode);
vtkCxxSetObjectMacro(vtkMRMLScalarVolumeNode, VoxelValueQuantity, vtkCodedEntry);
vtkCxxSetObjectMacro(vtkMRMLScalarVolumeNode, VoxelValueUnits, vtkCodedEntry);
//----------------------------------------------------------------------------
vtkMRMLScalarVolumeNode::vtkMRMLScalarVolumeNode()
: VoxelValueQuantity(NULL)
, VoxelValueUnits(NULL)
{
}
//----------------------------------------------------------------------------
vtkMRMLScalarVolumeNode::~vtkMRMLScalarVolumeNode()
{
this->SetVoxelValueQuantity(NULL);
this->SetVoxelValueUnits(NULL);
}
//----------------------------------------------------------------------------
void vtkMRMLScalarVolumeNode::WriteXML(ostream& of, int nIndent)
{
Superclass::WriteXML(of, nIndent);
if (this->GetVoxelValueQuantity())
{
of << " voxelValueQuantity=\"" << vtkMRMLNode::URLEncodeString(this->GetVoxelValueQuantity()->GetAsString().c_str()) << "\"";
}
if (this->GetVoxelValueUnits())
{
of << " voxelValueUnits=\"" << vtkMRMLNode::URLEncodeString(this->GetVoxelValueUnits()->GetAsString().c_str()) << "\"";
}
}
//----------------------------------------------------------------------------
void vtkMRMLScalarVolumeNode::ReadXMLAttributes(const char** atts)
{
int disabledModify = this->StartModify();
Superclass::ReadXMLAttributes(atts);
// For backward compatibility, we read the labelMap attribute and save it as a custom attribute.
// This allows scene reader to detect that this node has to be converted to a segmentation node.
const char* attName;
const char* attValue;
while (*atts != NULL)
{
attName = *(atts++);
attValue = *(atts++);
if (!strcmp(attName, "labelMap"))
{
std::stringstream ss;
int val;
ss << attValue;
ss >> val;
if (val)
{
this->SetAttribute("LabelMap", "1");
}
}
else if (!strcmp(attName, "voxelValueQuantity"))
{
vtkNew<vtkCodedEntry> entry;
entry->SetFromString(vtkMRMLNode::URLDecodeString(attValue));
this->SetVoxelValueQuantity(entry.GetPointer());
}
else if (!strcmp(attName, "voxelValueUnits"))
{
vtkNew<vtkCodedEntry> entry;
entry->SetFromString(vtkMRMLNode::URLDecodeString(attValue));
this->SetVoxelValueUnits(entry.GetPointer());
}
}
this->EndModify(disabledModify);
}
//----------------------------------------------------------------------------
// Copy the node's attributes to this object.
// Does NOT copy: ID, FilePrefix, Name, VolumeID
void vtkMRMLScalarVolumeNode::Copy(vtkMRMLNode *anode)
{
Superclass::Copy(anode);
}
//-----------------------------------------------------------
void vtkMRMLScalarVolumeNode::CreateNoneNode(vtkMRMLScene *scene)
{
// Create a None volume RGBA of 0, 0, 0 so the filters won't complain
// about missing input
vtkNew<vtkImageData> id;
id->SetDimensions(1, 1, 1);
id->AllocateScalars(VTK_DOUBLE, 4);
id->GetPointData()->GetScalars()->FillComponent(0, 0.0);
id->GetPointData()->GetScalars()->FillComponent(1, 125.0);
id->GetPointData()->GetScalars()->FillComponent(2, 0.0);
id->GetPointData()->GetScalars()->FillComponent(3, 0.0);
vtkNew<vtkMRMLScalarVolumeNode> n;
n->SetName("None");
// the scene will set the id
n->SetAndObserveImageData(id.GetPointer());
scene->AddNode(n.GetPointer());
}
//----------------------------------------------------------------------------
vtkMRMLScalarVolumeDisplayNode* vtkMRMLScalarVolumeNode::GetScalarVolumeDisplayNode()
{
return vtkMRMLScalarVolumeDisplayNode::SafeDownCast(this->GetDisplayNode());
}
//----------------------------------------------------------------------------
void vtkMRMLScalarVolumeNode::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os,indent);
if (this->GetVoxelValueQuantity())
{
os << indent << "VoxelValueQuantity: " << this->GetVoxelValueQuantity()->GetAsPrintableString() << "\n";
}
if (this->GetVoxelValueUnits())
{
os << indent << "VoxelValueUnits: " << this->GetVoxelValueUnits()->GetAsPrintableString() << "\n";
}
}
//---------------------------------------------------------------------------
vtkMRMLStorageNode* vtkMRMLScalarVolumeNode::CreateDefaultStorageNode()
{
return vtkMRMLVolumeArchetypeStorageNode::New();
}
//----------------------------------------------------------------------------
void vtkMRMLScalarVolumeNode::CreateDefaultDisplayNodes()
{
if (vtkMRMLScalarVolumeDisplayNode::SafeDownCast(this->GetDisplayNode())!=NULL)
{
// display node already exists
return;
}
if (this->GetScene()==NULL)
{
vtkErrorMacro("vtkMRMLScalarVolumeNode::CreateDefaultDisplayNodes failed: scene is invalid");
return;
}
vtkNew<vtkMRMLScalarVolumeDisplayNode> dispNode;
this->GetScene()->AddNode(dispNode.GetPointer());
dispNode->SetDefaultColorMap();
this->SetAndObserveDisplayNodeID(dispNode->GetID());
}