Skip to content

Commit

Permalink
Merge pull request #523 from PaulHax/crosshair-view-switch-fix
Browse files Browse the repository at this point in the history
fix(CrosshairsWidget2D): avoid error when changing layout
  • Loading branch information
floryst authored Nov 29, 2023
2 parents 401f6a8 + 716283d commit 86981a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
22 changes: 13 additions & 9 deletions src/components/tools/crosshairs/CrosshairsWidget2D.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import vtkWidgetManager from '@kitware/vtk.js/Widgets/Core/WidgetManager';
import {
defineComponent,
onBeforeUnmount,
onMounted,
PropType,
ref,
toRefs,
watchEffect,
computed,
} from 'vue';
import vtkPlaneManipulator from '@kitware/vtk.js/Widgets/Manipulators/PlaneManipulator';
import { LPSAxisDir } from '@/src/types/lps';
import { useCurrentImage } from '@/src/composables/useCurrentImage';
import { updatePlaneManipulatorFor2DView } from '@/src/utils/manipulators';
import { vtkCrosshairsViewWidget } from '@/src/vtk/CrosshairsWidget';
import { useCrosshairsToolStore } from '@/src/store/tools/crosshairs';
import { useViewStore } from '@/src/store/views';
import { onViewProxyMounted } from '@/src/composables/useViewProxy';
export default defineComponent({
name: 'CrosshairsWidget2D',
Expand All @@ -41,33 +43,35 @@ export default defineComponent({
widgetManager: widgetManagerRef,
viewDirection,
slice,
viewId,
} = toRefs(props);
const widgetRef = ref<vtkCrosshairsViewWidget>();
const crosshairsStore = useCrosshairsToolStore();
const factory = crosshairsStore.getWidgetFactory();
const viewProxy = computed(() => useViewStore().getViewProxy(viewId.value));
const widgetRef = ref<vtkCrosshairsViewWidget>();
const { currentImageMetadata } = useCurrentImage();
onMounted(() => {
onViewProxyMounted(viewProxy, () => {
const widgetManager = widgetManagerRef.value;
widgetRef.value = widgetManager.addWidget(
factory
) as vtkCrosshairsViewWidget;
if (!widgetRef.value) {
throw new Error('[PaintWidget2D] failed to create view widget');
throw new Error('CrosshairsWidget2D failed to create view widget');
}
});
// --- manipulator --- //
const manipulator = vtkPlaneManipulator.newInstance();
onMounted(() => {
onViewProxyMounted(viewProxy, () => {
widgetRef.value!.setManipulator(manipulator);
});
const { currentImageMetadata } = useCurrentImage();
watchEffect(() => {
updatePlaneManipulatorFor2DView(
manipulator,
Expand All @@ -79,13 +83,13 @@ export default defineComponent({
// --- visibility --- //
onMounted(() => {
onViewProxyMounted(viewProxy, () => {
widgetRef.value!.setVisibility(true);
});
// --- focus and rendering --- //
onMounted(() => {
onViewProxyMounted(viewProxy, () => {
const widgetManager = widgetManagerRef.value;
widgetManager.renderWidgets();
});
Expand Down
11 changes: 3 additions & 8 deletions src/components/tools/paint/PaintWidget2D.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ export default defineComponent({
},
},
setup(props) {
const {
widgetManager,
viewDirection,
slice,
viewId: viewID,
} = toRefs(props);
const { widgetManager, viewDirection, slice, viewId } = toRefs(props);
const paintStore = usePaintToolStore();
const widgetFactory = paintStore.getWidgetFactory();
Expand All @@ -70,15 +65,15 @@ export default defineComponent({
return indexPoint;
};
const viewProxy = computed(() => useViewStore().getViewProxy(viewID.value));
const viewProxy = computed(() => useViewStore().getViewProxy(viewId.value));
onViewProxyMounted(viewProxy, () => {
widgetRef.value = widgetManager.value.addWidget(
widgetFactory
) as vtkPaintViewWidget;
if (!widgetRef.value) {
throw new Error('[PaintWidget2D] failed to create view widget');
throw new Error('PaintWidget2D failed to create view widget');
}
widgetManager.value.renderWidgets();
Expand Down

0 comments on commit 86981a1

Please sign in to comment.