public void TestFromRows() { var v1 = new Vector3D(1, 2, 3); var v2 = new Vector3D(4, 5, 6); var v3 = new Vector3D(7, 8, 9); var m = Matrix3D.FromRows(v1, v2, v3); Assert.IsTrue(Matrix3D.AreEqual(m, new Matrix3D(new float[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }))); }
private void SetPatientOrientation(Vector3D rowDirectionPatient, Vector3D columnDirectionPatient) { if (!CanRotate()) { return; } if (rowDirectionPatient == null || columnDirectionPatient == null || !rowDirectionPatient.IsOrthogonalTo(columnDirectionPatient, (float)(5 / 180d * Math.PI))) { return; } var patientPresentation = SelectedPresentationImage as IPatientPresentationProvider; if (patientPresentation == null || !patientPresentation.PatientPresentation.IsValid) { return; } // Note the inverted column orientation vectors in both matrices - this is due to implicit Y axis inversion in the 3D transform columnDirectionPatient = -columnDirectionPatient; var currentRowOrientation = patientPresentation.PatientPresentation.OrientationX; var currentColumnOrientation = -patientPresentation.PatientPresentation.OrientationY; var currentOrientation = Matrix3D.FromRows(currentRowOrientation.Normalize(), currentColumnOrientation.Normalize(), currentRowOrientation.Cross(currentColumnOrientation).Normalize()); var requestedOrientation = Matrix3D.FromRows(rowDirectionPatient.Normalize(), columnDirectionPatient.Normalize(), rowDirectionPatient.Cross(columnDirectionPatient).Normalize()); var transform = _operation.GetOriginator(SelectedPresentationImage); // (because we're dealing with rotation matrices (i.e. orthogonal!), the Inverse is just Transpose) var rotation = requestedOrientation * currentOrientation.Transpose(); transform.Rotation = rotation * transform.Rotation; // this rotation is cumulative upon current rotation, since IPatientPresentationProvider is based on *current* view SelectedPresentationImage.Draw(); }