public static void Translate(this Matrix m, float x, float y, float z) { var t = new Matrix(new[,] { {1, 0, 0, x}, {0, 1, 0, y}, {0, 0, 1, z}, {0, 0, 0, 1} }); m.Set(t*m); }
public static void Scale(this Matrix m, float x, float y, float z) { var s = new Matrix(new[,] { {x, 0, 0, 0}, {0, y, 0, 0}, {0, 0, z, 0}, {0, 0, 0, 1} }); m.Set(s*m); }
private static void Set(this Matrix m, Matrix value) { m.SetRow(0, value[0, 0], value[0, 1], value[0, 2], value[0, 3]); m.SetRow(1, value[1, 0], value[1, 1], value[1, 2], value[1, 3]); m.SetRow(2, value[2, 0], value[2, 1], value[2, 2], value[2, 3]); m.SetRow(3, value[3, 0], value[3, 1], value[3, 2], value[3, 3]); }
public static void Multiply(this Matrix m, Matrix r) { m.Set(r*m); }
public Matrix RotateToVolumeOrientation(Matrix patientOrientation) { Platform.CheckForNullReference(patientOrientation, "patientOrientation"); var size = patientOrientation.Rows; Platform.CheckTrue(patientOrientation.IsSquare && (size == 3 || size == 4), "patientOrientation must be a 3x3 orientation matrix or a 4x4 affine transmation matrix"); var orientationVolume = size == 3 ? patientOrientation*_volumeOrientationPatient.Transpose() : patientOrientation*_volumeOrientationPatient.Augment(true); return orientationVolume; }
public Matrix RotateToPatientOrientation(Matrix volumeOrientation) { Platform.CheckForNullReference(volumeOrientation, "volumeOrientation"); var size = volumeOrientation.Rows; Platform.CheckTrue(volumeOrientation.IsSquare && (size == 3 || size == 4), "volumeOrientation must be a 3x3 orientation matrix or a 4x4 affine transmation matrix"); var orientationPatient = size == 3 ? volumeOrientation*_volumeOrientationPatient : volumeOrientation*_volumeOrientationPatient.Augment(); return orientationPatient; }
public Vector3D ConvertToVolume(Vector3D patientPosition) { Platform.CheckForNullReference(patientPosition, "patientPosition"); // Set orientation transform var patientVolumeTransform = _volumeOrientationPatient.Augment(true); // Set origin translation var rotatedOrigin = RotateToVolumeOrientation(VolumePositionPatient); patientVolumeTransform.SetRow(3, -rotatedOrigin.X, -rotatedOrigin.Y, -rotatedOrigin.Z, 1); // Transform patient position to volume position var patientPositionMatrix = new Matrix(1, 4); patientPositionMatrix.SetRow(0, patientPosition.X, patientPosition.Y, patientPosition.Z, 1F); var imagePositionMatrix = patientPositionMatrix*patientVolumeTransform; var imagePosition = new Vector3D(imagePositionMatrix[0, 0], imagePositionMatrix[0, 1], imagePositionMatrix[0, 2]); return imagePosition; }
public Vector3D ConvertToPatient(Vector3D volumePosition) { Platform.CheckForNullReference(volumePosition, "volumePosition"); // Set orientation transform var volumePatientTransform = _volumeOrientationPatient.Augment(); // Set origin translation volumePatientTransform.SetRow(3, VolumePositionPatient.X, VolumePositionPatient.Y, VolumePositionPatient.Z, 1); // Transform volume position to patient position var imagePositionMatrix = new Matrix(1, 4); imagePositionMatrix.SetRow(0, volumePosition.X, volumePosition.Y, volumePosition.Z, 1F); var patientPositionMatrix = imagePositionMatrix*volumePatientTransform; var patientPosition = new Vector3D(patientPositionMatrix[0, 0], patientPositionMatrix[0, 1], patientPositionMatrix[0, 2]); return patientPosition; }