Skip to content

Commit 27890ef

Browse files
committed
refactor: Move functions out of the volumeMapper publicAPI
1 parent e22d1e1 commit 27890ef

File tree

1 file changed

+35
-29
lines changed
  • Sources/Rendering/OpenGL/VolumeMapper

1 file changed

+35
-29
lines changed

Sources/Rendering/OpenGL/VolumeMapper/index.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
123123
// Set our className
124124
model.classHierarchy.push('vtkOpenGLVolumeMapper');
125125

126+
function useIndependentComponents(actorProperty, image) {
127+
const iComps = actorProperty.getIndependentComponents();
128+
const numComp = image
129+
?.getPointData()
130+
?.getScalars()
131+
?.getNumberOfComponents();
132+
const colorMixPreset = actorProperty.getColorMixPreset();
133+
return (iComps && numComp >= 2) || !!colorMixPreset;
134+
}
135+
136+
function isLabelmapOutlineRequired(actorProperty) {
137+
return (
138+
actorProperty.getUseLabelOutline() ||
139+
model.renderable.getBlendMode() ===
140+
BlendMode.LABELMAP_EDGE_PROJECTION_BLEND
141+
);
142+
}
143+
126144
function unregisterGraphicsResources(renderWindow) {
127145
[
128146
model._scalars,
@@ -190,17 +208,6 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
190208
shaders.Geometry = '';
191209
};
192210

193-
publicAPI.useIndependentComponents = (actorProperty) => {
194-
const iComps = actorProperty.getIndependentComponents();
195-
const image = model.currentInput;
196-
const numComp = image
197-
?.getPointData()
198-
?.getScalars()
199-
?.getNumberOfComponents();
200-
const colorMixPreset = actorProperty.getColorMixPreset();
201-
return (iComps && numComp >= 2) || !!colorMixPreset;
202-
};
203-
204211
publicAPI.replaceShaderValues = (shaders, ren, actor) => {
205212
const actorProps = actor.getProperty();
206213
let FSSource = shaders.Fragment;
@@ -215,7 +222,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
215222
).result;
216223
}
217224

218-
const vtkImageLabelOutline = publicAPI.isLabelmapOutlineRequired(actor);
225+
const vtkImageLabelOutline = isLabelmapOutlineRequired(actorProps);
219226
if (vtkImageLabelOutline === true) {
220227
FSSource = vtkShaderProgram.substitute(
221228
FSSource,
@@ -243,7 +250,10 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
243250
`#define vtkNumComponents ${numComp}`
244251
).result;
245252

246-
const useIndependentComps = publicAPI.useIndependentComponents(actorProps);
253+
const useIndependentComps = useIndependentComponents(
254+
actorProps,
255+
model.currentInput
256+
);
247257
if (useIndependentComps) {
248258
FSSource = vtkShaderProgram.substitute(
249259
FSSource,
@@ -907,7 +917,8 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
907917
program.setUniformf(`vPlaneDistance${i}`, dist);
908918
}
909919

910-
if (publicAPI.isLabelmapOutlineRequired(actor)) {
920+
const vprop = actor.getProperty();
921+
if (isLabelmapOutlineRequired(vprop)) {
911922
const image = model.currentInput;
912923
const worldToIndex = image.getWorldToIndex();
913924

@@ -1017,7 +1028,6 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
10171028
program.setUniformfv('lightExponent', lightExponent);
10181029
program.setUniformiv('lightPositional', lightPositional);
10191030
}
1020-
const vprop = actor.getProperty();
10211031
if (vprop.getVolumetricScatteringBlending() > 0.0) {
10221032
program.setUniformf('giReach', vprop.getGlobalIlluminationReach());
10231033
program.setUniformf(
@@ -1060,7 +1070,10 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
10601070

10611071
// set the component mix when independent
10621072
const numComp = model.scalarTexture.getComponents();
1063-
const useIndependentComps = publicAPI.useIndependentComponents(vprop);
1073+
const useIndependentComps = useIndependentComponents(
1074+
vprop,
1075+
model.currentInput
1076+
);
10641077
if (useIndependentComps) {
10651078
for (let i = 0; i < numComp; i++) {
10661079
program.setUniformf(
@@ -1141,9 +1154,9 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
11411154
}
11421155
}
11431156

1144-
const vtkImageLabelOutline = publicAPI.isLabelmapOutlineRequired(actor);
1157+
const vtkImageLabelOutline = isLabelmapOutlineRequired(vprop);
11451158
if (vtkImageLabelOutline === true) {
1146-
const labelOutlineOpacity = actor.getProperty().getLabelOutlineOpacity();
1159+
const labelOutlineOpacity = vprop.getLabelOutlineOpacity();
11471160
program.setUniformf('outlineOpacity', labelOutlineOpacity);
11481161
}
11491162

@@ -1520,7 +1533,10 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
15201533
}
15211534

15221535
const numComp = scalars.getNumberOfComponents();
1523-
const useIndependentComps = publicAPI.useIndependentComponents(vprop);
1536+
const useIndependentComps = useIndependentComponents(
1537+
vprop,
1538+
model.currentInput
1539+
);
15241540
const numIComps = useIndependentComps ? numComp : 1;
15251541

15261542
const scalarOpacityFunc = vprop.getScalarOpacity();
@@ -1854,16 +1870,6 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
18541870
model.labelOutlineThicknessTexture = lTex.oglObject;
18551871
}
18561872
};
1857-
1858-
publicAPI.isLabelmapOutlineRequired = (actor) => {
1859-
const prop = actor.getProperty();
1860-
const renderable = model.renderable;
1861-
1862-
return (
1863-
prop.getUseLabelOutline() ||
1864-
renderable.getBlendMode() === BlendMode.LABELMAP_EDGE_PROJECTION_BLEND
1865-
);
1866-
};
18671873
}
18681874

18691875
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)