forked from Slicer/SlicerGitSVNArchive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vtkMRMLTensorVolumeNode.cxx
226 lines (195 loc) · 5.86 KB
/
vtkMRMLTensorVolumeNode.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*=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 "vtkMRMLDiffusionTensorVolumeDisplayNode.h"
#include "vtkMRMLNRRDStorageNode.h"
#include "vtkMRMLScene.h"
#include "vtkMRMLTensorVolumeNode.h"
// VTK includes
#include <vtkImageData.h>
#include <vtkObjectFactory.h>
#include <vtkMatrix4x4.h>
//----------------------------------------------------------------------------
vtkMRMLNodeNewMacro(vtkMRMLTensorVolumeNode);
//----------------------------------------------------------------------------
vtkMRMLTensorVolumeNode::vtkMRMLTensorVolumeNode()
{
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
this->MeasurementFrameMatrix[i][j] = (i == j) ? 1.0 : 0.0;
}
}
this->Order = -1; //Tensor order
}
//----------------------------------------------------------------------------
vtkMRMLTensorVolumeNode::~vtkMRMLTensorVolumeNode() = default;
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::WriteXML(ostream& of, int nIndent)
{
Superclass::WriteXML(of, nIndent);
std::stringstream ss;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
ss << this->MeasurementFrameMatrix[i][j] << " ";
if ( i != 2 && j != 2 )
{
ss << " ";
}
}
}
of << " measurementFrame=\"" << ss.str() << "\"";
of << " order=\"" << Order << "\"";
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::ReadXMLAttributes(const char** atts)
{
int disabledModify = this->StartModify();
Superclass::ReadXMLAttributes(atts);
const char* attName;
const char* attValue;
while (*atts != nullptr)
{
attName = *(atts++);
attValue = *(atts++);
if (!strcmp(attName, "measurementFrame"))
{
std::stringstream ss;
double val;
ss << attValue;
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
ss >> val;
this->MeasurementFrameMatrix[i][j] = val;
}
}
}
if (!strcmp(attName, "order"))
{
std::stringstream ss;
ss << attValue;
ss >> Order;
}
}
this->EndModify(disabledModify);
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::SetMeasurementFrameMatrix(const double mf[3][3])
{
for (int i=0; i<3; i++)
{
for (int j=0; j<3; j++)
{
this->MeasurementFrameMatrix[i][j] = mf[i][j];
}
}
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::GetMeasurementFrameMatrix(double mf[3][3])
{
for (int i=0; i<3; i++)
{
for (int j=0; j<3; j++)
{
mf[i][j]= this->MeasurementFrameMatrix[i][j];
}
}
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::SetMeasurementFrameMatrix(vtkMatrix4x4 *mf)
{
for (int i=0; i<3; i++)
{
for (int j=0; j<3; j++)
{
this->MeasurementFrameMatrix[i][j]=mf->GetElement(i,j);
}
}
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::GetMeasurementFrameMatrix(vtkMatrix4x4 *mf)
{
mf->Identity();
for (int i=0; i<3; i++)
{
for (int j=0; j<3; j++)
{
mf->SetElement(i,j,this->MeasurementFrameMatrix[i][j]);
}
}
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::SetMeasurementFrameMatrix(const double xr, const double xa, const double xs,
const double yr, const double ya, const double ys,
const double zr, const double za, const double zs)
{
MeasurementFrameMatrix[0][0] = xr;
MeasurementFrameMatrix[0][1] = xa;
MeasurementFrameMatrix[0][2] = xs;
MeasurementFrameMatrix[1][0] = yr;
MeasurementFrameMatrix[1][1] = ya;
MeasurementFrameMatrix[1][2] = ys;
MeasurementFrameMatrix[2][0] = zr;
MeasurementFrameMatrix[2][1] = za;
MeasurementFrameMatrix[2][2] = zs;
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::CopyContent(vtkMRMLNode* anode, bool deepCopy/*=true*/)
{
MRMLNodeModifyBlocker blocker(this);
Superclass::CopyContent(anode, deepCopy);
vtkMRMLTensorVolumeNode* node = vtkMRMLTensorVolumeNode::SafeDownCast(anode);
if (!node)
{
return;
}
// Matrices
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
this->MeasurementFrameMatrix[i][j] = node->MeasurementFrameMatrix[i][j];
}
}
this->Order = node->Order;
}
//----------------------------------------------------------------------------
void vtkMRMLTensorVolumeNode::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os,indent);
os << "MeasurementFrameMatrix:\n";
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
os << indent << " " << this->MeasurementFrameMatrix[i][j];
}
os << indent << "\n";
}
os << "\n";
os << "Order: "<<this->Order;
}
//----------------------------------------------------------------------------
vtkMRMLStorageNode* vtkMRMLTensorVolumeNode::CreateDefaultStorageNode()
{
vtkMRMLScene* scene = this->GetScene();
if (scene == nullptr)
{
vtkErrorMacro("CreateDefaultStorageNode failed: scene is invalid");
return nullptr;
}
return vtkMRMLStorageNode::SafeDownCast(
scene->CreateNodeByClass("vtkMRMLNRRDStorageNode"));
}