Skip to content

Commit 4463a59

Browse files
sedghifinetjul
authored andcommitted
fix(volumeMapper): code readability when computed scale is not available
1 parent 70703a1 commit 4463a59

File tree

1 file changed

+32
-28
lines changed
  • Sources/Rendering/OpenGL/VolumeMapper

1 file changed

+32
-28
lines changed

Sources/Rendering/OpenGL/VolumeMapper/index.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -706,34 +706,38 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
706706
const volInfo = model.scalarTexture.getVolumeInfo();
707707
const ipScalarRange = model.renderable.getIpScalarRange();
708708

709-
const minVals = [];
710-
const maxVals = [];
711-
for (let i = 0; i < 4; i++) {
712-
// convert iprange from 0-1 into data range values
713-
minVals[i] =
714-
ipScalarRange[0] * volInfo.dataComputedScale[i] +
715-
volInfo.dataComputedOffset[i];
716-
maxVals[i] =
717-
ipScalarRange[1] * volInfo.dataComputedScale[i] +
718-
volInfo.dataComputedOffset[i];
719-
// convert data ranges into texture values
720-
minVals[i] = (minVals[i] - volInfo.offset[i]) / volInfo.scale[i];
721-
maxVals[i] = (maxVals[i] - volInfo.offset[i]) / volInfo.scale[i];
722-
}
723-
program.setUniform4f(
724-
'ipScalarRangeMin',
725-
minVals[0],
726-
minVals[1],
727-
minVals[2],
728-
minVals[3]
729-
);
730-
program.setUniform4f(
731-
'ipScalarRangeMax',
732-
maxVals[0],
733-
maxVals[1],
734-
maxVals[2],
735-
maxVals[3]
736-
);
709+
// In some situations, we might not have computed the scale and offset
710+
// for the data range, or it might not be needed.
711+
if (volInfo.dataComputedScale?.length) {
712+
const minVals = [];
713+
const maxVals = [];
714+
for (let i = 0; i < 4; i++) {
715+
// convert iprange from 0-1 into data range values
716+
minVals[i] =
717+
ipScalarRange[0] * volInfo.dataComputedScale[i] +
718+
volInfo.dataComputedOffset[i];
719+
maxVals[i] =
720+
ipScalarRange[1] * volInfo.dataComputedScale[i] +
721+
volInfo.dataComputedOffset[i];
722+
// convert data ranges into texture values
723+
minVals[i] = (minVals[i] - volInfo.offset[i]) / volInfo.scale[i];
724+
maxVals[i] = (maxVals[i] - volInfo.offset[i]) / volInfo.scale[i];
725+
}
726+
program.setUniform4f(
727+
'ipScalarRangeMin',
728+
minVals[0],
729+
minVals[1],
730+
minVals[2],
731+
minVals[3]
732+
);
733+
program.setUniform4f(
734+
'ipScalarRangeMax',
735+
maxVals[0],
736+
maxVals[1],
737+
maxVals[2],
738+
maxVals[3]
739+
);
740+
}
737741

738742
// if we have a zbuffer texture then set it
739743
if (model.zBufferTexture !== null) {

0 commit comments

Comments
 (0)