function planePlaneIntersection(targetImagePlane, referenceImagePlane) {
  var targetRowCosines = (0, _convertToVector2.default)(targetImagePlane.rowCosines);
  var targetColumnCosines = (0, _convertToVector2.default)(targetImagePlane.columnCosines);
  var targetImagePositionPatient = (0, _convertToVector2.default)(targetImagePlane.imagePositionPatient);
  var referenceRowCosines = (0, _convertToVector2.default)(referenceImagePlane.rowCosines);
  var referenceColumnCosines = (0, _convertToVector2.default)(referenceImagePlane.columnCosines);
  var referenceImagePositionPatient = (0, _convertToVector2.default)(referenceImagePlane.imagePositionPatient);

  // First, get the normals of each image plane
  var targetNormal = targetRowCosines.clone().cross(targetColumnCosines);
  var targetPlane = new _externalModules2.default.cornerstoneMath.Plane();

  targetPlane.setFromNormalAndCoplanarPoint(targetNormal, targetImagePositionPatient);

  var referenceNormal = referenceRowCosines.clone().cross(referenceColumnCosines);
  var referencePlane = new _externalModules2.default.cornerstoneMath.Plane();

  referencePlane.setFromNormalAndCoplanarPoint(referenceNormal, referenceImagePositionPatient);

  var originDirection = referencePlane.clone().intersectPlane(targetPlane);
  var origin = originDirection.origin;
  var direction = originDirection.direction;

  // Calculate the longest possible length in the reference image plane (the length of the diagonal)
  var bottomRight = imagePointToPatientPoint({
    x: referenceImagePlane.columns,
    y: referenceImagePlane.rows
  }, referenceImagePlane);
  var distance = referenceImagePositionPatient.distanceTo(bottomRight);

  // Use this distance to bound the ray intersecting the two planes
  var line = new _externalModules2.default.cornerstoneMath.Line3();

  line.start = origin;
  line.end = origin.clone().add(direction.multiplyScalar(distance));

  // Find the intersections between this line and the reference image plane's four sides
  var rect = getRectangleFromImagePlane(referenceImagePlane);
  var intersections = lineRectangleIntersection(line, rect);

  // Return the intersections between this line and the reference image plane's sides
  // In order to draw the reference line from the target image.
  if (intersections.length !== 2) {
    return;
  }

  return {
    start: intersections[0],
    end: intersections[1]
  };
}
// Gets the line of intersection between two planes in patient space
Gets the line of intersection between two planes in patient space
Gets the line of intersection between two planes in patient space
function planePlaneIntersection(targetImagePlane, referenceImagePlane) {
  var targetRowCosines = (0, _convertToVector2.default)(targetImagePlane.rowCosines);
  var targetColumnCosines = (0, _convertToVector2.default)(targetImagePlane.columnCosines);
  var targetImagePositionPatient = (0, _convertToVector2.default)(targetImagePlane.imagePositionPatient);
  var referenceRowCosines = (0, _convertToVector2.default)(referenceImagePlane.rowCosines);
  var referenceColumnCosines = (0, _convertToVector2.default)(referenceImagePlane.columnCosines);
  var referenceImagePositionPatient = (0, _convertToVector2.default)(referenceImagePlane.imagePositionPatient);
  var targetNormal = targetRowCosines.clone().cross(targetColumnCosines);
  var targetPlane = new _externalModules2.default.cornerstoneMath.Plane();
  targetPlane.setFromNormalAndCoplanarPoint(targetNormal, targetImagePositionPatient);
  var referenceNormal = referenceRowCosines.clone().cross(referenceColumnCosines);
  var referencePlane = new _externalModules2.default.cornerstoneMath.Plane();
  referencePlane.setFromNormalAndCoplanarPoint(referenceNormal, referenceImagePositionPatient);
  var originDirection = referencePlane.clone().intersectPlane(targetPlane);
  var origin = originDirection.origin;
  var direction = originDirection.direction;
  var bottomRight = imagePointToPatientPoint({
    x: referenceImagePlane.columns,
    y: referenceImagePlane.rows
  }, referenceImagePlane);
  var distance = referenceImagePositionPatient.distanceTo(bottomRight);
  var line = new _externalModules2.default.cornerstoneMath.Line3();
  line.start = origin;
  line.end = origin.clone().add(direction.multiplyScalar(distance));
  var rect = getRectangleFromImagePlane(referenceImagePlane);
  var intersections = lineRectangleIntersection(line, rect);
  if (intersections.length !== 2) {
    return;
  }
  return {
    start: intersections[0],
    end: intersections[1]
  };
}
function planePlaneIntersection ( targetImagePlane , referenceImagePlane ) { var targetRowCosines = ( 0 , _convertToVector2 . default ) ( targetImagePlane . rowCosines ) ; var targetColumnCosines = ( 0 , _convertToVector2 . default ) ( targetImagePlane . columnCosines ) ; var targetImagePositionPatient = ( 0 , _convertToVector2 . default ) ( targetImagePlane . imagePositionPatient ) ; var referenceRowCosines = ( 0 , _convertToVector2 . default ) ( referenceImagePlane . rowCosines ) ; var referenceColumnCosines = ( 0 , _convertToVector2 . default ) ( referenceImagePlane . columnCosines ) ; var referenceImagePositionPatient = ( 0 , _convertToVector2 . default ) ( referenceImagePlane . imagePositionPatient ) ; var targetNormal = targetRowCosines . clone ( ) . cross ( targetColumnCosines ) ; var targetPlane = new _externalModules2 . default . cornerstoneMath . Plane ( ) ; targetPlane . setFromNormalAndCoplanarPoint ( targetNormal , targetImagePositionPatient ) ; var referenceNormal = referenceRowCosines . clone ( ) . cross ( referenceColumnCosines ) ; var referencePlane = new _externalModules2 . default . cornerstoneMath . Plane ( ) ; referencePlane . setFromNormalAndCoplanarPoint ( referenceNormal , referenceImagePositionPatient ) ; var originDirection = referencePlane . clone ( ) . intersectPlane ( targetPlane ) ; var origin = originDirection . origin ; var direction = originDirection . direction ; var bottomRight = imagePointToPatientPoint ( { x : referenceImagePlane . columns , y : referenceImagePlane . rows } , referenceImagePlane ) ; var distance = referenceImagePositionPatient . distanceTo ( bottomRight ) ; var line = new _externalModules2 . default . cornerstoneMath . Line3 ( ) ; line . start = origin ; line . end = origin . clone ( ) . add ( direction . multiplyScalar ( distance ) ) ; var rect = getRectangleFromImagePlane ( referenceImagePlane ) ; var intersections = lineRectangleIntersection ( line , rect ) ; if ( intersections . length !== 2 ) { return ; } return { start : intersections [ 0 ] , end : intersections [ 1 ] } ; }
Gets the line of intersection between two planes in patient space
Gets the line of intersection between two planes in patient space
// First, get the normals of each image plane // Calculate the longest possible length in the reference image plane (the length of the diagonal) // Use this distance to bound the ray intersecting the two planes // Find the intersections between this line and the reference image plane's four sides // Return the intersections between this line and the reference image plane's sides // In order to draw the reference line from the target image.