Exemple #1
0
        private static IGraphic CreateInteractivePolyline(IList <PointF> vertices)
        {
            var closed = FloatComparer.AreEqual(vertices[0], vertices[vertices.Count - 1]);

            // use a standard rectangle primitive if the axes defines an axis-aligned rectangle
            if (closed && vertices.Count == 5 && IsAxisAligned(vertices[0], vertices[1]) && IsAxisAligned(vertices[1], vertices[2]) && IsAxisAligned(vertices[2], vertices[3]) && IsAxisAligned(vertices[3], vertices[4]))
            {
                var bounds    = RectangleUtilities.ConvertToPositiveRectangle(RectangleUtilities.ComputeBoundingRectangle(vertices[0], vertices[1], vertices[2], vertices[3]));
                var rectangle = new RectanglePrimitive {
                    TopLeft = bounds.Location, BottomRight = bounds.Location + bounds.Size
                };
                return(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(new MoveControlGraphic(rectangle))));
            }
            else if (!closed && vertices.Count == 3)
            {
                var protractor = new ProtractorGraphic {
                    Points = { vertices[0], vertices[1], vertices[2] }
                };
                return(new VerticesControlGraphic(new MoveControlGraphic(protractor)));
            }
            else if (!closed && vertices.Count == 2)
            {
                var line = new PolylineGraphic {
                    Points = { vertices[0], vertices[1] }
                };
                return(new VerticesControlGraphic(new MoveControlGraphic(line)));
            }

            var polyline = new PolylineGraphic(closed);

            polyline.Points.AddRange(vertices);
            return(closed ? new PolygonControlGraphic(true, new MoveControlGraphic(polyline)) : new VerticesControlGraphic(true, new MoveControlGraphic(polyline)));
        }
Exemple #2
0
        protected override Roi CreateRoiFromGraphic(IOverlayGraphicsProvider overlayGraphics, Angle shapeData)
        {
            ProtractorGraphic graphic = new ProtractorGraphic();

            overlayGraphics.OverlayGraphics.Add(graphic);
            graphic.CoordinateSystem = CoordinateSystem.Source;
            graphic.Points.Add(shapeData.Value1);
            graphic.Points.Add(shapeData.Value2);
            graphic.Points.Add(shapeData.Value3);
            graphic.ResetCoordinateSystem();
            return(graphic.GetRoi());
        }
		internal ProtractorRoiInfo(ProtractorGraphic protractor) : base(protractor.ParentPresentationImage)
		{
			_points = new List<PointF>();

			protractor.CoordinateSystem = CoordinateSystem.Source;
			try
			{
				for (int i = 0; i < protractor.Points.Count; ++i)
					_points.Add(protractor.Points[i]);
			}
			finally
			{
				protractor.ResetCoordinateSystem();
			}
		}
        public ProtractorRoi(ProtractorGraphic protractor) : base(protractor.ParentPresentationImage)
        {
            _points = new List <PointF>();

            protractor.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                for (int i = 0; i < protractor.Points.Count; ++i)
                {
                    _points.Add(protractor.Points[i]);
                }
            }
            finally
            {
                protractor.ResetCoordinateSystem();
            }
        }
Exemple #5
0
		protected ProtractorGraphic (ProtractorGraphic source, ICloningContext context)
			: base(source, context)
		{
			context.CloneFields(source, this);
		}
Exemple #6
0
        internal static List <IGraphic> PopulateImageViewerWithSavedMarkup(List <IMarkup> markupList, IImageViewer imageViewer)
        {
            var graphics = new List <IGraphic>();

            foreach (var markup in markupList)
            {
                foreach (var box in imageViewer.PhysicalWorkspace.ImageBoxes)
                {
                    if (box.DisplaySet == null)
                    {
                        continue;
                    }

                    var imageSop =
                        box.DisplaySet.PresentationImages.Cast <IImageSopProvider>().FirstOrDefault(
                            pi => pi.ImageSop.SopInstanceUid == markup.PresentationImageUid && pi.Frame.FrameNumber == markup.FrameNumber);

                    var selectedPresentationImage = imageSop as IPresentationImage;
                    if (selectedPresentationImage == null)
                    {
                        continue;
                    }

                    var graphicsProvider = selectedPresentationImage as IOverlayGraphicsProvider;
                    if (graphicsProvider != null)
                    {
                        if (markup is MarkupEllipse)
                        {
                            var markupEllipse    = (MarkupEllipse)markup;
                            var ellipsePrimitive = new EllipsePrimitive();
                            var roiGraphic       = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(
                                                                                                        new MoveControlGraphic(ellipsePrimitive))));
                            var boundableGraphic = roiGraphic.Subject as BoundableGraphic;

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            if (boundableGraphic != null)
                            {
                                roiGraphic.Suspend();                                 // prevent callout location calculation until all points are set
                                roiGraphic.Name = markup.Name;
                                ellipsePrimitive.BottomRight = markupEllipse.BottomRight;
                                ellipsePrimitive.TopLeft     = markupEllipse.TopLeft;
                                roiGraphic.State             = roiGraphic.CreateInactiveState();
                                roiGraphic.Resume(true);                                 // Force callout location calculation
                                roiGraphic.Callout.TextLocation = markupEllipse.CalloutLocation;
                            }
                        }
                        else if (markup is MarkupPolygonal)
                        {
                            var markupPolygon = (MarkupPolygonal)markup;

                            var polyline = new PolylineGraphic(true);
                            foreach (var point in markupPolygon.Vertices)
                            {
                                polyline.Points.Add(point);
                            }
                            var roiGraphic = new RoiGraphic(new PolygonControlGraphic(true, new MoveControlGraphic(polyline)));

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            //if (boundableGraphic != null)
                            {
                                roiGraphic.Suspend();                                 // prevent callout location calculation until all points are set
                                roiGraphic.Name  = markup.Name;
                                roiGraphic.State = roiGraphic.CreateInactiveState();
                                roiGraphic.Resume(true);                                 // Force callout location calculation
                                roiGraphic.Callout.TextLocation = markupPolygon.CalloutLocation;
                            }
                        }
                        else if (markup is MarkupRectangle)
                        {
                            var markupRectangle    = (MarkupRectangle)markup;
                            var rectanglePrimitive = new RectanglePrimitive();
                            var roiGraphic         = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(
                                                                                                          new MoveControlGraphic(rectanglePrimitive))));
                            var boundableGraphic = roiGraphic.Subject as BoundableGraphic;

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            if (boundableGraphic != null)
                            {
                                roiGraphic.Suspend();                                 // prevent callout location calculation until all points are set
                                roiGraphic.Name = markup.Name;
                                rectanglePrimitive.BottomRight = markupRectangle.BottomRight;
                                rectanglePrimitive.TopLeft     = markupRectangle.TopLeft;
                                roiGraphic.State = roiGraphic.CreateInactiveState();
                                roiGraphic.Resume(true);                                 // Force callout location calculation
                                roiGraphic.Callout.TextLocation = markupRectangle.CalloutLocation;
                            }
                        }
                        else if (markup is MarkupProtractor)
                        {
                            var markupProtractor = (MarkupProtractor)markup;

                            var protractorGraphic = new ProtractorGraphic();
                            foreach (var point in markupProtractor.Points)
                            {
                                protractorGraphic.Points.Add(point);
                            }
                            var roiGraphic = new RoiGraphic(new VerticesControlGraphic(new MoveControlGraphic(protractorGraphic)));

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            roiGraphic.Suspend();                             // prevent callout location calculation until all points are set
                            roiGraphic.Name  = markup.Name;
                            roiGraphic.State = roiGraphic.CreateInactiveState();
                            roiGraphic.Resume(true);                             // Force callout location calculation
                            roiGraphic.Callout.TextLocation = markupProtractor.CalloutLocation;
                        }
                        else if (markup is MarkupLinear)
                        {
                            var markupLinear = (MarkupLinear)markup;

                            var polylineGraphic = new PolylineGraphic();
                            foreach (var point in markupLinear.Vertices)
                            {
                                polylineGraphic.Points.Add(point);
                            }
                            var roiGraphic = new RoiGraphic(new VerticesControlGraphic(new MoveControlGraphic(polylineGraphic)));

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            roiGraphic.Suspend();                             // prevent callout location calculation until all points are set
                            roiGraphic.Name  = markup.Name;
                            roiGraphic.State = roiGraphic.CreateInactiveState();
                            roiGraphic.Resume(true);                             // Force callout location calculation
                            roiGraphic.Callout.TextLocation = markupLinear.CalloutLocation;
                        }
                        else if (markup is MarkupPoint)
                        {
                            var markupPoint = (MarkupPoint)markup;

                            IGraphic calloutGraphic;
                            if (markupPoint.UseCrosshair)
                            {
                                calloutGraphic = new UserCrosshairCalloutGraphic
                                {
                                    AnchorPoint  = markupPoint.Point,
                                    TextLocation = markupPoint.CalloutLocation,
                                    Text         = markupPoint.CalloutText,
                                    ShowShaft    = !String.IsNullOrEmpty(markupPoint.CalloutText),
                                    LineStyle    = LineStyle.Dot
                                };
                            }
                            else
                            {
                                calloutGraphic = new UserCalloutGraphic
                                {
                                    AnchorPoint   = markupPoint.Point,
                                    TextLocation  = markupPoint.CalloutLocation,
                                    Text          = markupPoint.CalloutText,
                                    ShowArrowhead = true,
                                    LineStyle     = LineStyle.Solid
                                };
                            }

                            var statefulGraphic = new StandardStatefulGraphic(calloutGraphic);
                            statefulGraphic.State = statefulGraphic.CreateInactiveState();

                            var contextGraphic = new ContextMenuControlGraphic(typeof(ClearCanvas.ImageViewer.Tools.Standard.TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic);
                            contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions;

                            //if (markupPoint.Name != "RemoveForCalloutPlacement")
                            {
                                markup.GraphicHashcode = contextGraphic.GetHashCode();
                                graphics.Add(contextGraphic);
                                graphicsProvider.OverlayGraphics.Add(contextGraphic);
                                //selectedPresentationImage.Draw();
                            }
                        }
                    }

                    box.TopLeftPresentationImage = selectedPresentationImage;
                    box.Tiles[0].Select();
                    box.Draw();

                    break;
                }
            }
            return(graphics);
        }