public MammographyImageSpatialTransform(IGraphic ownerGraphic, int rows, int columns, double pixelSpacingX, double pixelSpacingY, double pixelAspectRatioX, double pixelAspectRatioY, PatientOrientation patientOrientation, string laterality)
: base(ownerGraphic, rows, columns, pixelSpacingX, pixelSpacingY, pixelAspectRatioX, pixelAspectRatioY)
{
// image coordinates are defined with X and Y being equivalent to the screen axes (right and down) and with Z = X cross Y (into the screen)
Vector3D imagePosterior, imageHead, imageLeft; // patient orientation vectors in image space
GetPatientOrientationVectors(patientOrientation, out imageHead, out imageLeft, out imagePosterior);
// no adjustments if the posterior direction is not represented in the image
if ((_imagePosterior = imagePosterior) != null)
{
Vector3D normativePosterior, normativeHead, normativeLeft; // normative patient orientation vectors in image space
GetNormativeOrientationVectors(laterality, out normativeHead, out normativeLeft, out normativePosterior);
// only do any adjustments if laterality implies a normative orientation for the posterior direction
if (normativePosterior != null)
{
// check if the order of the patient vectors are flipped according to the normative vectors
// we know we need to flip if the direction vector cross products have different signs
if (imageHead != null)
FlipX = _coreFlipX = Math.Sign(imagePosterior.Cross(imageHead).Z) != Math.Sign(normativePosterior.Cross(normativeHead).Z);
else if (imageLeft != null)
FlipX = _coreFlipX = Math.Sign(imagePosterior.Cross(imageLeft).Z) != Math.Sign(normativePosterior.Cross(normativeLeft).Z);
// with flip normalized, just rotate to align the current posterior direction with the normative posterior
var currentPosterior = GetCurrentPosteriorVector(_imagePosterior, SourceWidth, AdjustedSourceHeight, 0, 1, 1, _coreFlipX, false);
var posteriorAngle = Math.Atan2(currentPosterior.Y, currentPosterior.X);
var normativeAngle = Math.Atan2(normativePosterior.Y, normativePosterior.X);
// compute required rotation, rounded to multiples of 90 degrees (PI/2 radians)
RotationXY = _coreRotation = 90*((int) Math.Round((normativeAngle - posteriorAngle)*2/Math.PI));
}
}
}