chore(bidirectional-tool): Clean up longest/shortest diameters calculation

This commit is contained in:
Bruno Alves de Faria 2018-04-20 16:20:23 -03:00 committed by Erik Ziegler
parent d834c751a9
commit 02ec88655a
3 changed files with 61 additions and 37 deletions

View File

@ -0,0 +1,32 @@
// Calculate the longest and shortest diameters for the given measurementData
export default function(eventData, measurementData) {
const { rowPixelSpacing, columnPixelSpacing } = eventData.image;
const { start, end, perpendicularStart, perpendicularEnd } = measurementData.handles;
// updatePerpendicularLineHandles(eventData, measurementData);
// Calculate the long axis length
const dx = (start.x - end.x) * (columnPixelSpacing || 1);
const dy = (start.y - end.y) * (rowPixelSpacing || 1);
let length = Math.sqrt(dx * dx + dy * dy);
// Calculate the short axis length
const wx = (perpendicularStart.x - perpendicularEnd.x) * (columnPixelSpacing || 1);
const wy = (perpendicularStart.y - perpendicularEnd.y) * (rowPixelSpacing || 1);
let width = Math.sqrt(wx * wx + wy * wy);
if (!width) {
width = 0;
}
// Length is always longer than width
if (width > length) {
const tempW = width;
const tempL = length;
length = tempW;
width = tempL;
}
// Set measurement text to show lesion table
measurementData.longestDiameter = length.toFixed(1);
measurementData.shortestDiameter = width.toFixed(1);
}

View File

@ -1,5 +1,6 @@
import { cornerstone } from 'meteor/ohif:cornerstone'; import { cornerstone } from 'meteor/ohif:cornerstone';
import setHandlesPosition from './setHandlesPosition'; import setHandlesPosition from './setHandlesPosition';
import calculateLongestAndShortestDiameters from '../calculateLongestAndShortestDiameters';
export default function (mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) { export default function (mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) {
const element = mouseEventData.element; const element = mouseEventData.element;
@ -29,14 +30,23 @@ export default function (mouseEventData, toolType, data, handle, doneMovingCallb
cornerstone.updateImage(element); cornerstone.updateImage(element);
const eventType = 'cornerstonetoolsmeasurementmodified'; const measurementModifiedHandler = () => {
const modifiedEventData = { const eventType = 'cornerstonetoolsmeasurementmodified';
toolType, const modifiedEventData = {
element, toolType,
measurementData: data element,
measurementData: data
};
calculateLongestAndShortestDiameters(mouseEventData, data);
cornerstone.triggerEvent(element, eventType, modifiedEventData);
element.removeEventListener('cornerstoneimagerendered', measurementModifiedHandler);
}; };
cornerstone.triggerEvent(element, eventType, modifiedEventData); // Wait on image render before triggering the modified event
element.addEventListener('cornerstoneimagerendered', measurementModifiedHandler);
}; };
element.addEventListener('cornerstonetoolsmousedrag', mouseDragCallback); element.addEventListener('cornerstonetoolsmousedrag', mouseDragCallback);

View File

@ -2,6 +2,7 @@ import { cornerstone, cornerstoneMath, cornerstoneTools } from 'meteor/ohif:corn
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
import { toolType } from '../definitions'; import { toolType } from '../definitions';
import drawHandles from './drawHandles'; import drawHandles from './drawHandles';
import calculateLongestAndShortestDiameters from '../calculateLongestAndShortestDiameters';
import updatePerpendicularLineHandles from '../updatePerpendicularLineHandles'; import updatePerpendicularLineHandles from '../updatePerpendicularLineHandles';
import drawPerpendicularLine from './drawPerpendicularLine'; import drawPerpendicularLine from './drawPerpendicularLine';
import drawSelectedMarker from './drawSelectedMarker'; import drawSelectedMarker from './drawSelectedMarker';
@ -41,11 +42,9 @@ export default function(event) {
for (let i = 0; i < toolData.data.length; i++) { for (let i = 0; i < toolData.data.length; i++) {
const data = toolData.data[i]; const data = toolData.data[i];
if (data.visible === false) { if (data.visible === false) continue;
continue;
}
const { start, end, perpendicularStart, perpendicularEnd, textBox } = data.handles; const { start, end, textBox } = data.handles;
const strokeWidth = lineWidth; const strokeWidth = lineWidth;
context.save(); context.save();
@ -93,26 +92,8 @@ export default function(event) {
// Draw the selected marker // Draw the selected marker
drawSelectedMarker(eventData, data.handles, '#FF9999'); drawSelectedMarker(eventData, data.handles, '#FF9999');
// Calculate the long axis length // Calculate the longest and shortest diameters, storing it in the respective attributes
const dx = (start.x - end.x) * (colPixelSpacing || 1); calculateLongestAndShortestDiameters(eventData, data);
const dy = (start.y - end.y) * (rowPixelSpacing || 1);
let length = Math.sqrt(dx * dx + dy * dy);
// Calculate the short axis length
const wx = (perpendicularStart.x - perpendicularEnd.x) * (colPixelSpacing || 1);
const wy = (perpendicularStart.y - perpendicularEnd.y) * (rowPixelSpacing || 1);
let width = Math.sqrt(wx * wx + wy * wy);
if (!width) {
width = 0;
}
// Length is always longer than width
if (width > length) {
const tempW = width;
const tempL = length;
length = tempW;
width = tempL;
}
if (data.measurementNumber) { if (data.measurementNumber) {
// Draw the textbox // Draw the textbox
@ -121,9 +102,14 @@ export default function(event) {
suffix = ' pixels'; suffix = ' pixels';
} }
const lengthText = ' L ' + length.toFixed(1) + suffix; const lengthText = ' L ' + data.longestDiameter + suffix;
const widthText = ' W ' + width.toFixed(1) + suffix; const widthText = ' W ' + data.shortestDiameter + suffix;
const textLines = [`Target ${data.measurementNumber}`, lengthText, widthText]; let textLines = [`Target ${data.measurementNumber}`, lengthText, widthText];
// Append extra text lines when applies
if (data.additionalData && Array.isArray(data.additionalData.extraTextLines)) {
textLines = textLines.concat(data.additionalData.extraTextLines);
}
const boundingBox = cornerstoneTools.drawTextBox( const boundingBox = cornerstoneTools.drawTextBox(
context, context,
@ -208,10 +194,6 @@ export default function(event) {
context.stroke(); context.stroke();
} }
// Set measurement text to show lesion table
data.longestDiameter = length.toFixed(1);
data.shortestDiameter = width.toFixed(1);
context.restore(); context.restore();
} }
} }