Esempio n. 1
0
        protected RoiGraphic CreateRoiGraphic(bool initiallySelected)
        {
            //When you create a graphic from within a tool (particularly one that needs capture, like a multi-click graphic),
            //see it through to the end of creation.  It's just cleaner, not to mention that if this tool knows how to create it,
            //it should also know how to (and be responsible for) cancelling it and/or deleting it appropriately.
            IGraphic graphic = CreateGraphic();
            IAnnotationCalloutLocationStrategy strategy = CreateCalloutLocationStrategy();

            RoiGraphic roiGraphic;

            if (strategy == null)
            {
                roiGraphic = new RoiGraphic(graphic);
            }
            else
            {
                roiGraphic = new RoiGraphic(graphic, strategy);
            }

            if (Settings.Default.AutoNameMeasurements && !string.IsNullOrEmpty(this.RoiNameFormat))
            {
                roiGraphic.Name = string.Format(this.RoiNameFormat, ++_serialNumber);
            }
            else
            {
                roiGraphic.Name = string.Empty;
            }

            roiGraphic.State = initiallySelected ? roiGraphic.CreateSelectedState() : roiGraphic.CreateInactiveState();

            return(roiGraphic);
        }
Esempio n. 2
0
 private void WatchRoiGraphic(RoiGraphic roiGraphic)
 {
     if (roiGraphic != null)
     {
         roiGraphic.RoiChanged += OnRoiChanged;
     }
 }
Esempio n. 3
0
        protected void AddRoiGraphic(IPresentationImage image, RoiGraphic roiGraphic, IOverlayGraphicsProvider provider)
        {
            _undoableCommand = new DrawableUndoableCommand(image);
            _undoableCommand.Enqueue(new AddGraphicUndoableCommand(roiGraphic, provider.OverlayGraphics));
            _undoableCommand.Name = CreationCommandName;
            _undoableCommand.Execute();

            OnRoiCreation(roiGraphic);
        }
Esempio n. 4
0
        private void OnGraphicSelectionChanged(object sender, GraphicSelectionChangedEventArgs e)
        {
            RoiGraphic deselectedGraphic = e.DeselectedGraphic as RoiGraphic;
            RoiGraphic selectedGraphic   = e.SelectedGraphic as RoiGraphic;

            UnwatchRoiGraphic(deselectedGraphic);
            WatchRoiGraphic(selectedGraphic);

            OnAllPropertiesChanged();
        }
Esempio n. 5
0
        public void TestRotationConstraints()
        {
            SynchronizationContext oldContext = SynchronizationContext.Current;

            if (oldContext == null)
            {
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            }
            try
            {
                CompositeGraphic      sceneGraph     = CreateTestSceneGraph();
                CompositeImageGraphic imageComposite = (CompositeImageGraphic)sceneGraph.Graphics[0];
                ImageGraphic          image          = (ImageGraphic)imageComposite.Graphics[0];
                CompositeGraphic      primitiveOwner = (CompositeGraphic)imageComposite.Graphics[1];
                Graphic primitive = (Graphic)primitiveOwner.Graphics[0];

                RoiGraphic roiGraphic = (RoiGraphic)imageComposite.Graphics[2];

                try
                {
                    sceneGraph.SpatialTransform.RotationXY     = 90;
                    imageComposite.SpatialTransform.RotationXY = 90;
                    primitiveOwner.SpatialTransform.RotationXY = 10;
                    primitive.SpatialTransform.RotationXY      = -20;
                }
                catch (Exception)
                {
                    Assert.Fail("These operations should not throw an exception!");
                }

                Matrix cumulativeTransform;
                try
                {
                    imageComposite.SpatialTransform.RotationXY = 30;
                    //should throw; no non-90 degree rotations allowed on an image
                    cumulativeTransform = image.SpatialTransform.CumulativeTransform;
                    Assert.Fail("expected exception not thrown!");
                }
                catch (ArgumentException)
                {
                    imageComposite.SpatialTransform.RotationXY = 90;
                }

                roiGraphic.SpatialTransform.RotationXY = 100;
                //should throw; no rotation allowed on a roi
                cumulativeTransform = roiGraphic.SpatialTransform.CumulativeTransform;
            }
            finally
            {
                if (oldContext != SynchronizationContext.Current)
                {
                    SynchronizationContext.SetSynchronizationContext(oldContext);
                }
            }
        }
Esempio n. 6
0
        private Roi GetRoi()
        {
            RoiGraphic graphic = GetSelectedRoi();

            if (graphic == null)
            {
                return(null);
            }

            return(graphic.Roi);
        }
        private IPointsGraphic GetSelectedPolyline()
        {
            RoiGraphic graphic = GetSelectedRoi();

            if (graphic == null)
            {
                return(null);
            }

            IPointsGraphic line = graphic.Subject as IPointsGraphic;

            if (line == null)
            {
                return(null);
            }

            return(line);
        }
Esempio n. 8
0
        private static CompositeGraphic CreateTestSceneGraph()
        {
            CompositeGraphic      sceneGraph     = new CompositeGraphic();
            ImageSpatialTransform imageTransform = CreateTransform();

            sceneGraph.Graphics.Add(imageTransform.OwnerGraphic);

            CompositeGraphic composite = new CompositeGraphic();
            Graphic          leaf      = new LinePrimitive();

            composite.Graphics.Add(leaf);
            ((CompositeImageGraphic)imageTransform.OwnerGraphic).Graphics.Add(composite);

            RoiGraphic roiGraphic = new RoiGraphic(new EllipsePrimitive());

            ((CompositeImageGraphic)imageTransform.OwnerGraphic).Graphics.Add(roiGraphic);

            return(sceneGraph);
        }
Esempio n. 9
0
        public override bool Start(IMouseInformation mouseInformation)
        {
            base.Start(mouseInformation);

            if (_graphicBuilder != null)
            {
                return(_graphicBuilder.Start(mouseInformation));
            }

            if (!CanStart(mouseInformation.Tile.PresentationImage))
            {
                return(false);
            }

            RoiGraphic roiGraphic = CreateRoiGraphic();

            _graphicBuilder = CreateGraphicBuilder(roiGraphic.Subject);
            _graphicBuilder.GraphicComplete  += OnGraphicBuilderComplete;
            _graphicBuilder.GraphicCancelled += OnGraphicBuilderCancelled;

            AddRoiGraphic(mouseInformation.Tile.PresentationImage,
                          roiGraphic,
                          (IOverlayGraphicsProvider)mouseInformation.Tile.PresentationImage);

            roiGraphic.Suspend();
            try
            {
                if (_graphicBuilder.Start(mouseInformation))
                {
                    return(true);
                }
            }
            finally
            {
                roiGraphic.Resume(true);
            }

            this.Cancel();
            return(false);
        }
Esempio n. 10
0
        public RoiGraphic GetSelectedRoi()
        {
            if (this.ImageViewer == null)
            {
                return(null);
            }

            if (this.ImageViewer.SelectedPresentationImage == null)
            {
                return(null);
            }

            if (this.ImageViewer.SelectedPresentationImage.SelectedGraphic == null)
            {
                return(null);
            }

            RoiGraphic graphic =
                this.ImageViewer.SelectedPresentationImage.SelectedGraphic as RoiGraphic;

            return(graphic);
        }
Esempio n. 11
0
 protected virtual void OnRoiCreation(RoiGraphic roiGraphic)
 {
 }
Esempio n. 12
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);
        }