private void InitializeTranformationMatrizes() { GeometryType = FrameGeometryType.None; if (!PixelSpacingBetweenColumns.IsNearlyZero() && !PixelSpacingBetweenRows.IsNearlyZero()) { // at least pixel spacing is present GeometryType = FrameGeometryType.Plane; if (DirectionNormal.IsZero) { ImageToPatientSpace = MatrixD.Identity(4); ImageToPatientSpace[0, 0] = PixelSpacingBetweenColumns; ImageToPatientSpace[1, 1] = PixelSpacingBetweenRows; } else { ImageToPatientSpace = MatrixD.Identity(4); ImageToPatientSpace.Column(0, DirectionRow.X * PixelSpacingBetweenColumns, DirectionRow.Y * PixelSpacingBetweenColumns, DirectionRow.Z * PixelSpacingBetweenColumns, 0); ImageToPatientSpace.Column(1, DirectionColumn.X * PixelSpacingBetweenRows, DirectionColumn.Y * PixelSpacingBetweenRows, DirectionColumn.Z * PixelSpacingBetweenRows, 0); ImageToPatientSpace.Column(2, DirectionNormal.X, DirectionNormal.Y, DirectionNormal.Z, 0); ImageToPatientSpace.Column(3, PointTopLeft.X, PointTopLeft.Y, PointTopLeft.Z, 1); } PatientToImageSpace = ImageToPatientSpace.Invert(); if (PointTopLeft != Point3D.Zero || DirectionRow != Vector3D.AxisX || DirectionColumn != Vector3D.AxisY) { GeometryType = FrameGeometryType.Volume; } } }
public FrameGeometry(string frameOfReferenceUid, double[] imagePatientPosition, double[] imagePatientOrientation, double[] pixelSpacing, int width, int height) { // copy provided values FrameOfReferenceUid = frameOfReferenceUid; PointTopLeft = new Point3D(imagePatientPosition); DirectionRow = new Vector3D(imagePatientOrientation, 0); DirectionColumn = new Vector3D(imagePatientOrientation, 3); FrameSize = new Point2(width, height); PixelSpacingX = pixelSpacing[0]; PixelSpacingY = pixelSpacing[1]; // calculate some additional values DirectionNormal = DirectionRow.CrossProduct(DirectionColumn); if (DirectionNormal.IsZero) { Orientation = FrameOrientation.None; } else { var axis = DirectionNormal.NearestAxis(); if (axis.X != 0) { Orientation = FrameOrientation.Sagittal; } else if (axis.Y != 0) { Orientation = FrameOrientation.Coronal; } else if (axis.Z != 0) { Orientation = FrameOrientation.Axial; } else { Orientation = FrameOrientation.None; } } PointTopRight = PointTopLeft + DirectionRow * PixelSpacingX * FrameSize.X; PointBottomLeft = PointTopLeft + DirectionColumn * PixelSpacingY * FrameSize.Y; PointBottomRight = PointBottomLeft + (PointTopRight - PointTopLeft); if (DirectionNormal.IsZero) { ImageToPatientSpace = MatrixD.Identity(4); ImageToPatientSpace[0, 0] = PixelSpacingX; ImageToPatientSpace[1, 1] = PixelSpacingY; } else { ImageToPatientSpace = MatrixD.Identity(4); ImageToPatientSpace.Column(0, DirectionRow.X * PixelSpacingX, DirectionRow.Y * PixelSpacingX, DirectionRow.Z * PixelSpacingX, 0); ImageToPatientSpace.Column(1, DirectionColumn.X * PixelSpacingY, DirectionColumn.Y * PixelSpacingY, DirectionColumn.Z * PixelSpacingY, 0); ImageToPatientSpace.Column(2, DirectionNormal.X, DirectionNormal.Y, DirectionNormal.Z, 0); ImageToPatientSpace.Column(3, PointTopLeft.X, PointTopLeft.Y, PointTopLeft.Z, 1); } PatientToImageSpace = ImageToPatientSpace.Invert(); }