コード例 #1
0
        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();
        }
コード例 #2
0
ファイル: FrameGeometry.cs プロジェクト: fo-dicom/fo-dicom
        private void InitializeCalcualtedVolumeData(double[] imagePatientPosition, double[] imagePatientOrientation)
        {
            if (imagePatientPosition.Length == 0 && imagePatientOrientation.Length == 0)
            {
                Orientation     = FrameOrientation.None;
                PointTopLeft    = new Point3D(0, 0, 0);
                DirectionRow    = new Vector3D(1, 0, 0);
                DirectionColumn = new Vector3D(0, 1, 0);
            }
            else
            {
                PointTopLeft    = new Point3D(imagePatientPosition);
                DirectionRow    = new Vector3D(imagePatientOrientation, 0);
                DirectionColumn = new Vector3D(imagePatientOrientation, 3);
            }
            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 * PixelSpacingBetweenColumns * FrameSize.X;
            PointBottomLeft  = PointTopLeft + DirectionColumn * PixelSpacingBetweenRows * FrameSize.Y;
            PointBottomRight = PointBottomLeft + (PointTopRight - PointTopLeft);
        }