WIP reorganization
This commit is contained in:
1 parent
6706dfe634
commit
054e37dfb7
266 files changed
+98
-620
No files matched your search
+2
@@ -0,0 +1,2 @@
|
||||
import moveHandle from './moveHandle';
|
||||
export default moveHandle;
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import { cornerstone } from 'meteor/ohif:cornerstone';
|
||||
import setHandlesPosition from './setHandlesPosition';
|
||||
import calculateLongestAndShortestDiameters from '../calculateLongestAndShortestDiameters';
|
||||
|
||||
export default function (mouseEventData, toolType, data, handle, doneMovingCallback, preventHandleOutsideImage) {
|
||||
const element = mouseEventData.element;
|
||||
const distanceFromTool = {
|
||||
x: handle.x - mouseEventData.currentPoints.image.x,
|
||||
y: handle.y - mouseEventData.currentPoints.image.y
|
||||
};
|
||||
|
||||
const mouseDragCallback = event => {
|
||||
const eventData = event.detail;
|
||||
handle.active = true;
|
||||
|
||||
if (handle.index === undefined || handle.index === null) {
|
||||
handle.x = eventData.currentPoints.image.x + distanceFromTool.x;
|
||||
handle.y = eventData.currentPoints.image.y + distanceFromTool.y;
|
||||
} else {
|
||||
setHandlesPosition(handle, eventData, data);
|
||||
}
|
||||
|
||||
if (preventHandleOutsideImage) {
|
||||
handle.x = Math.max(handle.x, 0);
|
||||
handle.x = Math.min(handle.x, eventData.image.width);
|
||||
|
||||
handle.y = Math.max(handle.y, 0);
|
||||
handle.y = Math.min(handle.y, eventData.image.height);
|
||||
}
|
||||
|
||||
cornerstone.updateImage(element);
|
||||
|
||||
const measurementModifiedHandler = () => {
|
||||
const eventType = 'cornerstonetoolsmeasurementmodified';
|
||||
const modifiedEventData = {
|
||||
toolType,
|
||||
element,
|
||||
measurementData: data
|
||||
};
|
||||
|
||||
calculateLongestAndShortestDiameters(mouseEventData, data);
|
||||
|
||||
cornerstone.triggerEvent(element, eventType, modifiedEventData);
|
||||
|
||||
element.removeEventListener('cornerstoneimagerendered', measurementModifiedHandler);
|
||||
};
|
||||
|
||||
// Wait on image render before triggering the modified event
|
||||
element.addEventListener('cornerstoneimagerendered', measurementModifiedHandler);
|
||||
};
|
||||
|
||||
element.addEventListener('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();
|
||||
}
|
||||
};
|
||||
|
||||
// Bind the event listener for image rendering
|
||||
element.addEventListener('cornerstoneimagerendered', imageRenderedHandler);
|
||||
|
||||
const mouseUpCallback = () => {
|
||||
element.removeEventListener('cornerstonetoolsmousedrag', mouseDragCallback);
|
||||
element.removeEventListener('cornerstonetoolsmouseup', mouseUpCallback);
|
||||
element.removeEventListener('cornerstonetoolsmouseclick', mouseUpCallback);
|
||||
element.removeEventListener('cornerstoneimagerendered', imageRenderedHandler);
|
||||
cornerstone.updateImage(element);
|
||||
|
||||
if (typeof doneMovingCallback === 'function') {
|
||||
doneMovingCallback();
|
||||
}
|
||||
};
|
||||
|
||||
element.addEventListener('cornerstonetoolsmouseup', mouseUpCallback);
|
||||
element.addEventListener('cornerstonetoolsmouseclick', mouseUpCallback);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import { cornerstoneMath } from 'meteor/ohif:cornerstone';
|
||||
|
||||
// Move long-axis start point
|
||||
export default function(eventData, data) {
|
||||
const { distance } = cornerstoneMath.point;
|
||||
const { start, end, perpendicularStart, perpendicularEnd } = data.handles;
|
||||
const { image } = eventData.currentPoints;
|
||||
|
||||
const longLine = {
|
||||
start: {
|
||||
x: start.x,
|
||||
y: start.y
|
||||
},
|
||||
end: {
|
||||
x: end.x,
|
||||
y: end.y
|
||||
}
|
||||
};
|
||||
|
||||
const perpendicularLine = {
|
||||
start: {
|
||||
x: perpendicularStart.x,
|
||||
y: perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: perpendicularEnd.x,
|
||||
y: perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
const intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
const distanceFromPerpendicularP1 = distance(perpendicularStart, intersection);
|
||||
const distanceFromPerpendicularP2 = distance(perpendicularEnd, intersection);
|
||||
|
||||
const distanceToLineP2 = distance(end, intersection);
|
||||
const newLineLength = distance(end, image);
|
||||
|
||||
if (newLineLength <= distanceToLineP2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const dx = (end.x - image.x) / newLineLength;
|
||||
const dy = (end.y - image.y) / newLineLength;
|
||||
|
||||
const k = distanceToLineP2 / newLineLength;
|
||||
|
||||
const newIntersection = {
|
||||
x: end.x + ((image.x - end.x) * k),
|
||||
y: end.y + ((image.y - end.y) * k)
|
||||
};
|
||||
|
||||
perpendicularStart.x = newIntersection.x - distanceFromPerpendicularP1 * dy;
|
||||
perpendicularStart.y = newIntersection.y + distanceFromPerpendicularP1 * dx;
|
||||
|
||||
perpendicularEnd.x = newIntersection.x + distanceFromPerpendicularP2 * dy;
|
||||
perpendicularEnd.y = newIntersection.y - distanceFromPerpendicularP2 * dx;
|
||||
|
||||
return true;
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import { cornerstoneMath } from 'meteor/ohif:cornerstone';
|
||||
|
||||
// Move long-axis end point
|
||||
export default function(eventData, data) {
|
||||
const { distance } = cornerstoneMath.point;
|
||||
const { start, end, perpendicularStart, perpendicularEnd } = data.handles;
|
||||
const { image } = eventData.currentPoints;
|
||||
|
||||
const longLine = {
|
||||
start: {
|
||||
x: start.x,
|
||||
y: start.y
|
||||
},
|
||||
end: {
|
||||
x: end.x,
|
||||
y: end.y
|
||||
}
|
||||
};
|
||||
|
||||
const perpendicularLine = {
|
||||
start: {
|
||||
x: perpendicularStart.x,
|
||||
y: perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: perpendicularEnd.x,
|
||||
y: perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
const intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
const distanceFromPerpendicularP1 = distance(perpendicularStart, intersection);
|
||||
const distanceFromPerpendicularP2 = distance(perpendicularEnd, intersection);
|
||||
|
||||
const distanceToLineP2 = distance(start, intersection);
|
||||
const newLineLength = distance(start, image);
|
||||
|
||||
if (newLineLength <= distanceToLineP2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const dx = (start.x - image.x) / newLineLength;
|
||||
const dy = (start.y - image.y) / newLineLength;
|
||||
|
||||
const k = distanceToLineP2 / newLineLength;
|
||||
|
||||
const newIntersection = {
|
||||
x: start.x + ((image.x - start.x) * k),
|
||||
y: start.y + ((image.y - start.y) * k)
|
||||
};
|
||||
|
||||
perpendicularStart.x = newIntersection.x + distanceFromPerpendicularP1 * dy;
|
||||
perpendicularStart.y = newIntersection.y - distanceFromPerpendicularP1 * dx;
|
||||
|
||||
perpendicularEnd.x = newIntersection.x - distanceFromPerpendicularP2 * dy;
|
||||
perpendicularEnd.y = newIntersection.y + distanceFromPerpendicularP2 * dx;
|
||||
|
||||
return true;
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
import { cornerstoneMath } from 'meteor/ohif:cornerstone';
|
||||
|
||||
// Move perpendicular line start point
|
||||
export default function(eventData, data) {
|
||||
const { distance } = cornerstoneMath.point;
|
||||
const { start, end, perpendicularStart, perpendicularEnd } = data.handles;
|
||||
|
||||
const fudgeFactor = 1;
|
||||
|
||||
const fixedPoint = perpendicularEnd;
|
||||
const movedPoint = eventData.currentPoints.image;
|
||||
|
||||
const distanceFromFixed = cornerstoneMath.lineSegment.distanceToPoint(data.handles, fixedPoint);
|
||||
const distanceFromMoved = cornerstoneMath.lineSegment.distanceToPoint(data.handles, movedPoint);
|
||||
|
||||
const distanceBetweenPoints = distance(fixedPoint, movedPoint);
|
||||
|
||||
const total = distanceFromFixed + distanceFromMoved;
|
||||
|
||||
if (distanceBetweenPoints <= distanceFromFixed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const length = distance(start, end);
|
||||
if (length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const dx = (start.x - end.x) / length;
|
||||
const dy = (start.y - end.y) / length;
|
||||
|
||||
const adjustedLineP1 = {
|
||||
x: start.x - fudgeFactor * dx,
|
||||
y: start.y - fudgeFactor * dy
|
||||
};
|
||||
const adjustedLineP2 = {
|
||||
x: end.x + fudgeFactor * dx,
|
||||
y: end.y + fudgeFactor * dy
|
||||
};
|
||||
|
||||
perpendicularStart.x = movedPoint.x;
|
||||
perpendicularStart.y = movedPoint.y;
|
||||
perpendicularEnd.x = movedPoint.x - total * dy;
|
||||
perpendicularEnd.y = movedPoint.y + total * dx;
|
||||
|
||||
const longLine = {
|
||||
start: {
|
||||
x: start.x,
|
||||
y: start.y
|
||||
},
|
||||
end: {
|
||||
x: end.x,
|
||||
y: end.y
|
||||
}
|
||||
};
|
||||
|
||||
const perpendicularLine = {
|
||||
start: {
|
||||
x: perpendicularStart.x,
|
||||
y: perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: perpendicularEnd.x,
|
||||
y: perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
const intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
if (!intersection) {
|
||||
if (distance(movedPoint, start) > distance(movedPoint, end)) {
|
||||
perpendicularStart.x = adjustedLineP2.x + distanceFromMoved * dy;
|
||||
perpendicularStart.y = adjustedLineP2.y - distanceFromMoved * dx;
|
||||
perpendicularEnd.x = perpendicularStart.x - total * dy;
|
||||
perpendicularEnd.y = perpendicularStart.y + total * dx;
|
||||
} else {
|
||||
perpendicularStart.x = adjustedLineP1.x + distanceFromMoved * dy;
|
||||
perpendicularStart.y = adjustedLineP1.y - distanceFromMoved * dx;
|
||||
perpendicularEnd.x = perpendicularStart.x - total * dy;
|
||||
perpendicularEnd.y = perpendicularStart.y + total * dx;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
import { cornerstoneMath } from 'meteor/ohif:cornerstone';
|
||||
|
||||
// Move perpendicular line end point
|
||||
export default function(eventData, data) {
|
||||
const { distance } = cornerstoneMath.point;
|
||||
const { start, end, perpendicularStart, perpendicularEnd } = data.handles;
|
||||
|
||||
const fudgeFactor = 1;
|
||||
|
||||
const fixedPoint = perpendicularStart;
|
||||
const movedPoint = eventData.currentPoints.image;
|
||||
|
||||
const distanceFromFixed = cornerstoneMath.lineSegment.distanceToPoint(data.handles, fixedPoint);
|
||||
const distanceFromMoved = cornerstoneMath.lineSegment.distanceToPoint(data.handles, movedPoint);
|
||||
|
||||
const distanceBetweenPoints = distance(fixedPoint, movedPoint);
|
||||
|
||||
const total = distanceFromFixed + distanceFromMoved;
|
||||
|
||||
if (distanceBetweenPoints <= distanceFromFixed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const length = distance(start, end);
|
||||
const dx = (start.x - end.x) / length;
|
||||
const dy = (start.y - end.y) / length;
|
||||
|
||||
const adjustedLineP1 = {
|
||||
x: start.x - fudgeFactor * dx,
|
||||
y: start.y - fudgeFactor * dy
|
||||
};
|
||||
const adjustedLineP2 = {
|
||||
x: end.x + fudgeFactor * dx,
|
||||
y: end.y + fudgeFactor * dy
|
||||
};
|
||||
|
||||
perpendicularStart.x = movedPoint.x + total * dy;
|
||||
perpendicularStart.y = movedPoint.y - total * dx;
|
||||
perpendicularEnd.x = movedPoint.x;
|
||||
perpendicularEnd.y = movedPoint.y;
|
||||
perpendicularEnd.locked = false;
|
||||
perpendicularStart.locked = false;
|
||||
|
||||
const longLine = {
|
||||
start: {
|
||||
x: start.x,
|
||||
y: start.y
|
||||
},
|
||||
end: {
|
||||
x: end.x,
|
||||
y: end.y
|
||||
}
|
||||
};
|
||||
|
||||
const perpendicularLine = {
|
||||
start: {
|
||||
x: perpendicularStart.x,
|
||||
y: perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: perpendicularEnd.x,
|
||||
y: perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
const intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
if (!intersection) {
|
||||
if (distance(movedPoint, start) > distance(movedPoint, end)) {
|
||||
perpendicularEnd.x = adjustedLineP2.x - distanceFromMoved * dy;
|
||||
perpendicularEnd.y = adjustedLineP2.y + distanceFromMoved * dx;
|
||||
perpendicularStart.x = perpendicularEnd.x + total * dy;
|
||||
perpendicularStart.y = perpendicularEnd.y - total * dx;
|
||||
} else {
|
||||
perpendicularEnd.x = adjustedLineP1.x - distanceFromMoved * dy;
|
||||
perpendicularEnd.y = adjustedLineP1.y + distanceFromMoved * dx;
|
||||
perpendicularStart.x = perpendicularEnd.x + total * dy;
|
||||
perpendicularStart.y = perpendicularEnd.y - total * dx;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
import { cornerstoneMath } from 'meteor/ohif:cornerstone';
|
||||
import perpendicularBothFixedLeft from './perpendicularBothFixedLeft';
|
||||
import perpendicularBothFixedRight from './perpendicularBothFixedRight';
|
||||
import perpendicularLeftFixedPoint from './perpendicularLeftFixedPoint';
|
||||
import perpendicularRightFixedPoint from './perpendicularRightFixedPoint';
|
||||
|
||||
// Sets position of handles(start, end, perpendicularStart, perpendicularEnd)
|
||||
export default function(handle, eventData, data) {
|
||||
let movedPoint,
|
||||
outOfBounds,
|
||||
result,
|
||||
intersection,
|
||||
d1,
|
||||
d2;
|
||||
|
||||
let longLine = {},
|
||||
perpendicularLine = {};
|
||||
|
||||
if (handle.index === 0) {
|
||||
// if long-axis start point is moved
|
||||
result = perpendicularBothFixedLeft(eventData, data);
|
||||
if (result) {
|
||||
handle.x = eventData.currentPoints.image.x;
|
||||
handle.y = eventData.currentPoints.image.y;
|
||||
} else {
|
||||
eventData.currentPoints.image.x = handle.x;
|
||||
eventData.currentPoints.image.y = handle.y;
|
||||
}
|
||||
|
||||
} else if (handle.index === 1) {
|
||||
// if long-axis end point is moved
|
||||
result = perpendicularBothFixedRight(eventData, data);
|
||||
if (result) {
|
||||
handle.x = eventData.currentPoints.image.x;
|
||||
handle.y = eventData.currentPoints.image.y;
|
||||
} else {
|
||||
eventData.currentPoints.image.x = handle.x;
|
||||
eventData.currentPoints.image.y = handle.y;
|
||||
}
|
||||
|
||||
} else if (handle.index === 2) {
|
||||
outOfBounds = false;
|
||||
// if perpendicular start point is moved
|
||||
longLine.start = {
|
||||
x: data.handles.start.x,
|
||||
y: data.handles.start.y
|
||||
};
|
||||
longLine.end = {
|
||||
x: data.handles.end.x,
|
||||
y: data.handles.end.y
|
||||
};
|
||||
|
||||
perpendicularLine.start = {
|
||||
x: data.handles.perpendicularEnd.x,
|
||||
y: data.handles.perpendicularEnd.y
|
||||
};
|
||||
perpendicularLine.end = {
|
||||
x: eventData.currentPoints.image.x,
|
||||
y: eventData.currentPoints.image.y
|
||||
};
|
||||
|
||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
if (!intersection) {
|
||||
perpendicularLine.end = {
|
||||
x: data.handles.perpendicularStart.x,
|
||||
y: data.handles.perpendicularStart.y
|
||||
};
|
||||
|
||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
||||
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
||||
|
||||
if (!intersection || d1 < 3 || d2 < 3) {
|
||||
outOfBounds = true;
|
||||
}
|
||||
}
|
||||
|
||||
movedPoint = false;
|
||||
|
||||
if (!outOfBounds) {
|
||||
movedPoint = perpendicularLeftFixedPoint(eventData, data);
|
||||
|
||||
if (!movedPoint) {
|
||||
eventData.currentPoints.image.x = data.handles.perpendicularStart.x;
|
||||
eventData.currentPoints.image.y = data.handles.perpendicularStart.y;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (handle.index === 3) {
|
||||
outOfBounds = false;
|
||||
|
||||
// if perpendicular end point is moved
|
||||
longLine.start = {
|
||||
x: data.handles.start.x,
|
||||
y: data.handles.start.y
|
||||
};
|
||||
longLine.end = {
|
||||
x: data.handles.end.x,
|
||||
y: data.handles.end.y
|
||||
};
|
||||
|
||||
perpendicularLine.start = {
|
||||
x: data.handles.perpendicularStart.x,
|
||||
y: data.handles.perpendicularStart.y
|
||||
};
|
||||
perpendicularLine.end = {
|
||||
x: eventData.currentPoints.image.x,
|
||||
y: eventData.currentPoints.image.y
|
||||
};
|
||||
|
||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
if (!intersection) {
|
||||
perpendicularLine.end = {
|
||||
x: data.handles.perpendicularEnd.x,
|
||||
y: data.handles.perpendicularEnd.y
|
||||
};
|
||||
|
||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
||||
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
||||
|
||||
if (!intersection || d1 < 3 || d2 < 3) {
|
||||
outOfBounds = true;
|
||||
}
|
||||
}
|
||||
|
||||
movedPoint = false;
|
||||
|
||||
if (!outOfBounds) {
|
||||
movedPoint = perpendicularRightFixedPoint(eventData, data);
|
||||
|
||||
if (!movedPoint) {
|
||||
eventData.currentPoints.image.x = data.handles.perpendicularEnd.x;
|
||||
eventData.currentPoints.image.y = data.handles.perpendicularEnd.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user