diff --git a/Sources/Widgets/Widgets3D/ImageCroppingWidget/behavior.js b/Sources/Widgets/Widgets3D/ImageCroppingWidget/behavior.js index 641e2311bd0..c5c11337583 100644 --- a/Sources/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +++ b/Sources/Widgets/Widgets3D/ImageCroppingWidget/behavior.js @@ -5,6 +5,7 @@ import { transformVec3, handleTypeFromName, calculateDirection, + calculateCropperCenter, } from 'vtk.js/Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers'; export default function widgetBehavior(publicAPI, model) { @@ -76,14 +77,8 @@ export default function widgetBehavior(publicAPI, model) { if (type === 'faces') { // get center of current crop box - const center = [ - (planes[0] + planes[1]) / 2, - (planes[2] + planes[3]) / 2, - (planes[4] + planes[5]) / 2, - ]; - - // manipulator should be a line manipulator - const worldCenter = transformVec3(center, indexToWorldT); + const worldCenter = calculateCropperCenter(planes, indexToWorldT); + manipulator.setHandleOrigin(worldCenter); manipulator.setHandleNormal( calculateDirection(model.activeState.getOrigin(), worldCenter) @@ -100,14 +95,7 @@ export default function widgetBehavior(publicAPI, model) { const faceName = edgeAxis.map((i) => AXES[i + 1]).join(''); const handle = model.widgetState.getStatesWithLabel(faceName)[0]; // get center of current crop box - const center = [ - (planes[0] + planes[1]) / 2, - (planes[2] + planes[3]) / 2, - (planes[4] + planes[5]) / 2, - ]; - - // manipulator should be a line manipulator - const worldCenter = transformVec3(center, indexToWorldT); + const worldCenter = calculateCropperCenter(planes, indexToWorldT); manipulator.setHandleNormal( calculateDirection(handle.getOrigin(), worldCenter) diff --git a/Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers.js b/Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers.js index 8b3e365c3d3..0f243c71b48 100644 --- a/Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +++ b/Sources/Widgets/Widgets3D/ImageCroppingWidget/helpers.js @@ -35,6 +35,16 @@ export function handleTypeFromName(name) { return 'faces'; } +export function calculateCropperCenter(planes, transform) { + // get center of current crop box + const center = [ + (planes[0] + planes[1]) / 2, + (planes[2] + planes[3]) / 2, + (planes[4] + planes[5]) / 2, + ]; + return transformVec3(center, transform); +} + export function calculateDirection(v1, v2) { const direction = vec3.create(); vec3.subtract(direction, v1, v2);