-
Notifications
You must be signed in to change notification settings - Fork 256
/
index.ts
273 lines (225 loc) · 7.28 KB
/
index.ts
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import {
RenderingEngine,
Types,
Enums,
volumeLoader,
getRenderingEngine,
CONSTANTS,
} from '@cornerstonejs/core';
import {
initDemo,
createImageIdsAndCacheMetaData,
setTitleAndDescription,
addButtonToToolbar,
addDropdownToToolbar,
setCtTransferFunctionForVolumeActor,
setPetColorMapTransferFunctionForVolumeActor,
} from '../../../../utils/demo/helpers';
// This is for debugging purposes
console.warn(
'Click on index.ts to open source code for this example --------->'
);
const { ViewportType } = Enums;
const { ORIENTATION } = CONSTANTS;
const renderingEngineId = 'myRenderingEngine';
const viewportId = 'CT_SAGITTAL_STACK';
// Define unique ids for the volumes
const volumeLoaderScheme = 'cornerstoneStreamingImageVolume'; // Loader id which defines which volume loader to use
const ctVolumeName = 'CT_VOLUME_ID'; // Id of the volume less loader prefix
const ctVolumeId = `${volumeLoaderScheme}:${ctVolumeName}`; // VolumeId with loader id + volume id
// Define a unique id for the volume
const ptVolumeName = 'PT_VOLUME_ID';
const ptVolumeId = `${volumeLoaderScheme}:${ptVolumeName}`;
// ======== Set up page ======== //
setTitleAndDescription(
'Volume Viewport API With Multiple Volumes',
'Demonstrates how to interact with a Volume viewport when using fusion.'
);
const content = document.getElementById('content');
const element = document.createElement('div');
element.id = 'cornerstone-element';
element.style.width = '500px';
element.style.height = '500px';
content.appendChild(element);
// ============================= //
// TODO -> Maybe some of these implementations should be pushed down to some API
// Buttons
addButtonToToolbar({
title: 'Set CT VOI Range',
onClick: () => {
// Get the rendering engine
const renderingEngine = getRenderingEngine(renderingEngineId);
// Get the stack viewport
const viewport = <Types.IVolumeViewport>(
renderingEngine.getViewport(viewportId)
);
// Get the volume actor from the viewport
const actorEntry = viewport.getActor(ctVolumeId);
// Set the mapping range of the actor to a range to highlight bones
const volumeActor = actorEntry.actor as Types.VolumeActor;
volumeActor
.getProperty()
.getRGBTransferFunction(0)
.setMappingRange(-1500, 2500);
viewport.render();
},
});
addButtonToToolbar({
title: 'Reset Viewport',
onClick: () => {
// Get the rendering engine
const renderingEngine = getRenderingEngine(renderingEngineId);
// Get the volume viewport
const viewport = <Types.IVolumeViewport>(
renderingEngine.getViewport(viewportId)
);
// Resets the viewport's camera
viewport.resetCamera();
// TODO reset the viewport properties, we don't have API for this.
viewport.render();
},
});
let fused = false;
addButtonToToolbar({
title: 'toggle PET',
onClick: () => {
// Get the rendering engine
const renderingEngine = getRenderingEngine(renderingEngineId);
// Get the volume viewport
const viewport = <Types.IVolumeViewport>(
renderingEngine.getViewport(viewportId)
);
if (fused) {
// Removes the PT actor from the scene
viewport.removeVolumeActors([ptVolumeId], true);
fused = false;
} else {
// Add the PET volume to the viewport. It is in the same DICOM Frame Of Reference/worldspace
// If it was in a different frame of reference, you would need to register it first.
viewport.addVolumes(
[
{
volumeId: ptVolumeId,
callback: setPetColorMapTransferFunctionForVolumeActor,
},
],
true
);
fused = true;
}
},
});
const orientationOptions = {
axial: 'axial',
sagittal: 'sagittal',
coronal: 'coronal',
oblique: 'oblique',
};
addDropdownToToolbar({
options: {
values: ['axial', 'sagittal', 'coronal', 'oblique'],
defaultValue: 'sagittal',
},
onSelectedValueChange: (selectedValue) => {
// Get the rendering engine
const renderingEngine = getRenderingEngine(renderingEngineId);
// Get the volume viewport
const viewport = <Types.IVolumeViewport>(
renderingEngine.getViewport(viewportId)
);
// TODO -> Maybe we should rename sliceNormal to viewPlaneNormal everywhere?
let viewUp;
let viewPlaneNormal;
switch (selectedValue) {
case orientationOptions.axial:
viewUp = ORIENTATION.AXIAL.viewUp;
viewPlaneNormal = ORIENTATION.AXIAL.sliceNormal;
break;
case orientationOptions.sagittal:
viewUp = ORIENTATION.SAGITTAL.viewUp;
viewPlaneNormal = ORIENTATION.SAGITTAL.sliceNormal;
break;
case orientationOptions.coronal:
viewUp = ORIENTATION.CORONAL.viewUp;
viewPlaneNormal = ORIENTATION.CORONAL.sliceNormal;
break;
case orientationOptions.oblique:
// Some random oblique value for this dataset
viewUp = [-0.5962687530844388, 0.5453181550345819, -0.5891448751239446];
viewPlaneNormal = [
-0.5962687530844388, 0.5453181550345819, -0.5891448751239446,
];
break;
default:
throw new Error('undefined orientation option');
}
// TODO -> Maybe we should have a helper for this on the viewport
// Set the new orientation
viewport.setCamera({ viewUp, viewPlaneNormal });
// Reset the camera after the normal changes
viewport.resetCamera();
viewport.render();
},
});
/**
* Runs the demo
*/
async function run() {
// Init Cornerstone and related libraries
await initDemo();
const wadoRsRoot = 'https://d1qmxk7r72ysft.cloudfront.net/dicomweb';
const StudyInstanceUID =
'1.3.6.1.4.1.14519.5.2.1.7009.2403.334240657131972136850343327463';
// Get Cornerstone imageIds and fetch metadata into RAM
const ctImageIds = await createImageIdsAndCacheMetaData({
StudyInstanceUID,
SeriesInstanceUID:
'1.3.6.1.4.1.14519.5.2.1.7009.2403.226151125820845824875394858561',
wadoRsRoot,
type: 'VOLUME',
});
const ptImageIds = await createImageIdsAndCacheMetaData({
StudyInstanceUID,
SeriesInstanceUID:
'1.3.6.1.4.1.14519.5.2.1.7009.2403.879445243400782656317561081015',
wadoRsRoot,
type: 'VOLUME',
});
// Instantiate a rendering engine
const renderingEngine = new RenderingEngine(renderingEngineId);
// Create a stack viewport
const viewportInput = {
viewportId,
type: ViewportType.ORTHOGRAPHIC,
element,
defaultOptions: {
orientation: ORIENTATION.SAGITTAL,
background: <Types.Point3>[0.2, 0, 0.2],
},
};
renderingEngine.enableElement(viewportInput);
// Get the stack viewport that was created
const viewport = <Types.IVolumeViewport>(
renderingEngine.getViewport(viewportId)
);
// Define a volume in memory
const ctVolume = await volumeLoader.createAndCacheVolume(ctVolumeId, {
imageIds: ctImageIds,
});
// Set the volume to load
ctVolume.load();
// Set the volume on the viewport
viewport.setVolumes([
{ volumeId: ctVolumeId, callback: setCtTransferFunctionForVolumeActor },
]);
// Render the image
renderingEngine.render();
// Load the PT in the background as we know we'll need it
// Define a volume in memory
const ptVolume = await volumeLoader.createAndCacheVolume(ptVolumeId, {
imageIds: ptImageIds,
});
// Set the volume to load
ptVolume.load();
}
run();