Skip to content

Commit

Permalink
fix(VTKResliceCursor): make injected value as non-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
jadh4v committed Oct 26, 2023
1 parent 1e532f7 commit 125a335
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 38 deletions.
16 changes: 7 additions & 9 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -403,26 +403,24 @@ export default defineComponent({
// --- ResliceCursorWidget --- //
// Construct the common instance of vtkResliceCursorWidget and provide it
// to all the child ObliqueView components.
const resliceCursor = ref<vtkResliceCursorWidget>(
vtkResliceCursorWidget.newInstance({
scaleInPixels: true,
rotationHandlePosition: 0.75,
})
);
const resliceCursor = vtkResliceCursorWidget.newInstance({
scaleInPixels: true,
rotationHandlePosition: 0.75,
}) as vtkResliceCursorWidget;
provide(VTKResliceCursor, resliceCursor);
// TODO: Move this to a store/global-state for reslicing.
// Orient the planes of the vtkResliceCursorWidget to the orientation
// of the currently set image.
const resliceCursorState =
resliceCursor.value.getWidgetState() as ResliceCursorWidgetState;
resliceCursor.getWidgetState() as ResliceCursorWidgetState;
// Temporary fix to disable race between PanTool and ResliceCursorWidget
resliceCursorState.setScrollingMethod(-1);
watch(currentImageData, (image) => {
if (image && resliceCursor.value) {
resliceCursor.value.setImage(image);
if (image && resliceCursor) {
resliceCursor.setImage(image);
// Reset to default plane values before transforming based on current image-data.
resliceCursorState.setPlanes({
[ViewTypes.YZ_PLANE]: {
Expand Down
11 changes: 3 additions & 8 deletions src/components/VtkObliqueThreeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ export default defineComponent({
setViewProxyContainer(vtkContainerRef.value);
});
const resliceCursorRef = inject(VTKResliceCursor);
if (!resliceCursorRef) {
const resliceCursor = inject(VTKResliceCursor);
if (!resliceCursor) {
throw Error('Cannot access global ResliceCursor instance.');
}
const updateViewFromResliceCursor = () => {
const rep = baseImageRep?.value;
const resliceCursor = resliceCursorRef?.value;
const state = resliceCursor?.getWidgetState() as ResliceCursorWidgetState;
const planeOrigin = state?.getCenter();
if (resliceCursor && rep && planeOrigin) {
Expand All @@ -181,11 +180,7 @@ export default defineComponent({
viewProxy.value.renderLater();
};
onVTKEvent(
resliceCursorRef.value.getWidgetState(),
'onModified',
onPlanesUpdated
);
onVTKEvent(resliceCursor.getWidgetState(), 'onModified', onPlanesUpdated);
// --- camera setup --- //
Expand Down
16 changes: 7 additions & 9 deletions src/components/VtkObliqueView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ export default defineComponent({
const { viewProxy, setContainer: setViewProxyContainer } =
useViewProxy<vtkLPSView2DProxy>(viewID, ViewProxyType.Oblique);
const resliceCursorRef = inject(VTKResliceCursor);
if (!resliceCursorRef) {
const resliceCursor = inject(VTKResliceCursor);
if (!resliceCursor) {
throw Error('Cannot access global ResliceCursor instance.');
}
Expand Down Expand Up @@ -294,17 +294,16 @@ export default defineComponent({
const updateViewFromResliceCursor = () => {
const rep = baseImageRep?.value;
const resliceCursor = resliceCursorRef?.value;
const state = resliceCursor?.getWidgetState() as ResliceCursorWidgetState;
if (resliceCursor && rep) {
const planeOrigin = state.getCenter();
const planeNormal = resliceCursorRef.value.getPlaneNormalFromViewType(
const planeNormal = resliceCursor.getPlaneNormalFromViewType(
VTKViewType.value
);
rep.getSlicePlane().setNormal(planeNormal);
rep.getSlicePlane().setOrigin(planeOrigin);
if (curImageData.value) {
resliceCursorRef.value.updateCameraPoints(
resliceCursor.updateCameraPoints(
viewProxy.value.getRenderer(),
VTKViewType.value,
false,
Expand All @@ -316,7 +315,7 @@ export default defineComponent({
};
onVTKEvent(
resliceCursorRef.value.getWidgetState(),
resliceCursor.getWidgetState(),
'onModified',
updateViewFromResliceCursor
);
Expand All @@ -327,7 +326,7 @@ export default defineComponent({
// Initialize camera points during construction
if (curImageData.value) {
resliceCursorRef.value.updateCameraPoints(
resliceCursor.updateCameraPoints(
viewProxy.value.getRenderer(),
VTKViewType.value,
true,
Expand Down Expand Up @@ -555,7 +554,6 @@ export default defineComponent({
);
viewProxy.value.resetCamera(bounds);
// reset cursor widget
const resliceCursor = resliceCursorRef?.value;
const state =
resliceCursor?.getWidgetState() as ResliceCursorWidgetState;
// Reset to default plane values before transforming based on current image-data.
Expand Down Expand Up @@ -583,7 +581,7 @@ export default defineComponent({
vec3.transformMat3(normal, normal, mat);
vec3.transformMat3(vup, vup, mat);
});
resliceCursorRef.value?.setCenter(center);
resliceCursor.setCenter(center);
}
if (curImageMetadata) {
state.placeWidget(bounds);
Expand Down
12 changes: 3 additions & 9 deletions src/components/tools/ResliceCursorTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ export default defineComponent({
return viewStore.viewSpecs[viewID.value].viewType;
});
const resliceCursorRef = inject(VTKResliceCursor);
if (!resliceCursorRef) {
throw new Error(
'ResliceCursorTool component cannot access the 2D widget manager.'
);
}
const resliceCursor = resliceCursorRef.value;
const resliceCursor = inject(VTKResliceCursor);
if (!resliceCursor) {
throw new Error('Cannot fetch global instance of ResliceCursor');
}
Expand Down Expand Up @@ -172,8 +166,8 @@ export default defineComponent({
watch(
currentImageData,
(currImage) => {
if (resliceCursorRef.value && currImage) {
resliceCursorRef.value.setImage(currImage);
if (resliceCursor && currImage) {
resliceCursor.setImage(currImage);
}
},
{ immediate: true }
Expand Down
5 changes: 2 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export const DefaultTheme = DarkTheme;
/**
* Retrieves the global ResliceCursorWidget instance.
*/
export const VTKResliceCursor: InjectionKey<
ComputedRef<vtkResliceCursorWidget>
> = Symbol('VTKResliceCursor');
export const VTKResliceCursor: InjectionKey<vtkResliceCursorWidget> =
Symbol('VTKResliceCursor');

export const VTKResliceCursorViewWidget: InjectionKey<
ComputedRef<vtkResliceCursorViewWidget>
Expand Down

0 comments on commit 125a335

Please sign in to comment.