From 232557d6a77907e9fdb9e4178cce498f23ea6477 Mon Sep 17 00:00:00 2001 From: Forrest Date: Fri, 8 Sep 2023 14:17:19 -0400 Subject: [PATCH] refactor(onVTKEvent): easier event interface --- src/components/VolumeRendering.vue | 11 ++---- src/components/tools/crop/Crop3D.vue | 8 +--- .../tools/crosshairs/CrosshairSVG2D.vue | 8 ++-- src/components/tools/polygon/PolygonSVG2D.vue | 8 ++-- .../tools/polygon/PolygonWidget2D.vue | 8 +--- .../tools/rectangle/RectangleSVG2D.vue | 8 ++-- .../tools/rectangle/RectangleWidget2D.vue | 13 ++----- src/components/tools/ruler/RulerSVG2D.vue | 8 ++-- src/components/tools/ruler/RulerWidget2D.vue | 13 ++----- src/composables/annotationTool.ts | 7 +--- src/composables/isViewAnimating.ts | 15 ++------ src/composables/onVTKEvent.ts | 38 +++++++++++++++++++ src/composables/useOrientationLabels.ts | 7 +--- src/composables/useVTKCallback.ts | 33 ---------------- src/composables/useVTKWorldToDisplay.ts | 21 +++++----- src/composables/useViewProxy.ts | 19 +++------- 16 files changed, 87 insertions(+), 138 deletions(-) create mode 100644 src/composables/onVTKEvent.ts delete mode 100644 src/composables/useVTKCallback.ts diff --git a/src/components/VolumeRendering.vue b/src/components/VolumeRendering.vue index fdc1b0ad9..4efb0f757 100644 --- a/src/components/VolumeRendering.vue +++ b/src/components/VolumeRendering.vue @@ -13,9 +13,9 @@ import type { vtkSubscription } from '@kitware/vtk.js/interfaces'; import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps'; import vtkPiecewiseFunctionProxy from '@kitware/vtk.js/Proxy/Core/PiecewiseFunctionProxy'; import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction'; +import { onVTKEvent } from '@/src/composables/onVTKEvent'; import { useResizeObserver } from '../composables/useResizeObserver'; import { useCurrentImage } from '../composables/useCurrentImage'; -import { useVTKCallback } from '../composables/useVTKCallback'; import useVolumeColoringStore from '../store/view-configs/volume-coloring'; import { getColorFunctionRangeFromPreset, @@ -128,8 +128,7 @@ export default defineComponent({ recurseGuard = false; } - const onWidgetOpacityChange = useVTKCallback(pwfWidget.onOpacityChange); - onWidgetOpacityChange(updateOpacityFunc); + onVTKEvent(pwfWidget, 'onOpacityChange', updateOpacityFunc); // trigger 3D view animations when updating the opacity widget const { viewProxy } = useViewProxy(TARGET_VIEW_ID, ViewProxyType.Volume); @@ -149,8 +148,7 @@ export default defineComponent({ .cancelAnimation(pwfWidget, true /* skipWarning */); }; - const onWidgetAnimation = useVTKCallback(pwfWidget.onAnimation); - onWidgetAnimation((animating: boolean) => { + onVTKEvent(pwfWidget, 'onAnimation', (animating: boolean) => { if (animating) { request3DAnimation(); } else { @@ -212,8 +210,7 @@ export default defineComponent({ { immediate: true } ); - const onTFModified = useVTKCallback(colorTransferFunc.onModified); - onTFModified(() => pwfWidget.render()); + onVTKEvent(colorTransferFunc, 'onModified', () => pwfWidget.render()); // update pwf widget when opacity function changes watch( diff --git a/src/components/tools/crop/Crop3D.vue b/src/components/tools/crop/Crop3D.vue index 3158360ee..977ac8ba7 100644 --- a/src/components/tools/crop/Crop3D.vue +++ b/src/components/tools/crop/Crop3D.vue @@ -1,6 +1,6 @@