-
Notifications
You must be signed in to change notification settings - Fork 6
/
vtkWindowLevelTool.cxx
165 lines (137 loc) · 4.25 KB
/
vtkWindowLevelTool.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
/*=========================================================================
Program: ToolCursor
Module: vtkWindowLevelTool.cxx
Copyright (c) 2010 David Gobbi
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkWindowLevelTool.h"
#include "vtkObjectFactory.h"
#include "vtkToolCursor.h"
#include "vtkVolumePicker.h"
#include "vtkTransform.h"
#include "vtkRenderer.h"
#include "vtkImageProperty.h"
#include "vtkImageSlice.h"
#include "vtkProp.h"
#include "vtkPropCollection.h"
#include "vtkAssemblyPath.h"
#include "vtkCommand.h"
vtkStandardNewMacro(vtkWindowLevelTool);
//----------------------------------------------------------------------------
vtkWindowLevelTool::vtkWindowLevelTool()
{
this->StartWindowLevel[0] = 1.0;
this->StartWindowLevel[1] = 0.5;
this->CurrentImageProperty = 0;
}
//----------------------------------------------------------------------------
vtkWindowLevelTool::~vtkWindowLevelTool()
{
if (this->CurrentImageProperty)
{
this->CurrentImageProperty->Delete();
}
}
//----------------------------------------------------------------------------
void vtkWindowLevelTool::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
//----------------------------------------------------------------------------
void vtkWindowLevelTool::StartAction()
{
this->Superclass::StartAction();
this->SetCurrentImageToNthImage(-1);
if (this->CurrentImageProperty)
{
vtkImageProperty *property = this->CurrentImageProperty;
this->StartWindowLevel[0] = property->GetColorWindow();
this->StartWindowLevel[1] = property->GetColorLevel();
}
}
//----------------------------------------------------------------------------
void vtkWindowLevelTool::StopAction()
{
this->Superclass::StopAction();
this->InvokeEvent(vtkCommand::EndWindowLevelEvent, this);
}
//----------------------------------------------------------------------------
void vtkWindowLevelTool::DoAction()
{
this->Superclass::DoAction();
vtkToolCursor *cursor = this->GetToolCursor();
// Get the display position.
double x, y, x0, y0;
this->GetStartDisplayPosition(x0, y0);
this->GetDisplayPosition(x, y);
int *size = cursor->GetRenderer()->GetSize();
double window = this->StartWindowLevel[0];
double level = this->StartWindowLevel[1];
level += window*(y - y0)*2.0/(size[1] + 1);
window *= pow(10.0, (x - x0)*2.0/(size[1] + 1));
if (this->CurrentImageProperty)
{
this->CurrentImageProperty->SetColorWindow(window);
this->CurrentImageProperty->SetColorLevel(level);
}
}
//----------------------------------------------------------------------------
void vtkWindowLevelTool::SetCurrentImageToNthImage(int i)
{
// Get all the information needed for the interaction
vtkToolCursor *cursor = this->GetToolCursor();
vtkPropCollection *props = cursor->GetRenderer()->GetViewProps();
vtkProp *prop = 0;
vtkAssemblyPath *path;
vtkImageSlice *imageProp = 0;
vtkCollectionSimpleIterator pit;
for (int k = 0; k < 2; k++)
{
int j = 0;
for (props->InitTraversal(pit); (prop = props->GetNextProp(pit)); )
{
for (prop->InitPathTraversal(); (path = prop->GetNextPath()); )
{
vtkProp *tryProp = path->GetLastNode()->GetViewProp();
if ( tryProp && tryProp->GetPickable() &&
(imageProp = vtkImageSlice::SafeDownCast(tryProp)) != 0 )
{
if (j == i)
{
break;
}
imageProp = 0;
j++;
}
}
if (imageProp)
{
break;
}
}
if (i < 0)
{
i += j;
}
}
vtkImageProperty *property = 0;
if (imageProp)
{
property = imageProp->GetProperty();
}
if (property != this->CurrentImageProperty)
{
if (this->CurrentImageProperty)
{
this->CurrentImageProperty->Delete();
}
this->CurrentImageProperty = property;
if (this->CurrentImageProperty)
{
this->CurrentImageProperty->Register(this);
}
}
}