Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/components/VtkTwoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ import {
WL_HIST_BINS,
} 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 @@ -815,7 +816,28 @@ export default defineComponent({
const pwf = proxyManager.getPiecewiseFunction(arrayName);
pwf.setMode(vtkPiecewiseFunctionProxy.Mode.Points);
pwf.setDataRange(...opFunc.mappingRange);
pwf.setPoints([[0, 1]]); // only slice mesh controls opacity

switch (opFunc.mode) {
case vtkPiecewiseFunctionProxy.Mode.Gaussians:
pwf.setGaussians(opFunc.gaussians);
break;
case vtkPiecewiseFunctionProxy.Mode.Points: {
const opacityPoints = getShiftedOpacityFromPreset(
opFunc.preset,
opFunc.mappingRange,
opFunc.shift
);
if (opacityPoints) {
pwf.setPoints(opacityPoints);
}
break;
}
case vtkPiecewiseFunctionProxy.Mode.Nodes:
pwf.setNodes(opFunc.nodes);
break;
default:
}

rep.setOpacity(blendConfig.opacity);

// control color range manually
Expand Down
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ export const DEFAULT_PRESET_BY_MODALITY: Record<string, string> = {
MR: 'CT-Coronary-Arteries-2',
US: 'US-Fetal',
};
export const DEFAULT_PRESET = 'CT-AAA';

export const LAYER_PRESET_BY_MODALITY: Record<string, string> = {
...DEFAULT_PRESET_BY_MODALITY,
PT: '2hot-opaque',
};
export const LAYER_PRESET_DEFAULT = 'Blue to Red Rainbow';

// Keyboard shortcuts/hotkeys. Can add modifiers: 'Shift+Ctrl+A'
export const ACTION_TO_KEY = {
Expand Down
27 changes: 14 additions & 13 deletions src/store/view-configs/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@ import {
} from '@/src/utils/doubleKeyRecord';
import { Maybe } from '@/src/types';
import { identity } from '@/src/utils';
import { LAYER_PRESET_BY_MODALITY, LAYER_PRESET_DEFAULT } from '@/src/config';
import { createViewConfigSerializer } from './common';
import { DEFAULT_PRESET } from '../../vtk/ColorMaps';
import { ViewConfig } from '../../io/state-file/schema';
import { LayersConfig } from './types';
import { LayerID, useLayersStore } from '../datasets-layers';
import { useDICOMStore } from '../datasets-dicom';

export const MODALITY_TO_PRESET: Record<string, string> = {
PT: '2hot',
};

function getPreset(id: LayerID) {
const layersStore = useLayersStore();
const layer = layersStore.getLayer(id);
if (layer) {
if (layer.selection.type === 'dicom') {
const dicomStore = useDICOMStore();
const { Modality = undefined } =
dicomStore.volumeInfo[layer.selection.volumeKey];
return (Modality && MODALITY_TO_PRESET[Modality]) || DEFAULT_PRESET;
}
if (!layer) {
throw new Error(`Layer ${id} not found`);
}

if (layer.selection.type === 'dicom') {
const dicomStore = useDICOMStore();
const { Modality = undefined } =
dicomStore.volumeInfo[layer.selection.volumeKey];
return (
(Modality && LAYER_PRESET_BY_MODALITY[Modality]) || LAYER_PRESET_DEFAULT
);
}
return DEFAULT_PRESET;

return LAYER_PRESET_DEFAULT;
}

export const defaultLayersConfig = (): LayersConfig => ({
Expand Down
3 changes: 1 addition & 2 deletions src/store/view-configs/volume-coloring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getColorFunctionRangeFromPreset,
getOpacityFunctionFromPreset,
} from '@/src/utils/vtk-helpers';
import { DEFAULT_PRESET_BY_MODALITY } from '@/src/config';
import { DEFAULT_PRESET_BY_MODALITY, DEFAULT_PRESET } from '@/src/config';
import { ColorTransferFunction } from '@/src/types/views';
import { defineStore } from 'pinia';
import { reactive } from 'vue';
Expand All @@ -17,7 +17,6 @@ import {
import { DeepPartial, Maybe } from '@/src/types';
import { identity } from '@/src/utils';
import { createViewConfigSerializer } from './common';
import { DEFAULT_PRESET } from '../../vtk/ColorMaps';
import { ViewConfig } from '../../io/state-file/schema';
import { VolumeColorConfig } from './types';
import { useDICOMStore } from '../datasets-dicom';
Expand Down
8 changes: 7 additions & 1 deletion src/vtk/ColorMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ function registerPresets(presets: typeof MedicalPresets) {

registerPresets(MedicalPresets);

const twoHotOpaque = {
...vtkColorMaps.getPresetByName('2hot'),
Name: '2hot-opaque',
OpacityPoints: [0, 1],
};
vtkColorMaps.addPreset(twoHotOpaque);

/* prettier-ignore */
const GroupedPresets = [
{
Expand Down Expand Up @@ -61,6 +68,5 @@ const GroupedPresets = [
},
];

export const DEFAULT_PRESET = 'CT-AAA';
export const PresetNameList = GroupedPresets.flatMap((group) => group.presets);
export default GroupedPresets;
6 changes: 6 additions & 0 deletions src/vtk/MedicalColorPresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1518,5 +1518,11 @@
1,
1
]
},
{
"ColorSpace" : "HSV",
"Name" : "Blue to Red Rainbow",
"NanColor" : [ 0.498039215686, 0.498039215686, 0.498039215686 ],
"RGBPoints" : [ 0, 0, 0, 1, 1, 1, 0, 0 ]
}
]