public bool MouseDown(DicomImageViewControl sender, MouseEventArgs e) { foreach (Localize localize in Localizes) { if (localize.Contain(e.Location, sender)) { Select(localize); } } if (e.Button == MouseButtons.Left) { this.flagMove = true; if (Localizes.Count() > 0) { imageViewerManager.ReferenceLineManager.Refresh(); } } if (e.Button == MouseButtons.Right) { this.flagRotate = true; if (Localizes.Count() > 0) { imageViewerManager.ReferenceLineManager.Refresh(); } } mouseDownPoint = sender.convertToOrigin(e.Location); mouseDownPoint3D = sender.CurrentImagePlane.ConvertToPatient(sender.convertToOrigin(e.Location)); return(false); }
public void RepaintAllLocalizers(DicomImageViewControl butThis = null) { foreach (DicomImageViewControl control in this.imageViewerManager.LayoutManager.layoutControls) { if (control != butThis || butThis == null) { control.Invalidate(); } } }
public void CreateLocalize(DicomImageViewControl referenceDicomElement) { if (referenceDicomElement.CurrentDicomElement != null) { Localizes.Add(new Localize(referenceDicomElement, this.DefaultSliceNumber, this.DefaultSliceWidth, this.DefaultSliceSize, this.xFOV, this.yFOV)); if (Localizes.Count() > 0) { imageViewerManager.ReferenceLineManager.Refresh(); } this.RepaintAllLocalizers(referenceDicomElement); } }
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); }
public void RepaintLocalizers(Graphics g, DicomImageViewControl control) { if (this.Localizes.Count > 0) { if (control.CurrentDicomElement != null) { foreach (Localize localize in this.Localizes) { localize.Repaint(g, control); } } } }
public Localize(DicomImageViewControl control, int sliceNumber, float sliceWidth, float sliceSize, float xFOV, float yFOV) { this.Control = control; this.sliceNumber = sliceNumber; this.sliceWidth = (int)(sliceWidth / this.Control.CurrentDicomElement.ImageSop.Frames[1].PixelSpacing.Row); this.sliceSize = (int)(sliceSize / this.Control.CurrentDicomElement.ImageSop.Frames[1].PixelSpacing.Row); this.xFOV = (int)(xFOV / this.Control.CurrentDicomElement.ImageSop.Frames[1].PixelSpacing.Row); this.yFOV = (int)(yFOV / this.Control.CurrentDicomElement.ImageSop.Frames[1].PixelSpacing.Column); this.ImageOrientationPatientOfReferenceImage = new ImageOrientationPatient( this.Control.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.RowX, this.Control.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.RowY, this.Control.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.RowZ, this.Control.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.ColumnX, this.Control.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.ColumnY, this.Control.CurrentDicomElement.ImageSop.Frames[1].ImageOrientationPatient.ColumnZ ); CreateSplices3D(); }
private void bgrwLoadStudy_DoWork(object sender, DoWorkEventArgs e) { DirectoryInfo[] dirs = new DirectoryInfo(e.Argument.ToString()).GetDirectories(); int count = 0; foreach (DirectoryInfo di in dirs) { DicomImageViewControl control = (DicomImageViewControl)this.LayoutManager.layoutControls[count]; List <string> filePaths = new List <string>(); foreach (FileInfo file in di.GetFiles("*.dcm")) { DicomElement currentDicomElement = new DicomElement(file.FullName); control.DicomElements.Add(currentDicomElement); control.DicomElements.Sort(); control.CurrentDicomElement = ((DicomImageViewControl)control).DicomElements[0]; } control.LoadImage(); bgrwLoadStudy.ReportProgress(count); count++; } }
private LayoutControl CreateLayoutControl() { DicomImageViewControl dicomImageViewControl = new DicomImageViewControl(this); return(dicomImageViewControl); }
public bool MouseUp(DicomImageViewControl sender, Point point) { this.flagMove = false; this.flagRotate = false; return(false); }
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)); } }