예제 #1
0
        public bool IsInSameFrameOfReference(DicomImagePlane other)
        {
            Frame otherFrame = other._sourceFrame;

            if (_sourceFrame.ParentImageSop.StudyInstanceUID != otherFrame.ParentImageSop.StudyInstanceUID)
            {
                return(false);
            }

            return(this._sourceFrame.FrameOfReferenceUid == otherFrame.FrameOfReferenceUid);
        }
예제 #2
0
        public bool MouseMove(DicomImageViewControl sender, MouseEventArgs e)
        {
            if (this.flagMove == true)
            {
                Vector3D mouseMovePoint3D = sender.CurrentImagePlane.ConvertToPatient(sender.convertToOrigin(e.Location));
                if (Localizes.Count > 0)
                {
                    IPresentationImage targetImage      = sender.CurrentDicomElement.PresentationImage;
                    DicomImagePlane    targetImagePlane = DicomImagePlane.FromImage(targetImage);

                    foreach (Localize localize in Localizes)
                    {
                        if (localize.Selected)
                        {
                            localize.Move(sender.CurrentDicomElement, mouseMovePoint3D - mouseDownPoint3D);
                        }
                    }
                    RepaintAllLocalizers(sender);
                }

                mouseDownPoint3D = mouseMovePoint3D;
            }

            if (this.flagRotate == true)
            {
                Point    mouseMovePoint   = sender.convertToOrigin(e.Location);
                Vector3D mouseMovePoint3D = sender.CurrentImagePlane.ConvertToPatient(sender.convertToOrigin(e.Location));

                if (Localizes.Count > 0)
                {
                    IPresentationImage targetImage      = sender.CurrentDicomElement.PresentationImage;
                    DicomImagePlane    targetImagePlane = DicomImagePlane.FromImage(targetImage);

                    Directions row = sender.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.GetPrimaryRowDirection(false);
                    Directions col = sender.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.GetPrimaryColumnDirection(false);

                    foreach (Localize localize in Localizes)
                    {
                        if (localize.Selected)
                        {
                            localize.Rotate(mouseMovePoint.X - mouseDownPoint.X, row, col);
                        }
                    }
                    RepaintAllLocalizers();
                }

                mouseDownPoint   = mouseMovePoint;
                mouseDownPoint3D = mouseMovePoint3D;
            }

            return(false);
        }
        private IEnumerable <DicomImagePlane> GetPlanesParallelToReferencePlane()
        {
            DicomImagePlane currentReferenceImagePlane = DicomImagePlane.FromImage(this.imageViewerManager.CurrentDicomImageViewControl.CurrentDicomElement.PresentationImage);

            foreach (DicomElement dicomElement in this.imageViewerManager.CurrentDicomImageViewControl.DicomElements)
            {
                DicomImagePlane plane = DicomImagePlane.FromImage(dicomElement.PresentationImage);
                if (plane != null)
                {
                    if (currentReferenceImagePlane.IsInSameFrameOfReference(plane) &&
                        currentReferenceImagePlane.IsParallelTo(plane, _oneDegreeInRadians))
                    {
                        yield return(plane);
                    }
                }
            }
        }
예제 #4
0
        public float GetAngleBetween(DicomImagePlane other)
        {
            Vector3D normal1 = this.Normal.Normalize();
            Vector3D normal2 = other.Normal.Normalize();

            float dot = normal1.Dot(normal2);

            if (dot < -1F)
            {
                dot = -1F;
            }
            if (dot > 1F)
            {
                dot = 1F;
            }

            return(Math.Abs((float)Math.Acos(dot)));
        }
예제 #5
0
        public bool IsParallelTo(DicomImagePlane other, float angleTolerance)
        {
            angleTolerance = Math.Abs(angleTolerance);
            float upper = angleTolerance;
            float lower = -angleTolerance;

            float angle = GetAngleBetween(other);

            bool parallel = FloatComparer.IsGreaterThan(angle, lower) && FloatComparer.IsLessThan(angle, upper);

            if (!parallel)
            {
                upper    = (float)Math.PI + angleTolerance;
                lower    = (float)Math.PI - angleTolerance;
                parallel = FloatComparer.IsGreaterThan(angle, lower) && FloatComparer.IsLessThan(angle, upper);
            }

            return(parallel);
        }
 public void Refresh()
 {
     foreach (DicomImageViewControl control in this.imageViewerManager.LayoutManager.layoutControls)
     {
         control.ReferenceLines.Clear();
         if (control.CurrentDicomElement != null)
         {
             IPresentationImage targetImage = control.CurrentDicomElement.PresentationImage;
             if (targetImage != this.imageViewerManager.CurrentDicomImageViewControl.CurrentDicomElement.PresentationImage)
             {
                 DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(targetImage);
                 if (targetImagePlane != null)
                 {
                     control.ReferenceLines = GetAllReferenceLines(targetImagePlane).ToList();
                 }
             }
         }
         control.Invalidate();
     }
 }
예제 #7
0
        public bool GetIntersectionPoints(DicomImagePlane other, out Vector3D intersectionPointPatient1, out Vector3D intersectionPointPatient2)
        {
            intersectionPointPatient1 = intersectionPointPatient2 = null;

            Vector3D[,] lineSegmentsImagePlaneBounds = new Vector3D[, ]
            {
                { PositionPatientTopLeft, PositionPatientTopRight },
                { PositionPatientTopLeft, PositionPatientBottomLeft },
                { PositionPatientBottomRight, PositionPatientTopRight },
                { PositionPatientBottomRight, PositionPatientBottomLeft }
            };

            List <Vector3D> planeIntersectionPoints = new List <Vector3D>();

            for (int i = 0; i < 4; ++i)
            {
                Vector3D intersectionPoint = Vector3D.GetLinePlaneIntersection(other.Normal, other.PositionPatientCenterOfImage,
                                                                               lineSegmentsImagePlaneBounds[i, 0],
                                                                               lineSegmentsImagePlaneBounds[i, 1], true);
                if (intersectionPoint != null)
                {
                    planeIntersectionPoints.Add(intersectionPoint);
                }
            }

            if (planeIntersectionPoints.Count < 2)
            {
                return(false);
            }

            intersectionPointPatient1 = planeIntersectionPoints[0];
            intersectionPointPatient2 = CollectionUtils.SelectFirst(planeIntersectionPoints,
                                                                    delegate(Vector3D point)
            {
                return(!planeIntersectionPoints[0].Equals(point));
            });

            return(intersectionPointPatient1 != null && intersectionPointPatient2 != null);
        }
        private static ReferenceLine GetReferenceLine(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
        {
            const float parallelTolerance = (float)(Math.PI / 18);

            if (referenceImagePlane.IsParallelTo(targetImagePlane, parallelTolerance))
            {
                return(null);
            }

            Vector3D intersectionPatient1, intersectionPatient2;

            if (!referenceImagePlane.GetIntersectionPoints(targetImagePlane, out intersectionPatient1, out intersectionPatient2))
            {
                return(null);
            }

            Vector3D intersectionImagePlane1 = targetImagePlane.ConvertToImagePlane(intersectionPatient1);
            Vector3D intersectionImagePlane2 = targetImagePlane.ConvertToImagePlane(intersectionPatient2);

            PointF intersectionImage1 = targetImagePlane.ConvertToImage(new PointF(intersectionImagePlane1.X, intersectionImagePlane1.Y));
            PointF intersectionImage2 = targetImagePlane.ConvertToImage(new PointF(intersectionImagePlane2.X, intersectionImagePlane2.Y));

            return(new ReferenceLine(intersectionImage1, intersectionImage2, ""));
        }
        private IEnumerable <ReferenceLine> GetAllReferenceLines(DicomImagePlane targetImagePlane)
        {
            ReferenceLine firstReferenceLine = null;
            ReferenceLine lastReferenceLine  = null;

            GetFirstAndLastReferenceLines(targetImagePlane, out firstReferenceLine, out lastReferenceLine);

            if (firstReferenceLine != null)
            {
                yield return(firstReferenceLine);
            }

            if (lastReferenceLine != null)
            {
                yield return(lastReferenceLine);
            }

            ReferenceLine currentReferenceLine = GetReferenceLine(_currentReferenceImagePlane, targetImagePlane);

            if (currentReferenceLine != null)
            {
                yield return(currentReferenceLine);
            }
        }
예제 #10
0
        private static DicomImagePlane CreateFromFrame(Frame frame)
        {
            int height = frame.Rows - 1;
            int width  = frame.Columns - 1;

            DicomImagePlane plane = new DicomImagePlane();

            plane.PositionPatientTopLeft       = frame.ImagePlaneHelper.ConvertToPatient(new PointF(0, 0));
            plane.PositionPatientTopRight      = frame.ImagePlaneHelper.ConvertToPatient(new PointF(width, 0));
            plane.PositionPatientBottomLeft    = frame.ImagePlaneHelper.ConvertToPatient(new PointF(0, height));
            plane.PositionPatientBottomRight   = frame.ImagePlaneHelper.ConvertToPatient(new PointF(width, height));
            plane.PositionPatientCenterOfImage = frame.ImagePlaneHelper.ConvertToPatient(new PointF(width / 2F, height / 2F));

            plane.Normal = frame.ImagePlaneHelper.GetNormalVector();

            if (plane.Normal == null || plane.PositionPatientCenterOfImage == null)
            {
                return(null);
            }

            plane.PositionImagePlaneTopLeft = frame.ImagePlaneHelper.ConvertToImagePlane(plane.PositionPatientTopLeft, Vector3D.Null);

            return(plane);
        }
예제 #11
0
        public bool Contain(Point point, DicomImageViewControl control)
        {
            if (control.CurrentDicomElement != null)
            {
                IPresentationImage targetImage = control.CurrentDicomElement.PresentationImage;

                DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(targetImage);

                List <Slice2D> Slices2D = new List <Slice2D>();

                foreach (var slice3D in this.Slices3D)
                {
                    List <Vector3D> planeIntersectionPoints = new List <Vector3D>();
                    Vector3D        intersectionPoint       = null;

                    // Ищем пересечения
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p0, slice3D.p1, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p1, slice3D.p2, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p2, slice3D.p3, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p3, slice3D.p0, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }

                    if (planeIntersectionPoints.Count < 2)
                    {
                        continue;
                    }

                    Vector3D pTargetImagePlane0 = targetImagePlane.ConvertToImagePlane(planeIntersectionPoints[0]);
                    Vector3D pTargetImagePlane1 = targetImagePlane.ConvertToImagePlane(planeIntersectionPoints[1]);

                    PointF pImage0 = targetImagePlane.ConvertToImage(new PointF(pTargetImagePlane0.X, pTargetImagePlane0.Y));
                    PointF pImage1 = targetImagePlane.ConvertToImage(new PointF(pTargetImagePlane1.X, pTargetImagePlane1.Y));

                    Slice2D slice2D = new Slice2D();

                    slice2D.p0 = new Point((int)pImage0.X, (int)pImage0.Y);
                    slice2D.p1 = new Point((int)pImage1.X, (int)pImage1.Y);

                    Slices2D.Add(slice2D);
                }

                GraphicsPath path = new GraphicsPath();

                if (Slices2D.Count > 1)
                {
                    Point p0 = control.convertToDestination(Slices2D[0].p0);
                    Point p1 = control.convertToDestination(Slices2D[0].p1);

                    Point p2 = control.convertToDestination(Slices2D[Slices2D.Count - 1].p1);
                    Point p3 = control.convertToDestination(Slices2D[Slices2D.Count - 1].p0);

                    path.StartFigure();
                    path.AddLine(p0, p1);
                    path.AddLine(p1, p2);
                    path.AddLine(p2, p3);
                    path.AddLine(p3, p0);
                    path.CloseFigure();

                    if (path.IsVisible(point.X, point.Y))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #12
0
        public void Repaint(Graphics g, DicomImageViewControl control)
        {
            if (control.CurrentDicomElement != null)
            {
                IPresentationImage targetImage = control.CurrentDicomElement.PresentationImage;

                DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(targetImage);

                List <Slice2D> Slices2D = new List <Slice2D>();

                foreach (var slice3D in this.Slices3D)
                {
                    List <Vector3D> planeIntersectionPoints = new List <Vector3D>();
                    Vector3D        intersectionPoint       = null;

                    // Ищем пересечения
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p0, slice3D.p1, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p1, slice3D.p2, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p2, slice3D.p3, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }
                    intersectionPoint = Vector3D.GetLinePlaneIntersection(targetImagePlane.Normal, targetImagePlane.PositionPatientCenterOfImage, slice3D.p3, slice3D.p0, true);
                    if (intersectionPoint != null)
                    {
                        planeIntersectionPoints.Add(intersectionPoint);
                    }

                    if (planeIntersectionPoints.Count < 2)
                    {
                        continue;
                    }


                    Vector3D pTargetImagePlane0 = targetImagePlane.ConvertToImagePlane(planeIntersectionPoints[0]);
                    Vector3D pTargetImagePlane1 = targetImagePlane.ConvertToImagePlane(planeIntersectionPoints[1]);

                    PointF pImage0 = targetImagePlane.ConvertToImage(new PointF(pTargetImagePlane0.X, pTargetImagePlane0.Y));
                    PointF pImage1 = targetImagePlane.ConvertToImage(new PointF(pTargetImagePlane1.X, pTargetImagePlane1.Y));

                    Slice2D slice2D = new Slice2D();

                    slice2D.p0     = new Point((int)pImage0.X, (int)pImage0.Y);
                    slice2D.p1     = new Point((int)pImage1.X, (int)pImage1.Y);
                    slice2D.Number = slice3D.Number;

                    Slices2D.Add(slice2D);
                }


                Pen pRed    = new Pen(new SolidBrush(Color.FromArgb(255, Color.Red)), 1);
                Pen pYellow = new Pen(new SolidBrush(Color.FromArgb(255, Color.Yellow)), 1);
                Pen pBlue   = new Pen(new SolidBrush(Color.FromArgb(255, Color.Blue)), 1);


                foreach (var slice in Slices2D)
                {
                    Point p0 = control.convertToDestination(slice.p0);
                    Point p1 = control.convertToDestination(slice.p1);

                    if (slice.Number == 1)
                    {
                        g.DrawLine(pRed, p0, p1);
                        g.DrawString("1", new Font("Tahoma", 7), Brushes.Red, new Point(p0.X - 10, p0.Y - 6));
                    }
                    else
                    {
                        if (selected)
                        {
                            g.DrawLine(pYellow, p0, p1);
                            g.DrawString(slice.Number.ToString(), new Font("Tahoma", 7), Brushes.Yellow, new Point(p0.X - 10, p0.Y - 6));
                        }
                        else
                        {
                            g.DrawLine(pBlue, p0, p1);
                            g.DrawString(slice.Number.ToString(), new Font("Tahoma", 7), Brushes.Blue, new Point(p0.X - 10, p0.Y - 6));
                        }
                    }
                }


                //Отрисовка центра 3D координат
                Vector3D _p       = targetImagePlane.ConvertToImagePlane(new Vector3D(0, 0, 0));
                PointF   _image_p = targetImagePlane.ConvertToImage(new PointF(_p.X, _p.Y));
                Point    __p      = new Point((int)_image_p.X, (int)_image_p.Y);
                Point    ___p     = control.convertToDestination(__p);

                g.DrawLine(pYellow, new Point(___p.X - 5, ___p.Y), new Point(___p.X + 5, ___p.Y));
                g.DrawLine(pYellow, new Point(___p.X, ___p.Y - 5), new Point(___p.X, ___p.Y + 5));
            }
        }