public ResliceToolGraphic(ResliceTool owner) { LineGraphic lineGraphic = new LineGraphic(); MprMoveControlGraphic moveControlGraphic = new MprMoveControlGraphic(lineGraphic); moveControlGraphic.UndoableOperationStart += OnControlGraphicUndoableOperationStart; moveControlGraphic.UndoableOperationStop += OnControlGraphicUndoableOperationStop; moveControlGraphic.UndoableOperationCancel += OnControlGraphicUndoableOperationCancel; MprLineStretchControlGraphic lineControlGraphic = new MprLineStretchControlGraphic(moveControlGraphic); lineControlGraphic.UndoableOperationStart += OnControlGraphicUndoableOperationStart; lineControlGraphic.UndoableOperationStop += OnControlGraphicUndoableOperationStop; lineControlGraphic.UndoableOperationCancel += OnControlGraphicUndoableOperationCancel; SliceControlGraphic sliceControlGraphic = new SliceControlGraphic(lineControlGraphic, this); StandardStatefulGraphic statefulGraphic = new StandardStatefulGraphic(sliceControlGraphic); statefulGraphic.State = statefulGraphic.CreateInactiveState(); base.Graphics.Add(statefulGraphic); _stateControlGraphic = statefulGraphic; _sliceControlGraphic = sliceControlGraphic; _lineGraphic = lineGraphic; _owner = owner; }
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; }
private static IControlGraphic CreateTextAreaGraphic() { InvariantTextPrimitive textArea = new InvariantTextPrimitive(); TextEditControlGraphic controlGraphic = new TextEditControlGraphic(new MoveControlGraphic(textArea)); controlGraphic.DeleteOnEmpty = true; StandardStatefulGraphic statefulGraphic = new StandardStatefulGraphic(controlGraphic); statefulGraphic.State = statefulGraphic.CreateInactiveState(); ContextMenuControlGraphic contextGraphic = new ContextMenuControlGraphic(typeof (TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic); contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions; return contextGraphic; }
private static IControlGraphic CreateTextCalloutGraphic() { UserCalloutGraphic callout = new UserCalloutGraphic(); callout.LineStyle = LineStyle.Solid; callout.ShowArrowhead = true; StandardStatefulGraphic statefulGraphic = new StandardStatefulGraphic(callout); statefulGraphic.State = statefulGraphic.CreateInactiveState(); /// TODO (CR Oct 2011): This is the wrong order - the "selected" graphic (stateful) gets /// deleted by the "delete graphics" tool, and then the top-level context menu /// graphic gets left dangling. ContextMenuControlGraphic contextGraphic = new ContextMenuControlGraphic(typeof (TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic); contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions; return contextGraphic; }
private static IGraphic TextAnnotationToGraphic(aim_dotnet.TextAnnotation textAnnotation, string shapeLabel) { Platform.CheckForNullReference(textAnnotation.ConnectorPoints, "ConnectorPoints"); Platform.CheckForNullReference(textAnnotation.ConnectorPoints.SpatialCoordinateCollection, "SpatialCoordinateCollection"); Platform.CheckArgumentRange(textAnnotation.ConnectorPoints.SpatialCoordinateCollection.Count, 1, 2, "SpatialCoordinateCollection"); if (textAnnotation.ConnectorPoints == null || textAnnotation.ConnectorPoints.SpatialCoordinateCollection == null) return null; var graphicText = shapeLabel.Trim(); graphicText = string.IsNullOrEmpty(graphicText) ? textAnnotation.Text.Trim() : string.Format("{0}:\r\n{1}", graphicText, textAnnotation.Text.Trim()); switch (textAnnotation.ConnectorPoints.SpatialCoordinateCollection.Count) { case 1: { var textPrimitive = new InvariantTextPrimitive(graphicText); textPrimitive.Location = AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); var statefulGraphic = new StandardStatefulGraphic(textPrimitive); statefulGraphic.State = statefulGraphic.CreateInactiveState(); return statefulGraphic; } break; case 2: { var callout = new CalloutGraphic(graphicText); callout.LineStyle = LineStyle.Solid; callout.ShowArrowhead = true; callout.AnchorPoint = AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); callout.TextLocation = AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[1]); var statefulGraphic = new StandardStatefulGraphic(callout); statefulGraphic.State = statefulGraphic.CreateInactiveState(); return statefulGraphic; } break; default: break; } return null; }
private static IGraphic GeoShapeToGraphic(aim_dotnet.IGeometricShape geoShape, string shapeLabel) { if (geoShape.SpatialCoordinateCollection == null || geoShape.SpatialCoordinateCollection.Count == 0) return null; IGraphic graphic = null; if (geoShape is aim_dotnet.Circle) { // Ellipse var shapeCircle = geoShape as aim_dotnet.Circle; var centerPt = AsPointF(shapeCircle.Center); var radiusPt = AsPointF(shapeCircle.RadiusPoint); var radiusLength = Vector.Distance(centerPt, radiusPt); RoiGraphic roiGraphic = AimRoiGraphic.CreateEllipse(); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; if (boundableGraphic != null) { roiGraphic.Suspend(); roiGraphic.Name = shapeLabel; boundableGraphic.TopLeft = new PointF((float) (centerPt.X - radiusLength), (float) (centerPt.Y - radiusLength)); boundableGraphic.BottomRight = new PointF((float) (centerPt.X + radiusLength), (float) (centerPt.Y + radiusLength)); roiGraphic.Resume(true); } graphic = roiGraphic; } else if (geoShape is aim_dotnet.Ellipse) { // Ellipse var shapeEllipse = geoShape as aim_dotnet.Ellipse; var firstMajorAxisPt = AsPointF(shapeEllipse.EllipseCollection[0]); var secondMajorAxisPt = AsPointF(shapeEllipse.EllipseCollection[1]); var firstMinorAxisPt = AsPointF(shapeEllipse.EllipseCollection[2]); var secondMinorAxisPt = AsPointF(shapeEllipse.EllipseCollection[3]); RoiGraphic roiGraphic = AimRoiGraphic.CreateEllipse(); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; if (boundableGraphic != null) { roiGraphic.Suspend(); roiGraphic.Name = shapeLabel; boundableGraphic.TopLeft = new PointF(firstMajorAxisPt.X, firstMinorAxisPt.Y); boundableGraphic.BottomRight = new PointF(secondMajorAxisPt.X, secondMinorAxisPt.Y); roiGraphic.Resume(true); } graphic = roiGraphic; } else if (geoShape is aim_dotnet.Point) { var shapePoint = geoShape as aim_dotnet.Point; var callout = new CalloutGraphic(shapeLabel); callout.LineStyle = LineStyle.Solid; callout.ShowArrowhead = true; callout.AnchorPoint = AsPointF(shapePoint.Center); callout.TextLocation = callout.AnchorPoint - new SizeF(30, 30); var statefulGraphic = new StandardStatefulGraphic(callout); statefulGraphic.State = statefulGraphic.CreateInactiveState(); graphic = statefulGraphic; } else if (geoShape is aim_dotnet.MultiPoint) { // How this case works: // If we have 2 points, it's a line // If we have 3 points, it's a protractor // All others - unknown unclosed object (not supported) var shapeMultiPoint = geoShape as aim_dotnet.MultiPoint; switch (shapeMultiPoint.SpatialCoordinateCollection.Count) { case 2: { // Line var interactiveGraphic = new VerticesControlGraphic(new MoveControlGraphic(new PolylineGraphic())); var firstPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[0]); var secondPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[1]); interactiveGraphic.Subject.Points.Add(firstPt); interactiveGraphic.Subject.Points.Add(secondPt); var roiGraphic = CreateRoiGraphic(interactiveGraphic, null); roiGraphic.Name = shapeLabel; roiGraphic.Resume(true); graphic = roiGraphic; } break; case 3: { // Protractor var interactiveGraphic = new VerticesControlGraphic(new MoveControlGraphic(new ProtractorGraphic())); var firstPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[0]); var secondPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[1]); var thirdPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[2]); interactiveGraphic.Subject.Points.Add(firstPt); interactiveGraphic.Subject.Points.Add(secondPt); interactiveGraphic.Subject.Points.Add(thirdPt); var roiGraphic = CreateRoiGraphic(interactiveGraphic, new ProtractorRoiCalloutLocationStrategy()); roiGraphic.Name = shapeLabel; roiGraphic.Resume(true); graphic = roiGraphic; } break; default: throw new NotImplementedException("Reading non-linear or non-triangular MultiPoint shape is not implemented"); } } else if (geoShape is aim_dotnet.Polyline) { var shapePolyline = geoShape as aim_dotnet.Polyline; var isRectangle = false; if (shapePolyline.SpatialCoordinateCollection.Count == 4) { var twoDPoint1 = AsPointF(shapePolyline.SpatialCoordinateCollection[0]); var twoDPoint2 = AsPointF(shapePolyline.SpatialCoordinateCollection[1]); var twoDPoint3 = AsPointF(shapePolyline.SpatialCoordinateCollection[2]); var twoDPoint4 = AsPointF(shapePolyline.SpatialCoordinateCollection[3]); if ((twoDPoint1.X == twoDPoint2.X && twoDPoint2.Y == twoDPoint3.Y && twoDPoint3.X == twoDPoint4.X && twoDPoint4.Y == twoDPoint1.Y) || (twoDPoint1.Y == twoDPoint2.Y && twoDPoint2.X == twoDPoint3.X && twoDPoint3.Y == twoDPoint4.Y && twoDPoint4.X == twoDPoint1.X)) { isRectangle = true; RoiGraphic roiGraphic = AimRoiGraphic.CreateRectangle(); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; if (boundableGraphic != null) { roiGraphic.Suspend(); roiGraphic.Name = shapeLabel; boundableGraphic.TopLeft = twoDPoint1; boundableGraphic.BottomRight = twoDPoint3; roiGraphic.Resume(true); } graphic = roiGraphic; } } if (!isRectangle) { RoiGraphic roiGraphic = AimRoiGraphic.CreatePolygon(); var polylineGraphic = roiGraphic.Subject as PolylineGraphic; if (polylineGraphic != null) { roiGraphic.Suspend(); for (var i = 0; i < shapePolyline.SpatialCoordinateCollection.Count; i++) { var twoDPoint = AsPointF(shapePolyline.SpatialCoordinateCollection[i]); polylineGraphic.Points.Add(twoDPoint); } // We deal with closed polygons only if (polylineGraphic.Points.Count > 0) polylineGraphic.Points.Add(polylineGraphic.Points[0]); roiGraphic.Name = shapeLabel; roiGraphic.Resume(true); } graphic = roiGraphic; } } else throw new Exception("Unknown shape type encountered: " + geoShape.GetType().FullName); return graphic; }