diff --git a/src/utils/frameOfReference.ts b/src/utils/frameOfReference.ts index 3c9b357a..016e6999 100644 --- a/src/utils/frameOfReference.ts +++ b/src/utils/frameOfReference.ts @@ -77,14 +77,14 @@ export function frameOfReferenceToImageSliceAndAxis( return { axis, slice }; } -export function getPixelSizeSquared( +export function getSmallestSpacing( frame: FrameOfReference, metadata: ImageMetadata -): number | null { - const toolImageFrame = frameOfReferenceToImageSliceAndAxis(frame, metadata); - if (!toolImageFrame) return null; - const axisIndex = metadata.lpsOrientation[toolImageFrame.axis]; +): number { + const sliceAxis = frameOfReferenceToImageSliceAndAxis(frame, metadata); + if (!sliceAxis) return Math.min(...metadata.spacing); // off orthogonal + const axisIndex = metadata.lpsOrientation[sliceAxis.axis]; const spacing = [...metadata.spacing]; spacing.splice(axisIndex, 1); - return spacing[0] * spacing[0] + spacing[1] * spacing[1]; + return Math.min(...spacing); } diff --git a/src/vtk/PolygonWidget/state.ts b/src/vtk/PolygonWidget/state.ts index 82f0d574..8d956423 100644 --- a/src/vtk/PolygonWidget/state.ts +++ b/src/vtk/PolygonWidget/state.ts @@ -8,7 +8,7 @@ import vtkAnnotationWidgetState from '@/src/vtk/ToolWidgetUtils/annotationWidget import { Polygon } from '@/src/types/polygon'; import { AnnotationToolType } from '@/src/store/tools/types'; import { getImageMetadata } from '@/src/composables/useCurrentImage'; -import { getPixelSizeSquared } from '@/src/utils/frameOfReference'; +import { getSmallestSpacing } from '@/src/utils/frameOfReference'; import createPointState from '../ToolWidgetUtils/pointState'; import { watchState } from '../ToolWidgetUtils/utils'; import decimate from './decimate'; @@ -17,7 +17,7 @@ export const MoveHandleLabel = 'moveHandle'; export const HandlesLabel = 'handles'; const HANDLE_PIXEL_SIZE = 20; -const DECIMATE_PIXEL_SIZE_FACTOR = 0.01; +const DECIMATE_PIXEL_SIZE_FACTOR = 0.2; type VtkObjectModel = { classHierarchy: string[]; @@ -132,23 +132,14 @@ function vtkPolygonWidgetState(publicAPI: any, model: any) { // Decimate points const imageMeta = getImageMetadata(tool.imageID); - const pixelSizeSquared = getPixelSizeSquared( - tool.frameOfReference, - imageMeta + const pixelScale = getSmallestSpacing(tool.frameOfReference, imageMeta); + const optimizedLine = decimate( + tool.points, + pixelScale * DECIMATE_PIXEL_SIZE_FACTOR ); - if (pixelSizeSquared) { - const optimizedLine = decimate( - tool.points, - pixelSizeSquared * DECIMATE_PIXEL_SIZE_FACTOR - ); - publicAPI.clearHandles(); - tool.points = optimizedLine; - addPointsAsHandles(); - } else { - console.error( - 'Off LPS axis pixel sizing not implemented. Not decimating line.' - ); - } + publicAPI.clearHandles(); + tool.points = optimizedLine; + addPointsAsHandles(); }; // Setup after deserialization