LT-123: Add missing files
-Replace mathUtils.js functions with existed functions in cornerstoneMath.js -Add rectToPoints, doesIntersect, getIntersectionRect methods in cornerstoneMath.rect, -Add intersectLine method in cornerstoneMath.lineSegment
This commit is contained in:
parent
3812def9cc
commit
12a326c7fe
@ -318,7 +318,6 @@ Template.viewer.onRendered(function() {
|
||||
var viewports = $(".imageViewerViewport");
|
||||
var element = viewports.get(activeViewportIndex);
|
||||
var enabledElement = cornerstone.getEnabledElement(element);
|
||||
console.log(enabledElement);
|
||||
// Check value of rowPixelSpacing & columnPixelSpacing to define as unavailable
|
||||
if (!enabledElement || !enabledElement.image || !enabledElement.image.rowPixelSpacing || !enabledElement.image.columnPixelSpacing) {
|
||||
// Disable Lesion Buttons
|
||||
|
||||
@ -976,10 +976,95 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
||||
return Math.sqrt(distanceToPointSquared(lineSegment, point));
|
||||
}
|
||||
|
||||
// Returns intersection points of two lines
|
||||
function intersectLine(lineSegment1, lineSegment2) {
|
||||
var intersectionPoint = {};
|
||||
|
||||
var x1 = lineSegment1.start.x, y1 = lineSegment1.start.y, x2 = lineSegment1.end.x, y2 = lineSegment1.end.y,
|
||||
x3 = lineSegment2.start.x, y3 = lineSegment2.start.y, x4 = lineSegment2.end.x, y4 = lineSegment2.end.y;
|
||||
|
||||
var a1, a2, b1, b2, c1, c2; // Coefficients of line equations
|
||||
var r1, r2, r3, r4; // Sign values
|
||||
|
||||
var denom, offset, num; //Intermediate values
|
||||
|
||||
// Compute a1, b1, c1, where line joining points 1 and 2 is "a1 x + b1 y + c1 = 0"
|
||||
a1 = y2 - y1;
|
||||
b1 = x1 - x2;
|
||||
c1 = x2 * y1 - x1 * y2;
|
||||
|
||||
// Compute r3 and r4
|
||||
r3 = a1 * x3 + b1 * y3 + c1;
|
||||
r4 = a1 * x4 + b1 * y4 + c1;
|
||||
|
||||
/* Check signs of r3 and r4. If both point 3 and point 4 lie on
|
||||
* same side of line 1, the line segments do not intersect.
|
||||
*/
|
||||
|
||||
if (r3 !== 0 &&
|
||||
r4 !== 0 &&
|
||||
cornerstoneMath.sign(r3) === cornerstoneMath.sign(r4)) {
|
||||
intersectionPoint.x = 0;
|
||||
intersectionPoint.y = 0;
|
||||
intersectionPoint.intersected = false;
|
||||
return intersectionPoint;
|
||||
}
|
||||
|
||||
/* Compute a2, b2, c2 */
|
||||
|
||||
a2 = y4 - y3;
|
||||
b2 = x3 - x4;
|
||||
c2 = x4 * y3 - x3 * y4;
|
||||
|
||||
/* Compute r1 and r2 */
|
||||
|
||||
r1 = a2 * x1 + b2 * y1 + c2;
|
||||
r2 = a2 * x2 + b2 * y2 + c2;
|
||||
|
||||
/* Check signs of r1 and r2. If both point 1 and point 2 lie
|
||||
* on same side of second line segment, the line segments do
|
||||
* not intersect.
|
||||
*/
|
||||
|
||||
if (r1 !== 0 &&
|
||||
r2 !== 0 &&
|
||||
cornerstoneMath.sign(r1) === cornerstoneMath.sign(r2)) {
|
||||
intersectionPoint.x = 0;
|
||||
intersectionPoint.y = 0;
|
||||
intersectionPoint.intersected = false;
|
||||
return intersectionPoint;
|
||||
}
|
||||
|
||||
/* Line segments intersect: compute intersection point.
|
||||
*/
|
||||
|
||||
denom = (a1 * b2) - (a2 * b1);
|
||||
|
||||
offset = denom < 0 ? -denom / 2 : denom / 2;
|
||||
|
||||
/* The denom/2 is to get rounding instead of truncating. It
|
||||
* is added or subtracted to the numerator, depending upon the
|
||||
* sign of the numerator.
|
||||
*/
|
||||
|
||||
num = (b1 * c2) - (b2 * c1);
|
||||
var x = parseFloat(num / denom);
|
||||
|
||||
num = (a2 * c1) - (a1 * c2);
|
||||
var y = parseFloat(num / denom);
|
||||
|
||||
intersectionPoint.x = x;
|
||||
intersectionPoint.y = y;
|
||||
intersectionPoint.intersected = true;
|
||||
|
||||
return intersectionPoint;
|
||||
}
|
||||
|
||||
// module exports
|
||||
cornerstoneMath.lineSegment =
|
||||
{
|
||||
distanceToPoint : distanceToPoint
|
||||
distanceToPoint : distanceToPoint,
|
||||
intersectLine: intersectLine
|
||||
};
|
||||
|
||||
|
||||
@ -1012,9 +1097,15 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
||||
return radians * radianToDegreesFactor;
|
||||
}
|
||||
|
||||
// Returns sign of number
|
||||
function sign(x) {
|
||||
return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
|
||||
}
|
||||
|
||||
cornerstoneMath.clamp = clamp;
|
||||
cornerstoneMath.degToRad = degToRad;
|
||||
cornerstoneMath.radToDeg = radToDeg;
|
||||
cornerstoneMath.sign = sign;
|
||||
|
||||
return cornerstoneMath;
|
||||
}(cornerstoneMath));
|
||||
@ -1754,6 +1845,7 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
||||
|
||||
return (distance < maxDistance);
|
||||
}
|
||||
|
||||
function distanceToPoint(rect, point)
|
||||
{
|
||||
var minDistance = 655535;
|
||||
@ -1767,10 +1859,109 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
||||
return minDistance;
|
||||
}
|
||||
|
||||
// Returns rectangle points
|
||||
function rectToPoints (rect) {
|
||||
var rectPoints = {
|
||||
top: rect.top,
|
||||
left: rect.left,
|
||||
right: rect.left + rect.width,
|
||||
bottom: rect.top + rect.height
|
||||
};
|
||||
|
||||
return rectPoints;
|
||||
}
|
||||
|
||||
// Returns whether two rectangles are intersected
|
||||
function doesIntersect (rect1, rect2) {
|
||||
var intersectLeftRight;
|
||||
var intersectTopBottom;
|
||||
|
||||
var rect1Points = rectToPoints(rect1);
|
||||
var rect2Points = rectToPoints(rect2);
|
||||
|
||||
if (rect1.width >= 0) {
|
||||
if (rect2.width >= 0)
|
||||
intersectLeftRight = !((rect1Points.right <= rect2Points.left) || (rect2Points.right <= rect1Points.left));
|
||||
else
|
||||
intersectLeftRight = !((rect1Points.right <= rect2Points.right) || (rect2Points.left <= rect1Points.left));
|
||||
} else {
|
||||
if (rect2.width >= 0)
|
||||
intersectLeftRight = !((rect1Points.left <= rect2Points.left) || (rect2Points.right <= rect1Points.right));
|
||||
else
|
||||
intersectLeftRight = !((rect1Points.left <= rect2Points.right) || (rect2Points.left <= rect1Points.right));
|
||||
}
|
||||
|
||||
if (rect1.height >= 0) {
|
||||
if (rect2.height >= 0)
|
||||
intersectTopBottom = !((rect1Points.bottom <= rect2Points.top) || (rect2Points.bottom <= rect1Points.top));
|
||||
else
|
||||
intersectTopBottom = !((rect1Points.bottom <= rect2Points.bottom) || (rect2Points.top <= rect1Points.top));
|
||||
} else {
|
||||
if (rect2.height >= 0)
|
||||
intersectTopBottom = !((rect1Points.top <= rect2Points.top) || (rect2Points.bottom <= rect1Points.bottom));
|
||||
else
|
||||
intersectTopBottom = !((rect1Points.top <= rect2Points.bottom) || (rect2Points.top <= rect1Points.bottom));
|
||||
}
|
||||
|
||||
return intersectLeftRight && intersectTopBottom;
|
||||
}
|
||||
|
||||
// Returns intersection points of two rectangles
|
||||
function getIntersectionRect(rect1, rect2) {
|
||||
var intersectPoints = {};
|
||||
|
||||
if (!doesIntersect(rect1, rect2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rect1Points = rectToPoints(rect1);
|
||||
var rect2Points = rectToPoints(rect2);
|
||||
|
||||
if (rect1.width >= 0) {
|
||||
if (rect2.width >= 0) {
|
||||
intersectPoints.left = Math.max(rect1Points.left, rect2Points.left);
|
||||
intersectPoints.right = Math.min(rect1Points.right, rect2Points.right);
|
||||
} else {
|
||||
intersectPoints.left = Math.max(rect1Points.left, rect2Points.right);
|
||||
intersectPoints.right = Math.min(rect1Points.right, rect2Points.left);
|
||||
}
|
||||
} else {
|
||||
if (rect2.width >= 0) {
|
||||
intersectPoints.left = Math.min(rect1Points.left, rect2Points.right);
|
||||
intersectPoints.right = Math.max(rect1Points.right, rect2Points.left);
|
||||
} else {
|
||||
intersectPoints.left = Math.min(rect1Points.left, rect2Points.left);
|
||||
intersectPoints.right = Math.max(rect1Points.right, rect2Points.right);
|
||||
}
|
||||
}
|
||||
|
||||
if (rect1.height >= 0) {
|
||||
if (rect2.height >= 0) {
|
||||
intersectPoints.top = Math.max(rect1Points.top, rect2Points.top);
|
||||
intersectPoints.bottom = Math.min(rect1Points.bottom, rect2Points.bottom);
|
||||
} else {
|
||||
intersectPoints.top = Math.max(rect1Points.top, rect2Points.bottom);
|
||||
intersectPoints.bottom = Math.min(rect1Points.bottom, rect2Points.top);
|
||||
}
|
||||
} else {
|
||||
if (rect2.height >= 0) {
|
||||
intersectPoints.top = Math.min(rect1Points.top, rect2Points.bottom);
|
||||
intersectPoints.bottom = Math.max(rect1Points.bottom, rect2Points.top);
|
||||
} else {
|
||||
intersectPoints.top = Math.min(rect1Points.top, rect2Points.top);
|
||||
intersectPoints.bottom = Math.max(rect1Points.bottom, rect2Points.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
return intersectPoints;
|
||||
|
||||
}
|
||||
|
||||
// module exports
|
||||
cornerstoneMath.rect =
|
||||
{
|
||||
distanceToPoint : distanceToPoint
|
||||
rectToLineSegments : distanceToPoint,
|
||||
getIntersectionRect : getIntersectionRect
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -237,13 +237,35 @@
|
||||
// Move long-axis start point
|
||||
function perpendicularBothFixedLeft(eventData, data) {
|
||||
|
||||
var intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularStart, data.handles.perpendicularEnd);
|
||||
var longLine = {
|
||||
start: {
|
||||
x: data.handles.start.x,
|
||||
y: data.handles.start.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.end.x,
|
||||
y: data.handles. end.y
|
||||
}
|
||||
};
|
||||
|
||||
var distanceFromPerpendicularP1 = getDistance(data.handles.perpendicularStart, intersection);
|
||||
var distanceFromPerpendicularP2 = getDistance(data.handles.perpendicularEnd, intersection);
|
||||
var perpendicularLine = {
|
||||
start: {
|
||||
x: data.handles.perpendicularStart.x,
|
||||
y: data.handles.perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.perpendicularEnd.x,
|
||||
y: data.handles. perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
var distanceToLineP2 = getDistance(data.handles.end, intersection);
|
||||
var newLineLength = getDistance(data.handles.end, eventData.currentPoints.image);
|
||||
var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
var distanceFromPerpendicularP1 = cornerstoneMath.point.distance(data.handles.perpendicularStart, intersection);
|
||||
var distanceFromPerpendicularP2 = cornerstoneMath.point.distance(data.handles.perpendicularEnd, intersection);
|
||||
|
||||
var distanceToLineP2 = cornerstoneMath.point.distance(data.handles.end, intersection);
|
||||
var newLineLength = cornerstoneMath.point.distance(data.handles.end, eventData.currentPoints.image);
|
||||
|
||||
if (newLineLength <= distanceToLineP2) {
|
||||
return false;
|
||||
@ -272,13 +294,35 @@
|
||||
// Move long-axis end point
|
||||
function perpendicularBothFixedRight(eventData, data) {
|
||||
|
||||
var intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularStart, data.handles.perpendicularEnd);
|
||||
var longLine = {
|
||||
start: {
|
||||
x: data.handles.start.x,
|
||||
y: data.handles.start.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.end.x,
|
||||
y: data.handles. end.y
|
||||
}
|
||||
};
|
||||
|
||||
var distanceFromPerpendicularP1 = getDistance(data.handles.perpendicularStart, intersection);
|
||||
var distanceFromPerpendicularP2 = getDistance(data.handles.perpendicularEnd, intersection);
|
||||
var perpendicularLine = {
|
||||
start: {
|
||||
x: data.handles.perpendicularStart.x,
|
||||
y: data.handles.perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.perpendicularEnd.x,
|
||||
y: data.handles. perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
var distanceToLineP2 = getDistance(data.handles.start, intersection);
|
||||
var newLineLength = getDistance(data.handles.start, eventData.currentPoints.image);
|
||||
var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
var distanceFromPerpendicularP1 = cornerstoneMath.point.distance(data.handles.perpendicularStart, intersection);
|
||||
var distanceFromPerpendicularP2 = cornerstoneMath.point.distance(data.handles.perpendicularEnd, intersection);
|
||||
|
||||
var distanceToLineP2 = cornerstoneMath.point.distance(data.handles.start, intersection);
|
||||
var newLineLength = cornerstoneMath.point.distance(data.handles.start, eventData.currentPoints.image);
|
||||
|
||||
if (newLineLength <= distanceToLineP2) {
|
||||
return false;
|
||||
@ -311,12 +355,11 @@
|
||||
var fixedPoint = data.handles.perpendicularEnd;
|
||||
var movedPoint = eventData.currentPoints.image;
|
||||
|
||||
var nearestFromFixed = getDistanceFromPointToLine(fixedPoint, data.handles.start, data.handles.end);
|
||||
var distanceFromFixed = nearestFromFixed.distance;
|
||||
var nearestFromMoved = getDistanceFromPointToLine(movedPoint, data.handles.start, data.handles.end);
|
||||
var distanceFromMoved = nearestFromMoved.distance;
|
||||
|
||||
var distanceBetweenPoints = getDistance(fixedPoint, movedPoint);
|
||||
var distanceFromFixed = cornerstoneMath.lineSegment.distanceToPoint(data.handles, fixedPoint);
|
||||
var distanceFromMoved = cornerstoneMath.lineSegment.distanceToPoint(data.handles, movedPoint);
|
||||
|
||||
var distanceBetweenPoints = cornerstoneMath.point.distance(fixedPoint, movedPoint);
|
||||
|
||||
var total = distanceFromFixed + distanceFromMoved;
|
||||
|
||||
@ -324,7 +367,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
var length = getDistance(data.handles.start, data.handles.end);
|
||||
var length = cornerstoneMath.point.distance(data.handles.start, data.handles.end);
|
||||
var dx = (data.handles.start.x - data.handles.end.x) / length;
|
||||
var dy = (data.handles.start.y - data.handles.end.y) / length;
|
||||
|
||||
@ -342,9 +385,31 @@
|
||||
data.handles.perpendicularEnd.x = movedPoint.x - total * dy;
|
||||
data.handles.perpendicularEnd.y = movedPoint.y + total * dx;
|
||||
|
||||
var intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularStart, data.handles.perpendicularEnd);
|
||||
var longLine = {
|
||||
start: {
|
||||
x: data.handles.start.x,
|
||||
y: data.handles.start.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.end.x,
|
||||
y: data.handles.end.y
|
||||
}
|
||||
};
|
||||
|
||||
var perpendicularLine = {
|
||||
start: {
|
||||
x: data.handles.perpendicularStart.x,
|
||||
y: data.handles.perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.perpendicularEnd.x,
|
||||
y: data.handles.perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
if (!intersection.intersected) {
|
||||
if (getDistance(movedPoint, data.handles.start) > getDistance(movedPoint, data.handles.end)) {
|
||||
if (cornerstoneMath.point.distance(movedPoint, data.handles.start) > cornerstoneMath.point.distance(movedPoint, data.handles.end)) {
|
||||
data.handles.perpendicularStart.x = adjustedLineP2.x + distanceFromMoved * dy;
|
||||
data.handles.perpendicularStart.y = adjustedLineP2.y - distanceFromMoved * dx;
|
||||
data.handles.perpendicularEnd.x = data.handles.perpendicularStart.x - total * dy;
|
||||
@ -373,12 +438,10 @@
|
||||
var fixedPoint = data.handles.perpendicularStart;
|
||||
var movedPoint = eventData.currentPoints.image;
|
||||
|
||||
var nearestFromFixed = getDistanceFromPointToLine(fixedPoint, data.handles.start, data.handles.end);
|
||||
var distanceFromFixed = nearestFromFixed.distance;
|
||||
var nearestFromMoved = getDistanceFromPointToLine(movedPoint, data.handles.start, data.handles.end);
|
||||
var distanceFromMoved = nearestFromMoved.distance;
|
||||
var distanceFromFixed = cornerstoneMath.lineSegment.distanceToPoint(data.handles, fixedPoint);
|
||||
var distanceFromMoved = cornerstoneMath.lineSegment.distanceToPoint(data.handles, movedPoint);
|
||||
|
||||
var distanceBetweenPoints = getDistance(fixedPoint, movedPoint);
|
||||
var distanceBetweenPoints = cornerstoneMath.point.distance(fixedPoint, movedPoint);
|
||||
|
||||
var total = distanceFromFixed + distanceFromMoved;
|
||||
|
||||
@ -386,7 +449,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
var length = getDistance(data.handles.start, data.handles.end);
|
||||
var length = cornerstoneMath.point.distance(data.handles.start, data.handles.end);
|
||||
var dx = (data.handles.start.x - data.handles.end.x) / length;
|
||||
var dy = (data.handles.start.y - data.handles.end.y) / length;
|
||||
|
||||
@ -404,9 +467,31 @@
|
||||
data.handles.perpendicularEnd.x = movedPoint.x;
|
||||
data.handles.perpendicularEnd.y = movedPoint.y;
|
||||
|
||||
var intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularStart, data.handles.perpendicularEnd);
|
||||
var longLine = {
|
||||
start: {
|
||||
x: data.handles.start.x,
|
||||
y: data.handles.start.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.end.x,
|
||||
y: data.handles.end.y
|
||||
}
|
||||
};
|
||||
|
||||
var perpendicularLine = {
|
||||
start: {
|
||||
x: data.handles.perpendicularStart.x,
|
||||
y: data.handles.perpendicularStart.y
|
||||
},
|
||||
end: {
|
||||
x: data.handles.perpendicularEnd.x,
|
||||
y: data.handles.perpendicularEnd.y
|
||||
}
|
||||
};
|
||||
|
||||
var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
if (!intersection.intersected) {
|
||||
if (getDistance(movedPoint, data.handles.start) > getDistance(movedPoint, data.handles.end)) {
|
||||
if (cornerstoneMath.point.distance(movedPoint, data.handles.start) > cornerstoneMath.point.distance(movedPoint, data.handles.end)) {
|
||||
data.handles.perpendicularEnd.x = adjustedLineP2.x - distanceFromMoved * dy;
|
||||
data.handles.perpendicularEnd.y = adjustedLineP2.y + distanceFromMoved * dx;
|
||||
data.handles.perpendicularStart.x = data.handles.perpendicularEnd.x + total * dy;
|
||||
@ -438,6 +523,8 @@
|
||||
d1,
|
||||
d2;
|
||||
|
||||
var longLine = {},
|
||||
perpendicularLine = {};
|
||||
|
||||
if (handle.index === 0) {
|
||||
// if long-axis start point is moved
|
||||
@ -464,13 +551,20 @@
|
||||
} 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};
|
||||
|
||||
intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularEnd, eventData.currentPoints.image);
|
||||
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.intersected) {
|
||||
intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularEnd, data.handles.perpendicularStart);
|
||||
perpendicularLine.end = {x: data.handles.perpendicularStart.x, y: data.handles.perpendicularStart.y};
|
||||
|
||||
d1 = getDistance(intersection, data.handles.start);
|
||||
d2 = getDistance(intersection, data.handles.end);
|
||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
||||
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
||||
|
||||
if (!intersection.intersected || d1 < 3 || d2 < 3) {
|
||||
outOfBounds = true;
|
||||
@ -490,14 +584,22 @@
|
||||
|
||||
} 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};
|
||||
|
||||
intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularStart, eventData.currentPoints.image);
|
||||
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.intersected) {
|
||||
intersection = getLineIntersection(data.handles.start, data.handles.end, data.handles.perpendicularEnd, data.handles.perpendicularStart);
|
||||
perpendicularLine.end = {x: data.handles.perpendicularEnd.x, y: data.handles.perpendicularEnd.y};
|
||||
|
||||
d1 = getDistance(intersection, data.handles.start);
|
||||
d2 = getDistance(intersection, data.handles.end);
|
||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||
|
||||
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
||||
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
||||
|
||||
if (!intersection.intersected || d1 < 3 || d2 < 3) {
|
||||
outOfBounds = true;
|
||||
@ -742,14 +844,14 @@
|
||||
var minDistance;
|
||||
|
||||
// Find distances between handles and textBox
|
||||
var distanceToStart = getDistance(data.handles.start, data.handles.textBox);
|
||||
var distanceToStart = cornerstoneMath.point.distance(data.handles.start, data.handles.textBox);
|
||||
distancesArr.push({
|
||||
distance: distanceToStart,
|
||||
point: data.handles.start
|
||||
});
|
||||
minDistance = distanceToStart;
|
||||
|
||||
var distanceToEnd = getDistance(data.handles.end, data.handles.textBox);
|
||||
var distanceToEnd = cornerstoneMath.point.distance(data.handles.end, data.handles.textBox);
|
||||
distancesArr.push({
|
||||
distance: distanceToEnd,
|
||||
point: data.handles.end
|
||||
@ -758,7 +860,7 @@
|
||||
minDistance = Math.min(distanceToEnd, minDistance);
|
||||
|
||||
if (data.handles.perpendicularStart.x && data.handles.perpendicularStart.y) {
|
||||
var distanceToPerpendicularStart = getDistance(data.handles.perpendicularStart, data.handles.textBox);
|
||||
var distanceToPerpendicularStart = cornerstoneMath.point.distance(data.handles.perpendicularStart, data.handles.textBox);
|
||||
distancesArr.push({
|
||||
distance: distanceToPerpendicularStart,
|
||||
point: data.handles.perpendicularStart
|
||||
@ -769,7 +871,7 @@
|
||||
}
|
||||
|
||||
if (data.handles.perpendicularEnd.x && data.handles.perpendicularEnd.y) {
|
||||
var distanceToPerpendicularEnd = getDistance(data.handles.perpendicularEnd, data.handles.textBox);
|
||||
var distanceToPerpendicularEnd = cornerstoneMath.point.distance(data.handles.perpendicularEnd, data.handles.textBox);
|
||||
distancesArr.push({
|
||||
distance: distanceToPerpendicularEnd,
|
||||
point: data.handles.perpendicularEnd
|
||||
@ -860,6 +962,9 @@
|
||||
var wx = (data.handles.perpendicularStart.x - data.handles.perpendicularEnd.x) * (eventData.image.columnPixelSpacing || 1);
|
||||
var wy = (data.handles.perpendicularStart.y - data.handles.perpendicularEnd.y) * (eventData.image.rowPixelSpacing || 1);
|
||||
var width = Math.sqrt(wx * wx + wy * wy);
|
||||
if (!width) {
|
||||
width = 0;
|
||||
}
|
||||
|
||||
// Draw the textbox
|
||||
var suffix = ' mm';
|
||||
|
||||
@ -113,98 +113,12 @@
|
||||
|
||||
}
|
||||
|
||||
function doesIntersect(canvasBounds, imageBounds) {
|
||||
var intersectLeftRight;
|
||||
var intersectTopBottom;
|
||||
|
||||
if (canvasBounds.width >= 0) {
|
||||
if (imageBounds.width >= 0)
|
||||
intersectLeftRight = !((canvasBounds.right <= imageBounds.left) || (imageBounds.right <= canvasBounds.left));
|
||||
else
|
||||
intersectLeftRight = !((canvasBounds.right <= imageBounds.right) || (imageBounds.left <= canvasBounds.left));
|
||||
} else {
|
||||
if (imageBounds.width >= 0)
|
||||
intersectLeftRight = !((canvasBounds.left <= imageBounds.left) || (imageBounds.right <= canvasBounds.right));
|
||||
else
|
||||
intersectLeftRight = !((canvasBounds.left <= imageBounds.right) || (imageBounds.left <= canvasBounds.right));
|
||||
}
|
||||
|
||||
if (canvasBounds.height >= 0) {
|
||||
if (imageBounds.height >= 0)
|
||||
intersectTopBottom = !((canvasBounds.bottom <= imageBounds.top) || (imageBounds.bottom <= canvasBounds.top));
|
||||
else
|
||||
intersectTopBottom = !((canvasBounds.bottom <= imageBounds.bottom) || (imageBounds.top <= canvasBounds.top));
|
||||
} else {
|
||||
if (imageBounds.height >= 0)
|
||||
intersectTopBottom = !((canvasBounds.top <= imageBounds.top) || (imageBounds.bottom <= canvasBounds.bottom));
|
||||
else
|
||||
intersectTopBottom = !((canvasBounds.top <= imageBounds.bottom) || (imageBounds.top <= canvasBounds.bottom));
|
||||
}
|
||||
|
||||
return intersectLeftRight && intersectTopBottom;
|
||||
}
|
||||
|
||||
function getIntersectionRectangle(canvasBounds, imageBounds) {
|
||||
var intersectPoints = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0
|
||||
};
|
||||
|
||||
if (!doesIntersect(canvasBounds, imageBounds)) {
|
||||
return intersectPoints;
|
||||
|
||||
}
|
||||
|
||||
if (canvasBounds.width >= 0) {
|
||||
if (imageBounds.width >= 0) {
|
||||
intersectPoints.left = Math.max(canvasBounds.left, imageBounds.left);
|
||||
intersectPoints.right = Math.min(canvasBounds.right, imageBounds.right);
|
||||
} else {
|
||||
intersectPoints.left = Math.max(canvasBounds.left, imageBounds.right);
|
||||
intersectPoints.right = Math.min(canvasBounds.right, imageBounds.left);
|
||||
}
|
||||
} else {
|
||||
if (imageBounds.width >= 0) {
|
||||
intersectPoints.left = Math.min(canvasBounds.left, imageBounds.right);
|
||||
intersectPoints.right = Math.max(canvasBounds.right, imageBounds.left);
|
||||
} else {
|
||||
intersectPoints.left = Math.min(canvasBounds.left, imageBounds.left);
|
||||
intersectPoints.right = Math.max(canvasBounds.right, imageBounds.right);
|
||||
}
|
||||
}
|
||||
|
||||
if (canvasBounds.height >= 0) {
|
||||
if (imageBounds.height >= 0) {
|
||||
intersectPoints.top = Math.max(canvasBounds.top, imageBounds.top);
|
||||
intersectPoints.bottom = Math.min(canvasBounds.bottom, imageBounds.bottom);
|
||||
} else {
|
||||
intersectPoints.top = Math.max(canvasBounds.top, imageBounds.bottom);
|
||||
intersectPoints.bottom = Math.min(canvasBounds.bottom, imageBounds.top);
|
||||
}
|
||||
} else {
|
||||
if (imageBounds.height >= 0) {
|
||||
intersectPoints.top = Math.min(canvasBounds.top, imageBounds.bottom);
|
||||
intersectPoints.bottom = Math.max(canvasBounds.bottom, imageBounds.top);
|
||||
} else {
|
||||
intersectPoints.top = Math.min(canvasBounds.top, imageBounds.top);
|
||||
intersectPoints.bottom = Math.max(canvasBounds.bottom, imageBounds.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
return intersectPoints;
|
||||
|
||||
}
|
||||
|
||||
// Computes the max bound for scales on the image
|
||||
function computeScaleBounds(eventData, canvasSize, imageSize, horizontalReduction, verticalReduction) {
|
||||
|
||||
var canvasBounds = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: canvasSize.width,
|
||||
bottom: canvasSize.height,
|
||||
width: canvasSize.width,
|
||||
height: canvasSize.height
|
||||
};
|
||||
@ -214,8 +128,6 @@
|
||||
canvasBounds = {
|
||||
left: canvasBounds.left + hReduction,
|
||||
top: canvasBounds.top + vReduction,
|
||||
right: (canvasBounds.left + hReduction) + (canvasBounds.width - 2 * hReduction),
|
||||
bottom: (canvasBounds.top + vReduction) + (canvasBounds.height - 2 * vReduction),
|
||||
width: canvasBounds.width - 2 * hReduction,
|
||||
height: canvasBounds.height - 2 * vReduction
|
||||
};
|
||||
@ -245,14 +157,11 @@
|
||||
var imageBounds = {
|
||||
left: startPointCanvasImageBounds.x + hReduction,
|
||||
top: startPointCanvasImageBounds.y + vReduction,
|
||||
right: (startPointCanvasImageBounds.x + hReduction) + (imageBoundsWidth - 2 * hReduction),
|
||||
bottom: (startPointCanvasImageBounds.y + vReduction) + (imageBoundsHeight - 2 * vReduction),
|
||||
width: imageBoundsWidth - 2 * hReduction,
|
||||
height: imageBoundsHeight - 2 * vReduction
|
||||
|
||||
};
|
||||
|
||||
return getIntersectionRectangle(canvasBounds, imageBounds);
|
||||
return cornerstoneMath.rect.getIntersectionRect(canvasBounds, imageBounds);
|
||||
|
||||
}
|
||||
|
||||
@ -281,17 +190,15 @@
|
||||
var verticalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
|
||||
var horizontalIntervalScale = (10.0 / eventData.enabledElement.image.rowPixelSpacing) * eventData.viewport.scale;
|
||||
|
||||
if (!canvasSize.width || !canvasSize.height || !imageSize.width || !imageSize.height ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 0.1 and 0.05 gives margin to horizontal and vertical lines
|
||||
var hscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.1, 0.05);
|
||||
var vscaleBounds = computeScaleBounds(eventData, canvasSize, imageSize, 0.05, 0.1);
|
||||
|
||||
if (!canvasSize.width || !canvasSize.height || !imageSize.width || !imageSize.height || !hscaleBounds || !vscaleBounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
var config = {
|
||||
width: imageSize.width,
|
||||
height: imageSize.height,
|
||||
hscaleBounds: hscaleBounds,
|
||||
vscaleBounds: vscaleBounds,
|
||||
verticalMinorTick: verticalIntervalScale,
|
||||
|
||||
@ -99,7 +99,6 @@ Package.onUse(function(api) {
|
||||
api.addFiles('lib/activateLesion.js', 'client');
|
||||
api.addFiles('lib/deactivateAllToolData.js', 'client');
|
||||
api.addFiles('lib/clearTools.js', 'client');
|
||||
api.addFiles('lib/mathUtils.js', 'client');
|
||||
|
||||
// Export gloabal functions
|
||||
api.export('activateLesion','client');
|
||||
@ -112,12 +111,6 @@ Package.onUse(function(api) {
|
||||
api.export('clearTools', 'client');
|
||||
api.export('LesionManager', 'client');
|
||||
|
||||
// Export mathUtils functions
|
||||
api.export('sign','client');
|
||||
api.export('getLineIntersection','client');
|
||||
api.export('getDistance','client');
|
||||
api.export('getDistanceFromPointToLine','client');
|
||||
|
||||
// Export client-side collections
|
||||
api.export('LesionLocations', 'client');
|
||||
api.export('LocationResponses', 'client');
|
||||
|
||||
@ -127,3 +127,4 @@ Template.worklistResult.events({
|
||||
search();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user