Skip to content

Commit 2ccba3e

Browse files
fix(ImageMapper): Consider all components when computing fn string
1 parent 8166f2a commit 2ccba3e

1 file changed

Lines changed: 54 additions & 28 deletions

File tree

  • Sources/Rendering/OpenGL/ImageMapper

Sources/Rendering/OpenGL/ImageMapper/index.js

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ const { vtkErrorMacro } = macro;
2222

2323
const { SlicingMode } = Constants;
2424

25+
// ----------------------------------------------------------------------------
26+
// helper methods
27+
// ----------------------------------------------------------------------------
28+
29+
function computeFnToString(property, fn, numberOfComponents) {
30+
let pwfun = fn.apply(property);
31+
if (pwfun) {
32+
const iComps = property.getIndependentComponents();
33+
let pwfunToString = `${property.getMTime()}-${iComps}-0-${pwfun.getMTime()}`;
34+
if (iComps) {
35+
for (let c = 1; c < numberOfComponents; c++) {
36+
pwfun = fn.apply(property, [c]);
37+
if (pwfun) {
38+
pwfunToString += `-${c}-${pwfun.getMTime()}`;
39+
} else {
40+
pwfunToString += `-${c}-none`;
41+
}
42+
}
43+
}
44+
return pwfunToString;
45+
}
46+
return '0';
47+
}
48+
2549
// ----------------------------------------------------------------------------
2650
// vtkOpenGLImageMapper methods
2751
// ----------------------------------------------------------------------------
@@ -622,13 +646,18 @@ function vtkOpenGLImageMapper(publicAPI, model) {
622646
const numIComps = iComps ? numComp : 1;
623647
const textureHeight = iComps ? 2 * numIComps : 1;
624648

625-
const cWidth = 1024;
626-
let cfun = actorProperty.getRGBTransferFunction();
627-
const cSize = cWidth * textureHeight * 3;
628-
const cTable = new Uint8Array(cSize);
629-
if (cfun) {
630-
const cfunToString = `${cfun.getMTime()}-${actorProperty.getMTime()}-${numComp}-${iComps}`;
631-
if (model.colorTextureString !== cfunToString) {
649+
const cfunToString = computeFnToString(
650+
actorProperty,
651+
actorProperty.getRGBTransferFunction,
652+
numIComps
653+
);
654+
655+
if (model.colorTextureString !== cfunToString) {
656+
const cWidth = 1024;
657+
const cSize = cWidth * textureHeight * 3;
658+
const cTable = new Uint8Array(cSize);
659+
let cfun = actorProperty.getRGBTransferFunction();
660+
if (cfun) {
632661
const tmpTable = new Float32Array(cWidth * 3);
633662

634663
for (let c = 0; c < numIComps; c++) {
@@ -646,25 +675,19 @@ function vtkOpenGLImageMapper(publicAPI, model) {
646675
}
647676
}
648677
}
649-
model.colorTextureString = cfunToString;
650-
651678
model.colorTexture.create2DFromRaw(
652679
cWidth,
653680
textureHeight,
654681
3,
655682
VtkDataTypes.UNSIGNED_CHAR,
656683
cTable
657684
);
658-
}
659-
} else {
660-
const cfunToString = '0';
661-
if (model.colorTextureString !== cfunToString) {
685+
} else {
662686
for (let i = 0; i < cWidth * 3; ++i) {
663687
cTable[i] = (255.0 * i) / ((cWidth - 1) * 3);
664688
cTable[i + 1] = (255.0 * i) / ((cWidth - 1) * 3);
665689
cTable[i + 2] = (255.0 * i) / ((cWidth - 1) * 3);
666690
}
667-
model.colorTextureString = cfunToString;
668691
model.colorTexture.create2DFromRaw(
669692
cWidth,
670693
1,
@@ -673,18 +696,25 @@ function vtkOpenGLImageMapper(publicAPI, model) {
673696
cTable
674697
);
675698
}
699+
700+
model.colorTextureString = cfunToString;
676701
}
677702

678703
// Build piecewise function buffer. This buffer is used either
679704
// for component weighting or opacity, depending on whether we're
680705
// rendering components independently or not.
681-
const pwfWidth = 1024;
682-
let pwfun = actorProperty.getPiecewiseFunction();
683-
const pwfSize = pwfWidth * textureHeight;
684-
const pwfTable = new Uint8Array(pwfSize);
685-
if (pwfun) {
686-
const pwfunToString = `${pwfun.getMTime()}-${actorProperty.getMTime()}-${numComp}-${iComps}`;
687-
if (model.pwfTextureString !== pwfunToString) {
706+
const pwfunToString = computeFnToString(
707+
actorProperty,
708+
actorProperty.getPiecewiseFunction,
709+
numIComps
710+
);
711+
712+
if (model.pwfTextureString !== pwfunToString) {
713+
const pwfWidth = 1024;
714+
const pwfSize = pwfWidth * textureHeight;
715+
const pwfTable = new Uint8Array(pwfSize);
716+
let pwfun = actorProperty.getPiecewiseFunction();
717+
if (pwfun) {
688718
const pwfFloatTable = new Float32Array(pwfSize);
689719
const tmpTable = new Float32Array(pwfWidth);
690720

@@ -710,22 +740,16 @@ function vtkOpenGLImageMapper(publicAPI, model) {
710740
}
711741
}
712742
}
713-
714-
model.pwfTextureString = pwfunToString;
715743
model.pwfTexture.create2DFromRaw(
716744
pwfWidth,
717745
textureHeight,
718746
1,
719747
VtkDataTypes.FLOAT,
720748
pwfFloatTable
721749
);
722-
}
723-
} else {
724-
const pwfunToString = '0';
725-
if (model.pwfTextureString !== pwfunToString) {
750+
} else {
726751
// default is opaque
727752
pwfTable.fill(255.0);
728-
model.pwfTextureString = pwfunToString;
729753
model.pwfTexture.create2DFromRaw(
730754
pwfWidth,
731755
1,
@@ -734,6 +758,8 @@ function vtkOpenGLImageMapper(publicAPI, model) {
734758
pwfTable
735759
);
736760
}
761+
762+
model.pwfTextureString = pwfunToString;
737763
}
738764

739765
// Find what IJK axis and what direction to slice along

0 commit comments

Comments
 (0)