diff --git a/Packages/ohif-lesiontracker/client/compatibility/bidirectionalTool/onImageRendered/onImageRendered.js b/Packages/ohif-lesiontracker/client/compatibility/bidirectionalTool/onImageRendered/onImageRendered.js index 1f8b4b94b..7d91437bb 100644 --- a/Packages/ohif-lesiontracker/client/compatibility/bidirectionalTool/onImageRendered/onImageRendered.js +++ b/Packages/ohif-lesiontracker/client/compatibility/bidirectionalTool/onImageRendered/onImageRendered.js @@ -65,10 +65,16 @@ export default function(event) { color = cornerstoneTools.toolColors.getToolColor(); } - // draw the line - const handleStartCanvas = cornerstone.pixelToCanvas(element, start); - const handleEndCanvas = cornerstone.pixelToCanvas(element, end); - const canvasTextLocation = cornerstone.pixelToCanvas(element, textBox); + // Update the perpendicular handles to draw it correctly + updatePerpendicularLineHandles(eventData, data); + + // Draw the line + const { pixelToCanvas } = cornerstone; + const handleStartCanvas = pixelToCanvas(element, start); + const handleEndCanvas = pixelToCanvas(element, end); + const handlePerpendicularStartCanvas = pixelToCanvas(element, perpendicularStart); + const handlePerpendicularEndCanvas = pixelToCanvas(element, perpendicularEnd); + const canvasTextLocation = pixelToCanvas(element, textBox); context.beginPath(); context.strokeStyle = color; @@ -78,7 +84,6 @@ export default function(event) { context.stroke(); // Draw perpendicular line - updatePerpendicularLineHandles(eventData, data); drawPerpendicularLine(context, element, data, color, strokeWidth); // Draw the handles @@ -144,7 +149,29 @@ export default function(event) { y: (handleStartCanvas.y + handleEndCanvas.y) / 2, }; - const points = [ handleStartCanvas, handleEndCanvas, midpointCanvas ]; + // Check if the perpendicular line has some length (start and end are not equal) + // Note: this check is needed to prevent NaN value on the intersection result + const { distance } = cornerstoneMath.point; + const lineHasLength = distance(perpendicularLine.start, perpendicularLine.end) > 0; + + // Define the lines intersection point + let linesIntersection; + if (lineHasLength) { + // As the line has length, define it as the intersection between the lines + const { intersectLine } = cornerstoneMath.lineSegment; + linesIntersection = intersectLine(longLine, perpendicularLine); + } else { + // As the line has no length, the tool is in its start position + linesIntersection = longLine.start; + } + + const points = [ + handleStartCanvas, + handleEndCanvas, + handlePerpendicularStartCanvas, + handlePerpendicularEndCanvas, + linesIntersection + ]; link.end.x = canvasTextLocation.x; link.end.y = canvasTextLocation.y; diff --git a/Packages/ohif-measurements/client/lib/MeasurementHandlers/handleSingleMeasurementRemoved.js b/Packages/ohif-measurements/client/lib/MeasurementHandlers/handleSingleMeasurementRemoved.js index 1208e44fe..5310fc28e 100644 --- a/Packages/ohif-measurements/client/lib/MeasurementHandlers/handleSingleMeasurementRemoved.js +++ b/Packages/ohif-measurements/client/lib/MeasurementHandlers/handleSingleMeasurementRemoved.js @@ -30,7 +30,7 @@ export default function({ instance, eventData, tool, toolGroupId, toolGroup }) { measurementApi.sortMeasurements(baseline.timepointId); // Repaint the images on all viewports without the removed measurements - _.each($('.imageViewerViewport'), element => cornerstone.updateImage(element)); + _.each($('.imageViewerViewport:not(.empty)'), element => cornerstone.updateImage(element)); // Notify that viewer suffered changes if (tool.toolGroup !== 'temp') {