Skip to content

Commit

Permalink
fix(VtkTwoView): layer opacity driven only by slice mesh opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 11, 2023
1 parent 6b26933 commit 3ec7ba3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 49 deletions.
52 changes: 3 additions & 49 deletions src/components/VtkTwoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ import useViewSliceStore, {
import CropTool from './tools/crop/CropTool.vue';
import { ToolContainer, VTKTwoViewWidgetManager } from '../constants';
import { useProxyManager } from '../composables/proxyManager';
import { getShiftedOpacityFromPreset } from '../utils/vtk-helpers';
import { useLayersStore } from '../store/datasets-layers';
import { useViewCameraStore } from '../store/view-configs/camera';
import useLayerColoringStore from '../store/view-configs/layers';
Expand Down Expand Up @@ -703,55 +702,10 @@ export default defineComponent({
lut.setDataRange(...ctFunc.mappingRange);
const pwf = proxyManager.getPiecewiseFunction(arrayName);
pwf.setMode(opFunc.mode);
pwf.setMode(vtkPiecewiseFunctionProxy.Mode.Points);
pwf.setDataRange(...opFunc.mappingRange);
const factor = blendConfig.opacity * 2;
const floor = Math.max(0, (blendConfig.opacity - 0.5) * 2);
switch (opFunc.mode) {
case vtkPiecewiseFunctionProxy.Mode.Gaussians: {
const mapped = opFunc.gaussians.map((g) => {
return {
...g,
height: g.height * factor,
yBias: blendConfig.opacity * 2,
};
});
pwf.setGaussians(mapped);
break;
}
case vtkPiecewiseFunctionProxy.Mode.Points: {
const opacityPoints = getShiftedOpacityFromPreset(
opFunc.preset,
opFunc.mappingRange,
opFunc.shift
);
if (!opacityPoints) {
throw new Error(`Could not find preset ${opFunc.preset}`);
}
const mapped = opacityPoints.map(([x, y]) => [
x,
y * factor + floor,
]);
pwf.setPoints(mapped);
break;
}
case vtkPiecewiseFunctionProxy.Mode.Nodes: {
const mappedNodes = opFunc.nodes.map((n) => {
return {
...n,
y: n.y * factor + floor,
} as const;
});
pwf.setNodes(mappedNodes);
break;
}
default:
throw new Error(
// @ts-expect-error should handle all modes
`invalid opacity function mode ${opFunc.mode}`
);
}
pwf.setPoints([[0, 1]]); // only slice mesh controls opacity
rep.setOpacity(blendConfig.opacity);
// control color range manually
rep.setRescaleOnColorBy(false);
Expand Down
1 change: 1 addition & 0 deletions src/store/view-configs/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const defaultLayersConfig = (): LayersConfig => ({
preset: '',
mappingRange: [0, 1],
},
// opacity function not used in VtkTwoView
opacityFunction: {
mode: vtkPiecewiseFunctionProxy.Mode.Gaussians,
gaussians: [],
Expand Down

0 comments on commit 3ec7ba3

Please sign in to comment.