コード例 #1
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);
        }
コード例 #2
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));
            }
        }