Skip to content

Commit 40d3069

Browse files
authored
Merge pull request #482 from PaulHax/layer-tf
feat(layers): use opacity transfer function except for PT
2 parents c0296b8 + f9896c7 commit 40d3069

File tree

6 files changed

+58
-17
lines changed

6 files changed

+58
-17
lines changed

src/components/VtkTwoView.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ import {
245245
WL_HIST_BINS,
246246
} from '../constants';
247247
import { useProxyManager } from '../composables/proxyManager';
248+
import { getShiftedOpacityFromPreset } from '../utils/vtk-helpers';
248249
import { useLayersStore } from '../store/datasets-layers';
249250
import { useViewCameraStore } from '../store/view-configs/camera';
250251
import useLayerColoringStore from '../store/view-configs/layers';
@@ -815,7 +816,28 @@ export default defineComponent({
815816
const pwf = proxyManager.getPiecewiseFunction(arrayName);
816817
pwf.setMode(vtkPiecewiseFunctionProxy.Mode.Points);
817818
pwf.setDataRange(...opFunc.mappingRange);
818-
pwf.setPoints([[0, 1]]); // only slice mesh controls opacity
819+
820+
switch (opFunc.mode) {
821+
case vtkPiecewiseFunctionProxy.Mode.Gaussians:
822+
pwf.setGaussians(opFunc.gaussians);
823+
break;
824+
case vtkPiecewiseFunctionProxy.Mode.Points: {
825+
const opacityPoints = getShiftedOpacityFromPreset(
826+
opFunc.preset,
827+
opFunc.mappingRange,
828+
opFunc.shift
829+
);
830+
if (opacityPoints) {
831+
pwf.setPoints(opacityPoints);
832+
}
833+
break;
834+
}
835+
case vtkPiecewiseFunctionProxy.Mode.Nodes:
836+
pwf.setNodes(opFunc.nodes);
837+
break;
838+
default:
839+
}
840+
819841
rep.setOpacity(blendConfig.opacity);
820842
821843
// control color range manually

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ export const DEFAULT_PRESET_BY_MODALITY: Record<string, string> = {
255255
MR: 'CT-Coronary-Arteries-2',
256256
US: 'US-Fetal',
257257
};
258+
export const DEFAULT_PRESET = 'CT-AAA';
259+
260+
export const LAYER_PRESET_BY_MODALITY: Record<string, string> = {
261+
...DEFAULT_PRESET_BY_MODALITY,
262+
PT: '2hot-opaque',
263+
};
264+
export const LAYER_PRESET_DEFAULT = 'Blue to Red Rainbow';
258265

259266
// Keyboard shortcuts/hotkeys. Can add modifiers: 'Shift+Ctrl+A'
260267
export const ACTION_TO_KEY = {

src/store/view-configs/layers.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@ import {
1414
} from '@/src/utils/doubleKeyRecord';
1515
import { Maybe } from '@/src/types';
1616
import { identity } from '@/src/utils';
17+
import { LAYER_PRESET_BY_MODALITY, LAYER_PRESET_DEFAULT } from '@/src/config';
1718
import { createViewConfigSerializer } from './common';
18-
import { DEFAULT_PRESET } from '../../vtk/ColorMaps';
1919
import { ViewConfig } from '../../io/state-file/schema';
2020
import { LayersConfig } from './types';
2121
import { LayerID, useLayersStore } from '../datasets-layers';
2222
import { useDICOMStore } from '../datasets-dicom';
2323

24-
export const MODALITY_TO_PRESET: Record<string, string> = {
25-
PT: '2hot',
26-
};
27-
2824
function getPreset(id: LayerID) {
2925
const layersStore = useLayersStore();
3026
const layer = layersStore.getLayer(id);
31-
if (layer) {
32-
if (layer.selection.type === 'dicom') {
33-
const dicomStore = useDICOMStore();
34-
const { Modality = undefined } =
35-
dicomStore.volumeInfo[layer.selection.volumeKey];
36-
return (Modality && MODALITY_TO_PRESET[Modality]) || DEFAULT_PRESET;
37-
}
27+
if (!layer) {
28+
throw new Error(`Layer ${id} not found`);
29+
}
30+
31+
if (layer.selection.type === 'dicom') {
32+
const dicomStore = useDICOMStore();
33+
const { Modality = undefined } =
34+
dicomStore.volumeInfo[layer.selection.volumeKey];
35+
return (
36+
(Modality && LAYER_PRESET_BY_MODALITY[Modality]) || LAYER_PRESET_DEFAULT
37+
);
3838
}
39-
return DEFAULT_PRESET;
39+
40+
return LAYER_PRESET_DEFAULT;
4041
}
4142

4243
export const defaultLayersConfig = (): LayersConfig => ({

src/store/view-configs/volume-coloring.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getColorFunctionRangeFromPreset,
55
getOpacityFunctionFromPreset,
66
} from '@/src/utils/vtk-helpers';
7-
import { DEFAULT_PRESET_BY_MODALITY } from '@/src/config';
7+
import { DEFAULT_PRESET_BY_MODALITY, DEFAULT_PRESET } from '@/src/config';
88
import { ColorTransferFunction } from '@/src/types/views';
99
import { defineStore } from 'pinia';
1010
import { reactive } from 'vue';
@@ -17,7 +17,6 @@ import {
1717
import { DeepPartial, Maybe } from '@/src/types';
1818
import { identity } from '@/src/utils';
1919
import { createViewConfigSerializer } from './common';
20-
import { DEFAULT_PRESET } from '../../vtk/ColorMaps';
2120
import { ViewConfig } from '../../io/state-file/schema';
2221
import { VolumeColorConfig } from './types';
2322
import { useDICOMStore } from '../datasets-dicom';

src/vtk/ColorMaps.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ function registerPresets(presets: typeof MedicalPresets) {
99

1010
registerPresets(MedicalPresets);
1111

12+
const twoHotOpaque = {
13+
...vtkColorMaps.getPresetByName('2hot'),
14+
Name: '2hot-opaque',
15+
OpacityPoints: [0, 1],
16+
};
17+
vtkColorMaps.addPreset(twoHotOpaque);
18+
1219
/* prettier-ignore */
1320
const GroupedPresets = [
1421
{
@@ -61,6 +68,5 @@ const GroupedPresets = [
6168
},
6269
];
6370

64-
export const DEFAULT_PRESET = 'CT-AAA';
6571
export const PresetNameList = GroupedPresets.flatMap((group) => group.presets);
6672
export default GroupedPresets;

src/vtk/MedicalColorPresets.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,5 +1518,11 @@
15181518
1,
15191519
1
15201520
]
1521+
},
1522+
{
1523+
"ColorSpace" : "HSV",
1524+
"Name" : "Blue to Red Rainbow",
1525+
"NanColor" : [ 0.498039215686, 0.498039215686, 0.498039215686 ],
1526+
"RGBPoints" : [ 0, 0, 0, 1, 1, 1, 0, 0 ]
15211527
}
15221528
]

0 commit comments

Comments
 (0)