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); } }
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, "")); }
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); }
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)); } }