forked from Slicer/SlicerGitSVNArchive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vtkMRMLVectorVolumeDisplayNode.cxx
179 lines (143 loc) · 5.58 KB
/
vtkMRMLVectorVolumeDisplayNode.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
/*=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: vtkMRMLVectorVolumeDisplayNode.cxx,v $
Date: $Date: 2006/03/17 15:10:10 $
Version: $Revision: 1.2 $
=========================================================================auto=*/
// MRML includes
#include "vtkMRMLVectorVolumeDisplayNode.h"
// VTK includes
#include <vtkObjectFactory.h>
#include <vtkImageAppendComponents.h>
#include <vtkImageCast.h>
#include <vtkImageData.h>
#include <vtkImageExtractComponents.h>
#include <vtkImageRGBToHSI.h>
#include <vtkImageShiftScale.h>
#include <vtkImageStencil.h>
#include <vtkImageThreshold.h>
#include <vtkVersion.h>
// STD includes
#include <sstream>
//----------------------------------------------------------------------------
vtkMRMLNodeNewMacro(vtkMRMLVectorVolumeDisplayNode);
//----------------------------------------------------------------------------
vtkMRMLVectorVolumeDisplayNode::vtkMRMLVectorVolumeDisplayNode()
{
this->ScalarMode = this->scalarModeMagnitude;
this->GlyphMode = this->glyphModeLines;
this->ShiftScale = vtkImageShiftScale::New();
this->RGBToHSI = vtkImageRGBToHSI::New();
this->ExtractIntensity = vtkImageExtractComponents::New();
this->ShiftScale->SetOutputScalarTypeToUnsignedChar();
this->ShiftScale->SetClampOverflow(1);
this->ExtractIntensity->SetInputConnection( this->RGBToHSI->GetOutputPort() );
this->ExtractIntensity->SetComponents( 2 );
this->Threshold->SetInputConnection( this->ExtractIntensity->GetOutputPort() );
this->AppendComponents->RemoveAllInputs();
this->AppendComponents->AddInputConnection(0, this->ShiftScale->GetOutputPort());
this->AppendComponents->AddInputConnection(0, this->MultiplyAlpha->GetOutputPort());
this->MultiplyAlpha->RemoveAllInputs();
this->MultiplyAlpha->SetInputConnection(0, this->Threshold->GetOutputPort() );
}
//----------------------------------------------------------------------------
vtkMRMLVectorVolumeDisplayNode::~vtkMRMLVectorVolumeDisplayNode()
{
this->ShiftScale->Delete();
this->RGBToHSI->Delete();
this->ExtractIntensity->Delete();
}
//----------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::SetInputToImageDataPipeline(vtkAlgorithmOutput *imageDataConnection)
{
this->ShiftScale->SetInputConnection(imageDataConnection);
this->RGBToHSI->SetInputConnection(imageDataConnection);
}
//----------------------------------------------------------------------------
vtkAlgorithmOutput* vtkMRMLVectorVolumeDisplayNode::GetInputImageDataConnection()
{
return this->ShiftScale->GetNumberOfInputConnections(0) ?
this->ShiftScale->GetInputConnection(0,0) : nullptr;
}
//---------------------------------------------------------------------------
vtkAlgorithmOutput* vtkMRMLVectorVolumeDisplayNode::GetScalarImageDataConnection()
{
return this->GetInputImageDataConnection();
}
//----------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::UpdateImageDataPipeline()
{
Superclass::UpdateImageDataPipeline();
double halfWindow = (this->GetWindow() / 2.);
double min = this->GetLevel() - halfWindow;
this->ShiftScale->SetShift ( -min );
this->ShiftScale->SetScale ( 255. / (this->GetWindow()) );
}
//----------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::WriteXML(ostream& of, int nIndent)
{
Superclass::WriteXML(of, nIndent);
std::stringstream ss;
ss.clear();
ss << this->ScalarMode;
of << " scalarMode=\"" << ss.str() << "\"";
ss.clear();
ss << this->GlyphMode;
of << " glyphMode=\"" << ss.str() << "\"";
}
//----------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::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, "scalarMode"))
{
std::stringstream ss;
ss << attValue;
ss >> this->ScalarMode;
}
else if (!strcmp(attName, "glyphMode"))
{
std::stringstream ss;
ss << attValue;
ss >> this->GlyphMode;
}
}
this->EndModify(disabledModify);
}
//----------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::CopyContent(vtkMRMLNode* anode, bool deepCopy/*=true*/)
{
MRMLNodeModifyBlocker blocker(this);
Superclass::CopyContent(anode, deepCopy);
vtkMRMLVectorVolumeDisplayNode *node = vtkMRMLVectorVolumeDisplayNode::SafeDownCast(anode);
if (!node)
{
return;
}
this->SetScalarMode(node->ScalarMode);
this->SetGlyphMode(node->GlyphMode);
}
//----------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os,indent);
os << indent << "Scalar Mode: " << this->ScalarMode << "\n";
os << indent << "Glyph Mode: " << this->GlyphMode << "\n";
}
//---------------------------------------------------------------------------
void vtkMRMLVectorVolumeDisplayNode::ProcessMRMLEvents ( vtkObject *caller,
unsigned long event,
void *callData )
{
Superclass::ProcessMRMLEvents(caller, event, callData);
}