forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetViewport_test.js
More file actions
224 lines (172 loc) · 4.58 KB
/
Copy pathsetViewport_test.js
File metadata and controls
224 lines (172 loc) · 4.58 KB
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
import { assert } from 'chai'; // eslint-disable-line import/extensions
import enable from '../src/enable.js';
import displayImage from '../src/displayImage.js';
import setViewport from '../src/setViewport.js';
import getViewport from '../src/getViewport.js';
import disable from '../src/disable.js';
const MIN_WINDOW_WIDTH = 0.000001;
const MIN_VIEWPORT_SCALE = 0.0001;
describe('Set an enabled element\'s viewport', function () {
beforeEach(function () {
// Arrange
this.element = document.createElement('div');
const options = {};
const height = 2;
const width = 2;
const getPixelData = () => new Uint8Array([0, 255, 255, 0]);
this.image = {
imageId: 'exampleImageId',
minPixelValue: 0,
maxPixelValue: 255,
slope: 1.0,
intercept: 0,
windowCenter: 127,
windowWidth: 256,
getPixelData,
rows: height,
columns: width,
height,
width,
color: false,
sizeInBytes: width * height * 2
};
this.viewport = {
scale: 2.0,
translation: {
x: 1,
y: 1
},
voi: {
windowWidth: 10,
windowCenter: 15
},
invert: true,
pixelReplication: true,
rotation: 90,
hflip: true,
vflip: true
};
enable(this.element, options);
});
it('should apply viewport settings if provided', function () {
// Act
displayImage(this.element, this.image, this.viewport);
const element = this.element;
const newViewport = {
scale: 3.0,
translation: {
x: 2,
y: 2
},
voi: {
windowWidth: 11,
windowCenter: 16
},
invert: false,
pixelReplication: false,
rotation: 91,
hflip: false,
vflip: false
};
// Act
setViewport(element, newViewport);
// Assert
const viewport = getViewport(element);
Object.keys(newViewport).forEach((key) => {
assert.deepEqual(newViewport[key], viewport[key]);
});
});
it('should prevent windowWidth from getting too small', function () {
// Act
displayImage(this.element, this.image, this.viewport);
const element = this.element;
// Arrange
this.viewport.voi.windowWidth = 0.0000000000001;
// Act
setViewport(element, this.viewport);
// Assert
const viewport = getViewport(element);
assert.equal(viewport.voi.windowWidth, MIN_WINDOW_WIDTH);
});
it('should prevent scale from getting too small', function () {
// Act
displayImage(this.element, this.image, this.viewport);
const element = this.element;
// Arrange
this.viewport.scale = 0.0000000000001;
// Act
setViewport(element, this.viewport);
// Assert
const viewport = getViewport(element);
assert.equal(viewport.scale, MIN_VIEWPORT_SCALE);
});
it('should normalize rotation values above 359 degrees', function () {
// Act
displayImage(this.element, this.image, this.viewport);
const element = this.element;
// Arrange
this.viewport.rotation = 365;
// Act
setViewport(element, this.viewport);
// Assert
const viewport = getViewport(element);
assert.equal(viewport.rotation, 5);
});
it('should normalize rotation values below 0 degrees', function () {
// Act
displayImage(this.element, this.image, this.viewport);
const element = this.element;
// Arrange
this.viewport.rotation = -5;
// Act
setViewport(element, this.viewport);
// Assert
const viewport = getViewport(element);
assert.equal(viewport.rotation, 355);
});
it('should apply initial viewport settings with no displayed image', function () {
const element = this.element;
const newViewport = {
scale: 3.0,
translation: {
x: 2,
y: 2
},
voi: {
windowWidth: 11,
windowCenter: 16
},
invert: false,
pixelReplication: false,
rotation: 91,
hflip: false,
vflip: false,
displayedArea: {
// Top Left Hand Corner
tlhc: {
x: 10,
y: 9
},
// Bottom Right Hand Corner
brhc: {
x: 3,
y: 2
},
rowPixelSpacing: 5,
columnPixelSpacing: 4,
presentationSizeMode: ''
}
};
// Act
setViewport(element, newViewport);
displayImage(this.element, this.image);
// Assert
const viewport = getViewport(element);
Object.keys(newViewport).forEach((key) => {
assert.deepEqual(newViewport[key], viewport[key]);
});
});
afterEach(function () {
disable(this.element);
});
});