Preventing zero-sized bidirectional targets
This commit is contained in:
parent
4d93839412
commit
88e932a2f7
@ -47,7 +47,7 @@ function createNewMeasurement(mouseEventData) {
|
|||||||
highlight: true,
|
highlight: true,
|
||||||
active: false,
|
active: false,
|
||||||
drawnIndependently: false,
|
drawnIndependently: false,
|
||||||
allowedOutsideImage: true,
|
allowedOutsideImage: false,
|
||||||
index: 0
|
index: 0
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
@ -56,7 +56,7 @@ function createNewMeasurement(mouseEventData) {
|
|||||||
highlight: true,
|
highlight: true,
|
||||||
active: true,
|
active: true,
|
||||||
drawnIndependently: false,
|
drawnIndependently: false,
|
||||||
allowedOutsideImage: true,
|
allowedOutsideImage: false,
|
||||||
index: 1
|
index: 1
|
||||||
},
|
},
|
||||||
textBox: {
|
textBox: {
|
||||||
@ -75,7 +75,7 @@ function createNewMeasurement(mouseEventData) {
|
|||||||
active: false,
|
active: false,
|
||||||
locked: true, // If perpendicular line is connected to long-line
|
locked: true, // If perpendicular line is connected to long-line
|
||||||
drawnIndependently: false,
|
drawnIndependently: false,
|
||||||
allowedOutsideImage: true,
|
allowedOutsideImage: false,
|
||||||
index: 2
|
index: 2
|
||||||
},
|
},
|
||||||
perpendicularEnd: {
|
perpendicularEnd: {
|
||||||
@ -84,7 +84,7 @@ function createNewMeasurement(mouseEventData) {
|
|||||||
highlight: true,
|
highlight: true,
|
||||||
active: false,
|
active: false,
|
||||||
drawnIndependently: false,
|
drawnIndependently: false,
|
||||||
allowedOutsideImage: true,
|
allowedOutsideImage: false,
|
||||||
index: 3
|
index: 3
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -172,12 +172,11 @@ function addNewMeasurement(mouseEventData) {
|
|||||||
const timestamp = new Date().getTime();
|
const timestamp = new Date().getTime();
|
||||||
cornerstoneTools.moveNewHandle(mouseEventData, toolType, measurementData, measurementData.handles.end, function() {
|
cornerstoneTools.moveNewHandle(mouseEventData, toolType, measurementData, measurementData.handles.end, function() {
|
||||||
const { handles, longestDiameter, shortestDiameter } = measurementData;
|
const { handles, longestDiameter, shortestDiameter } = measurementData;
|
||||||
const hasHandlesOutside = cornerstoneTools.anyHandlesOutsideImage(mouseEventData, handles); // TODO FIXME: >>>> not working
|
const hasHandlesOutside = cornerstoneTools.anyHandlesOutsideImage(mouseEventData, handles);
|
||||||
const ldSize = parseFloat(longestDiameter) || 0;
|
const longestDiameterSize = parseFloat(longestDiameter) || 0;
|
||||||
const sdSize = parseFloat(shortestDiameter) || 0;
|
const shortestDiameterSize = parseFloat(shortestDiameter) || 0;
|
||||||
const isTooSmal = (ldSize < 1) || (sdSize < 1);
|
const isTooSmal = (longestDiameterSize < 1) || (shortestDiameterSize < 1);
|
||||||
const isTooFast = (new Date().getTime() - timestamp) < 1000;
|
const isTooFast = (new Date().getTime() - timestamp) < 150;
|
||||||
console.warn('>>>>', cancelled, hasHandlesOutside, isTooSmal, isTooFast);
|
|
||||||
if (cancelled || hasHandlesOutside || isTooSmal || isTooFast) {
|
if (cancelled || hasHandlesOutside || isTooSmal || isTooFast) {
|
||||||
// delete the measurement
|
// delete the measurement
|
||||||
measurementData.cancelled = true;
|
measurementData.cancelled = true;
|
||||||
@ -793,13 +792,14 @@ function drawHandles(context, eventData, handles, color, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function moveHandle(mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) {
|
function moveHandle(mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) {
|
||||||
var element = mouseEventData.element;
|
const element = mouseEventData.element;
|
||||||
var distanceFromTool = {
|
const $element = $(element);
|
||||||
|
const distanceFromTool = {
|
||||||
x: handle.x - mouseEventData.currentPoints.image.x,
|
x: handle.x - mouseEventData.currentPoints.image.x,
|
||||||
y: handle.y - mouseEventData.currentPoints.image.y
|
y: handle.y - mouseEventData.currentPoints.image.y
|
||||||
};
|
};
|
||||||
|
|
||||||
function mouseDragCallback(e, eventData) {
|
const mouseDragCallback = (event, eventData) => {
|
||||||
handle.active = true;
|
handle.active = true;
|
||||||
|
|
||||||
if (handle.index === undefined || handle.index === null) {
|
if (handle.index === undefined || handle.index === null) {
|
||||||
@ -825,24 +825,38 @@ function moveHandle(mouseEventData, toolType, data, handle, doneMovingCallback,
|
|||||||
element: element,
|
element: element,
|
||||||
measurementData: data
|
measurementData: data
|
||||||
};
|
};
|
||||||
$(element).trigger(eventType, modifiedEventData);
|
$element.trigger(eventType, modifiedEventData);
|
||||||
|
};
|
||||||
|
|
||||||
|
$element.on('CornerstoneToolsMouseDrag', mouseDragCallback);
|
||||||
|
|
||||||
|
const currentImage = cornerstone.getImage(element);
|
||||||
|
const imageRenderedHandler = () => {
|
||||||
|
const newImage = cornerstone.getImage(element);
|
||||||
|
|
||||||
|
// Check if the rendered image changed during measurement modifying and stop it if so
|
||||||
|
if (newImage.imageId !== currentImage.imageId) {
|
||||||
|
mouseUpCallback();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$(element).on('CornerstoneToolsMouseDrag', mouseDragCallback);
|
// Bind the event listener for image rendering
|
||||||
|
$element.on('CornerstoneImageRendered', imageRenderedHandler);
|
||||||
|
|
||||||
function mouseUpCallback() {
|
const mouseUpCallback = () => {
|
||||||
$(element).off('CornerstoneToolsMouseDrag', mouseDragCallback);
|
$element.off('CornerstoneToolsMouseDrag', mouseDragCallback);
|
||||||
$(element).off('CornerstoneToolsMouseUp', mouseUpCallback);
|
$element.off('CornerstoneToolsMouseUp', mouseUpCallback);
|
||||||
$(element).off('CornerstoneToolsMouseClick', mouseUpCallback);
|
$element.off('CornerstoneToolsMouseClick', mouseUpCallback);
|
||||||
|
$element.off('CornerstoneImageRendered', imageRenderedHandler);
|
||||||
cornerstone.updateImage(element);
|
cornerstone.updateImage(element);
|
||||||
|
|
||||||
if (typeof doneMovingCallback === 'function') {
|
if (typeof doneMovingCallback === 'function') {
|
||||||
doneMovingCallback();
|
doneMovingCallback();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
$(element).on('CornerstoneToolsMouseUp', mouseUpCallback);
|
$element.on('CornerstoneToolsMouseUp', mouseUpCallback);
|
||||||
$(element).on('CornerstoneToolsMouseClick', mouseUpCallback);
|
$element.on('CornerstoneToolsMouseClick', mouseUpCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mouseMoveCallback is used to hide handles when mouse is away
|
// mouseMoveCallback is used to hide handles when mouse is away
|
||||||
|
|||||||
@ -127,7 +127,6 @@ class MeasurementHandlers {
|
|||||||
static onRemoved(e, instance, eventData) {
|
static onRemoved(e, instance, eventData) {
|
||||||
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
OHIF.log.info('CornerstoneToolsMeasurementRemoved');
|
||||||
const measurementData = eventData.measurementData;
|
const measurementData = eventData.measurementData;
|
||||||
const measurementNumber = measurementData.measurementNumber;
|
|
||||||
const { measurementApi, timepointApi } = instance.data;
|
const { measurementApi, timepointApi } = instance.data;
|
||||||
const Collection = measurementApi.tools[eventData.toolType];
|
const Collection = measurementApi.tools[eventData.toolType];
|
||||||
|
|
||||||
@ -142,9 +141,9 @@ class MeasurementHandlers {
|
|||||||
// Stop here if the measurement is already gone or never existed
|
// Stop here if the measurement is already gone or never existed
|
||||||
if (!measurement) return;
|
if (!measurement) return;
|
||||||
|
|
||||||
const timepointId = measurement.timepointId;
|
|
||||||
|
|
||||||
// Remove all the measurements with the given type and number
|
// Remove all the measurements with the given type and number
|
||||||
|
const { measurementNumber, timepointId } = measurement;
|
||||||
measurementApi.deleteMeasurements(measurementTypeId, {
|
measurementApi.deleteMeasurements(measurementTypeId, {
|
||||||
measurementNumber,
|
measurementNumber,
|
||||||
timepointId
|
timepointId
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user