This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.js
89 lines (67 loc) · 3.27 KB
/
main.js
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
var VolumeRenderingPlugin = class VolumeRenderingPlugin extends OHIF.plugins.ViewportPlugin {
constructor(options = {}) {
super("VolumeRenderingPlugin");
this.description = "VolumeRendering OHIF Plugin";
OHIF.plugins.VTKDataCache = OHIF.plugins.VTKDataCache || {};
OHIF.plugins.VTKDataCache.imageDataCache = new Map;
}
setup() {
console.warn(`${this.name}: Setup Complete`);
}
setupViewport(div, { viewportIndex = 0 }, displaySet) {
console.warn(`${this.name}|setupViewport: viewportIndex: ${viewportIndex}`);
if (!displaySet) {
displaySet = OHIF.plugins.ViewportPlugin.getDisplaySet(viewportIndex);
}
const { VTKUtils } = window;
const imageDataObject = VTKUtils.getImageData(displaySet);
const imageData = imageDataObject.vtkImageData;
div.innerHTML = '';
const volumeViewer = vtk.Rendering.Misc.vtkGenericRenderWindow.newInstance({
background: [0, 0, 0],
});
volumeViewer.setContainer(div);
// TODO: VTK's canvas currently does not fill the viewport element
// after it has been resized. We need to set the height to 100% and
// trigger volumeViewer.resize() whenever things are resized.
// We might need to find a way to hook onto the OHIF Viewer ResizeManager
// div.querySelector('canvas').style.height = '100%';
volumeViewer.resize();
const actor = VolumeRenderingPlugin.setupVTKActor(imageData);
VTKUtils.installVTKViewer(volumeViewer, actor);
}
static setupVTKActor(imageData) {
const mapper = vtk.Rendering.Core.vtkVolumeMapper.newInstance();
mapper.setInputData(imageData);
const actor = vtk.Rendering.Core.vtkVolume.newInstance();
actor.setMapper(mapper);
// create color and opacity transfer functions
const ctfun = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
ctfun.addRGBPoint(10.0, 0.4, 0.2, 0.0);
ctfun.addRGBPoint(100.0, 1.0, 1.0, 1.0);
const ofun = vtk.Common.DataModel.vtkPiecewiseFunction.newInstance();
ofun.addPoint(0.0, 0.0);
ofun.addPoint(200.0, 0.9);
ofun.addPoint(1000.0, 0.9);
actor.getProperty().setRGBTransferFunction(0, ctfun);
actor.getProperty().setScalarOpacity(0, ofun);
actor.getProperty().setScalarOpacityUnitDistance(0, 4.5);
actor.getProperty().setInterpolationTypeToLinear();
actor.getProperty().setUseGradientOpacity(0, true);
actor.getProperty().setGradientOpacityMinimumValue(0, 15);
actor.getProperty().setGradientOpacityMinimumOpacity(0, 0.0);
actor.getProperty().setGradientOpacityMaximumValue(0, 100);
actor.getProperty().setGradientOpacityMaximumOpacity(0, 1.0);
//actor.getProperty().setShade(true);
actor.getProperty().setAmbient(0.7);
actor.getProperty().setDiffuse(0.7);
actor.getProperty().setSpecular(0.3);
actor.getProperty().setSpecularPower(8.0);
return actor;
}
};
OHIF.plugins.entryPoints["VolumeRenderingPlugin"] = function () {
const volumeRenderingPlugin = new VolumeRenderingPlugin();
volumeRenderingPlugin.setup();
OHIF.plugins.VolumeRenderingPlugin = volumeRenderingPlugin;
};