Skip to content
Open
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
16 changes: 0 additions & 16 deletions src/components/VolumePresets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useVolumeColoringInitializer } from '@/src/composables/useVolumeColorin
import PersistentOverlay from '@/src/components/PersistentOverlay.vue';
import { useCurrentImage } from '@/src/composables/useCurrentImage';
import useVolumeColoringStore from '@/src/store/view-configs/volume-coloring';
import { getColorFunctionRangeFromPreset } from '@/src/utils/vtk-helpers';
import { useVolumeThumbnailing } from '@/src/composables/useVolumeThumbnailing';

const THUMBNAIL_SIZE = 80;
Expand Down Expand Up @@ -51,20 +50,6 @@ export default defineComponent({
);
const hasCurrentImage = computed(() => !!currentImageData.value);

// the data range, if any
const imageDataRange = computed((): [number, number] => {
const image = currentImageData.value;
if (image) {
return image.getPointData().getScalars().getRange();
}
return [0, 1];
});
const effectiveMappingRange = computed(
() =>
getColorFunctionRangeFromPreset(selectedPreset.value || '') ||
imageDataRange.value
);

const selectPreset = (name: string) => {
if (!viewId.value || !currentImageID.value) return;
volumeColoringStore.setColorPreset(
Expand Down Expand Up @@ -104,7 +89,6 @@ export default defineComponent({
thumbnails: currentThumbnails,
hasCurrentImage,
preset: selectedPreset,
fullMappingRange: effectiveMappingRange,
mappingRange: computed(
() => colorTransferFunctionRef.value!.mappingRange
),
Expand Down
131 changes: 73 additions & 58 deletions src/components/VolumeRendering.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import { useVolumeColoringInitializer } from '@/src/composables/useVolumeColorin
import { useResizeObserver } from '@/src/composables/useResizeObserver';
import { useCurrentImage } from '@/src/composables/useCurrentImage';
import useVolumeColoringStore from '@/src/store/view-configs/volume-coloring';
import {
getColorFunctionRangeFromPreset,
getShiftedOpacityFromPreset,
} from '@/src/utils/vtk-helpers';
import { mappingRangeSliders } from '@/src/utils/mappingRangeSliders';
import { getShiftedOpacityFromPreset } from '@/src/utils/vtk-helpers';

const WIDGET_WIDTH = 250;
const WIDGET_HEIGHT = 150;
Expand Down Expand Up @@ -214,10 +212,14 @@ export default defineComponent({

onVTKEvent(colorTransferFunc, 'onModified', () => pwfWidget.render());

const fitRange = computed(() =>
volumeColoringStore.getFitRange(currentImageID.value)
);

// update pwf widget when opacity function changes
watch(
opacityFunction,
(opFunc) => {
[opacityFunction, fitRange],
([opFunc, range]) => {
if (!opFunc) return;

if (opFunc.mode === vtkPiecewiseFunctionProxy.Mode.Gaussians) {
Expand All @@ -226,12 +228,12 @@ export default defineComponent({
} else if (opFunc.mode === vtkPiecewiseFunctionProxy.Mode.Points) {
pwfWidget.setPointsMode();
// get non-shifted points for the widget
const points = getShiftedOpacityFromPreset(
opFunc.preset,
opFunc.mappingRange,
0,
0
);
const points = getShiftedOpacityFromPreset({
...opFunc,
shift: 0,
shiftAlpha: 0,
fitRange: range,
});
pwfWidget.setOpacityPoints(points, opFunc.shift, opFunc.shiftAlpha);
}
},
Expand All @@ -245,19 +247,13 @@ export default defineComponent({
);
const hasCurrentImage = computed(() => !!currentImageData.value);

// the data range, if any
const imageDataRange = computed((): [number, number] => {
const image = currentImageData.value;
if (image) {
return image.getPointData().getScalars().getRange();
}
return [0, 1];
});

const fullMappingRange = computed(
() =>
getColorFunctionRangeFromPreset(selectedPreset.value || '') ||
imageDataRange.value
const fullMappingRange = computed(() =>
currentImageID.value && selectedPreset.value
? volumeColoringStore.getPresetColorRange(
currentImageID.value,
selectedPreset.value
)
: [0, 1]
);
const fullMappingRangeWidth = computed(() => {
const range = fullMappingRange.value;
Expand All @@ -273,6 +269,10 @@ export default defineComponent({
);
};

const resetColoring = () => {
if (selectedPreset.value) selectPreset(selectedPreset.value);
};

// --- mapping range editing --- //

onKeyDown('Control', () => pwfWidget.setShiftOpacityValues(true));
Expand Down Expand Up @@ -336,53 +336,68 @@ export default defineComponent({
mappingRange: computed(
() => colorTransferFunctionRef.value!.mappingRange
),
colorSliderStep: computed(() => {
const [low, high] = imageDataRange.value;
const width = high - low;
const step = Math.min(1, width / 256);
return step > 1 ? Math.round(step) : step;
}),
rangeShiftMin: computed(() => -fullMappingRangeWidth.value / 2),
rangeShiftMax: computed(() => fullMappingRangeWidth.value / 2),
sliders: computed(() => mappingRangeSliders(fullMappingRangeWidth.value)),
rangeShift,
rangeWidth,
rangeWidthMax: computed(() => fullMappingRangeWidth.value * 2),
request3DAnimation,
cancel3DAnimation,
selectPreset,
resetColoring,
};
},
});
</script>

<template>
<div class="overflow-hidden">
<div class="mt-4 pwf-editor" ref="editorContainerRef">
<div
class="mt-4 pwf-editor"
ref="editorContainerRef"
data-testid="volume-opacity-editor"
>
<div ref="pwfEditorRef" />
</div>
<div class="mapping-range-editor">
<v-slider
v-model="rangeShift"
density="compact"
hide-details
label="Shift"
:min="rangeShiftMin"
:max="rangeShiftMax"
:step="colorSliderStep"
@pointerdown="request3DAnimation"
@pointerup="cancel3DAnimation"
/>
<v-slider
v-model="rangeWidth"
density="compact"
hide-details
label="Width"
min="1"
:max="rangeWidthMax"
:step="colorSliderStep"
@pointerdown="request3DAnimation"
@pointerup="cancel3DAnimation"
/>
<div class="mapping-range-editor d-flex align-center ga-2">
<div class="flex-grow-1">
<v-slider
v-model="rangeShift"
data-testid="volume-color-shift"
density="compact"
hide-details
label="Shift"
:min="sliders.shift[0]"
:max="sliders.shift[1]"
:step="sliders.step"
@pointerdown="request3DAnimation"
@pointerup="cancel3DAnimation"
/>
<v-slider
v-model="rangeWidth"
data-testid="volume-color-width"
density="compact"
hide-details
label="Width"
:min="sliders.width[0]"
:max="sliders.width[1]"
:step="sliders.step"
@pointerdown="request3DAnimation"
@pointerup="cancel3DAnimation"
/>
</div>
<v-tooltip text="Reset color and opacity to the preset">
<template #activator="{ props: tooltipProps }">
<v-btn
v-bind="tooltipProps"
data-testid="volume-reset-color-opacity"
aria-label="Reset color and opacity"
icon="mdi-restore"
size="small"
density="compact"
variant="text"
@click="resetColoring"
/>
</template>
</v-tooltip>
</div>
</div>
</template>
Expand Down
7 changes: 6 additions & 1 deletion src/components/vtk/VtkBaseVolumeRepresentation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ watchEffect(() => {
// apply coloring
useVolumeColoringInitializer(viewID, imageID);

useColoringEffect(coloringConfig, cfun, ofun);
useColoringEffect(
coloringConfig,
cfun,
ofun,
computed(() => useVolumeColoringStore().getFitRange(imageID.value))
);

// cropping
const cropStore = useCropStore();
Expand Down
21 changes: 12 additions & 9 deletions src/composables/useColoringEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ type ApplyColoringParams = {
};
cfun: vtkColorTransferFunction;
ofun: vtkPiecewiseFunction;
fitRange?: Maybe<[number, number]>;
};

function applyColoring({
props: { colorFunction, opacityFunction },
cfun,
ofun,
fitRange,
}: ApplyColoringParams) {
cfun.setVectorModeToMagnitude();

Expand All @@ -42,12 +44,13 @@ function applyColoring({
cfun.setMappingRange(...colorFunction.mappingRange);
}

applyOpacityFunction(opacityFunction, ofun);
applyOpacityFunction(opacityFunction, ofun, fitRange);
}

export function applyOpacityFunction(
opacityFunction: OpacityFunction,
ofun: vtkPiecewiseFunction
ofun: vtkPiecewiseFunction,
fitRange?: Maybe<[number, number]>
) {
const { mappingRange } = opacityFunction;
if (!isZeroWidthRange(opacityFunction.mappingRange)) {
Expand All @@ -64,12 +67,10 @@ export function applyOpacityFunction(
);
break;
case vtkPiecewiseFunctionProxy.Mode.Points: {
const opacityPoints = getShiftedOpacityFromPreset(
opacityFunction.preset,
opacityFunction.mappingRange,
opacityFunction.shift,
opacityFunction.shiftAlpha
);
const opacityPoints = getShiftedOpacityFromPreset({
...opacityFunction,
fitRange,
});
if (opacityPoints) {
applyPointsToPiecewiseFunction(ofun, opacityPoints, mappingRange);
}
Expand All @@ -87,7 +88,8 @@ export function applyOpacityFunction(
export function useColoringEffect(
config: MaybeRef<Maybe<ColoringConfig>>,
cfun: MaybeRef<vtkColorTransferFunction>,
ofun: MaybeRef<vtkPiecewiseFunction>
ofun: MaybeRef<vtkPiecewiseFunction>,
fitRange?: MaybeRef<Maybe<[number, number]>>
) {
const colorTransferFunction = computed(() => unref(config)?.transferFunction);
const opacityFunction = computed(() => unref(config)?.opacityFunction);
Expand All @@ -104,6 +106,7 @@ export function useColoringEffect(
},
cfun: unref(cfun),
ofun: unref(ofun),
fitRange: unref(fitRange),
});
});
}
Loading
Loading