예제 #1
0
        public void CreateSplices3D()
        {
            Slices3D.Clear();

            DicomImagePlane referenceImagePlane = DicomImagePlane.FromImage(this.Control.CurrentDicomElement.PresentationImage);
            //Поиск центра 3D координат на 2D
            Vector3D _p       = referenceImagePlane.ConvertToImagePlane(new Vector3D(0, 0, 0));
            PointF   _image_p = referenceImagePlane.ConvertToImage(new PointF(_p.X, _p.Y));
            Point    __p      = new Point((int)_image_p.X, (int)_image_p.Y);



            this.p0 = referenceImagePlane.ConvertToPatient(__p);

            for (int i = 0; i < sliceNumber; i++)
            {
                Point p1 = new Point(__p.X - xFOV / 2, __p.Y - (int)(i * (sliceWidth + sliceSize)));
                Point p2 = new Point(__p.X - xFOV / 2, __p.Y - (int)(i * (sliceWidth + sliceSize)));
                Point p3 = new Point(__p.X + xFOV / 2, __p.Y - (int)(i * (sliceWidth + sliceSize)));
                Point p4 = new Point(__p.X + xFOV / 2, __p.Y - (int)(i * (sliceWidth + sliceSize)));

                Slice3D slice3D = new Slice3D();
                slice3D.p0     = referenceImagePlane.ConvertToPatient(p1, -yFOV / 2);
                slice3D.p1     = referenceImagePlane.ConvertToPatient(p2, yFOV / 2);
                slice3D.p2     = referenceImagePlane.ConvertToPatient(p3, yFOV / 2);
                slice3D.p3     = referenceImagePlane.ConvertToPatient(p4, -yFOV / 2);
                slice3D.Number = i + 1;

                Slices3D.Add(slice3D);
            }
        }
예제 #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);
                    }
                }
            }
        }
 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();
     }
 }
예제 #5
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);
        }
예제 #6
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));
            }
        }