/// <summary>
        /// Helper method to serialize a graphic to the supplied serialization state object.
        /// </summary>
        /// <param name="graphic">The graphic to serialize.</param>
        /// <param name="serializationState">The state to which the graphic should be serialized.</param>
        /// <returns>True if the graphic was serializable; False otherwise.</returns>
        public static bool SerializeGraphic(IGraphic graphic, GraphicAnnotationSequenceItem serializationState)
        {
            Platform.CheckForNullReference(graphic, "graphic");
            Platform.CheckForNullReference(serializationState, "serializationState");

            object[] attributes = graphic.GetType().GetCustomAttributes(typeof(DicomSerializableGraphicAnnotationAttribute), true);
            if (attributes.Length > 0)
            {
                ((DicomSerializableGraphicAnnotationAttribute)attributes[0]).Serializer.Serialize(graphic, serializationState);
                return(true);
            }
            return(false);
        }
예제 #2
0
        public static ContextMenu GetMenu(IGraphic graphic)
        {
            Type type = graphic.GetType();

            if (tools.ContainsKey(type))
            {
                return(tools[type].Menu);
            }
            else
            {
                return(new ContextMenu());
            }
        }
        private static IMarkup DoGraphicToIMarkup(IGraphic graphic)
        {
            if (graphic == null || graphic.ParentPresentationImage == null)
                return null;

            IMarkup markup = null;
            var roiGraphic = graphic as RoiGraphic;
            if (roiGraphic != null)
            {
                if (roiGraphic.Roi is EllipticalRoi)
                {
                    var ellipse = roiGraphic.Roi as EllipticalRoi;

                    markup = new MarkupEllipse
                    {
                        TopLeft = new PointF(ellipse.BoundingBox.Left, ellipse.BoundingBox.Top),
                        BottomRight = new PointF(ellipse.BoundingBox.Right, ellipse.BoundingBox.Bottom),
                        Name = graphic.Name,
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                else if (roiGraphic.Roi is PolygonalRoi)
                {
                    var polygon = roiGraphic.Roi as PolygonalRoi;

                    markup = new MarkupPolygonal
                    {
                        Name = graphic.Name,
                        Vertices = polygon.Polygon.Vertices == null ? null : new List<PointF>(polygon.Polygon.Vertices),
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                else if (roiGraphic.Roi is RectangularRoi)
                {
                    var rectangularRoi = roiGraphic.Roi as RectangularRoi;

                    markup = new MarkupRectangle
                    {
                        TopLeft = new PointF(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Top),
                        BottomRight = new PointF(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Bottom),
                        Name = graphic.Name,
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                else if (roiGraphic.Roi is ProtractorRoi)
                {
                    var protractorRoi = roiGraphic.Roi as ProtractorRoi;

                    markup = new MarkupProtractor
                    {
                        TopLeft = new PointF(protractorRoi.BoundingBox.Left, protractorRoi.BoundingBox.Top),
                        BottomRight = new PointF(protractorRoi.BoundingBox.Right, protractorRoi.BoundingBox.Bottom),
                        Name = graphic.Name,
                        Points = protractorRoi.Points == null ? null : new List<PointF>(protractorRoi.Points),
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }
                else if (roiGraphic.Roi is LinearRoi)
                {
                    var linearRoi = roiGraphic.Roi as LinearRoi;

                    markup = new MarkupLinear
                    {
                        Vertices = linearRoi.Points == null ? null : new List<PointF>(linearRoi.Points),
                        Name = graphic.Name,
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                if (markup != null)
                    markup.CaptionText = roiGraphic.Roi.GetType().Name + Environment.NewLine + roiGraphic.Callout.Text;
            }
            else if (graphic is UserCalloutGraphic)
            {
                var userCalloutGraphic = graphic as UserCalloutGraphic;
                markup = new MarkupPoint
                {
                    Name = graphic.Name,
                    CaptionText = userCalloutGraphic.Text,
                    CalloutText = userCalloutGraphic.Text,
                    CalloutLocation = userCalloutGraphic.TextLocation,
                    Point = userCalloutGraphic.AnchorPoint,
                    GraphicHashcode = graphic.GetHashCode()
                };
            }
            else if (graphic is CrosshairCalloutGraphic)
            {
                var userCalloutGraphic = graphic as CrosshairCalloutGraphic;
                markup = new MarkupPoint
                {
                    Name = graphic.Name,
                    CaptionText = userCalloutGraphic.Text,
                    CalloutText = userCalloutGraphic.Text,
                    CalloutLocation = userCalloutGraphic.TextLocation,
                    Point = userCalloutGraphic.AnchorPoint,
                    UseCrosshair = true,
                    GraphicHashcode = graphic.GetHashCode()
                };
            }
            else if (graphic is InvariantTextPrimitive)
            {
                var textGraphic = (InvariantTextPrimitive)graphic;
                markup = new MarkupPoint
                {
                    Name = graphic.Name,
                    CaptionText = textGraphic.Text,
                    CalloutText = textGraphic.Text,
                    CalloutLocation = textGraphic.Location,
                    Point = textGraphic.Location,
                    UseCrosshair = false,
                    GraphicHashcode = graphic.GetHashCode()
                };
            }
            else if (graphic is ContextMenuControlGraphic)
            {
                markup = DoGraphicToIMarkup(((ContextMenuControlGraphic)graphic).Subject);
            }
            else if (graphic is AimGraphic)
            {
                markup = DoGraphicToIMarkup(((AimGraphic)graphic).Graphic);
                // Fix name - not all composite graphics may have the Name set correctly
                if (markup != null)
                    markup.Name = ((AimGraphic)graphic).Graphic.Name;
            }
            else if (graphic is StandardStatefulGraphic)
            {
                markup = DoGraphicToIMarkup(((StandardStatefulGraphic)graphic).Subject);
            }
            else if (graphic is SegFrameImageGraphic)
            {
                // NO-OP
                // TODO: implement IMarkup for this type of graphic if we ever need to have segmentation graphic in the TemplateTree
            }
            else
                System.Diagnostics.Debug.Assert(false, "Could not create Markup from " + graphic.GetType().Name);

            return markup;
        }
		/// <summary>
		/// Helper method to serialize a graphic to the supplied serialization state object.
		/// </summary>
		/// <param name="graphic">The graphic to serialize.</param>
		/// <param name="serializationState">The state to which the graphic should be serialized.</param>
		/// <returns>True if the graphic was serializable; False otherwise.</returns>
		public static bool SerializeGraphic(IGraphic graphic, GraphicAnnotationSequenceItem serializationState)
		{
			Platform.CheckForNullReference(graphic, "graphic");
			Platform.CheckForNullReference(serializationState, "serializationState");

			object[] attributes = graphic.GetType().GetCustomAttributes(typeof (DicomSerializableGraphicAnnotationAttribute), true);
			if (attributes.Length > 0)
			{
				((DicomSerializableGraphicAnnotationAttribute) attributes[0]).Serializer.Serialize(graphic, serializationState);
				return true;
			}
			return false;
		}
예제 #5
0
        private static IMarkup DoGraphicToIMarkup(IGraphic graphic)
        {
            if (graphic == null || graphic.ParentPresentationImage == null)
            {
                return(null);
            }

            IMarkup markup     = null;
            var     roiGraphic = graphic as RoiGraphic;

            if (roiGraphic != null)
            {
                if (roiGraphic.Roi is EllipticalRoi)
                {
                    var ellipse = roiGraphic.Roi as EllipticalRoi;

                    markup = new MarkupEllipse
                    {
                        TopLeft         = new PointF(ellipse.BoundingBox.Left, ellipse.BoundingBox.Top),
                        BottomRight     = new PointF(ellipse.BoundingBox.Right, ellipse.BoundingBox.Bottom),
                        Name            = graphic.Name,
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                else if (roiGraphic.Roi is PolygonalRoi)
                {
                    var polygon = roiGraphic.Roi as PolygonalRoi;

                    markup = new MarkupPolygonal
                    {
                        Name            = graphic.Name,
                        Vertices        = polygon.Polygon.Vertices == null ? null : new List <PointF>(polygon.Polygon.Vertices),
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                else if (roiGraphic.Roi is RectangularRoi)
                {
                    var rectangularRoi = roiGraphic.Roi as RectangularRoi;

                    markup = new MarkupRectangle
                    {
                        TopLeft         = new PointF(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Top),
                        BottomRight     = new PointF(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Bottom),
                        Name            = graphic.Name,
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                else if (roiGraphic.Roi is ProtractorRoi)
                {
                    var protractorRoi = roiGraphic.Roi as ProtractorRoi;

                    markup = new MarkupProtractor
                    {
                        TopLeft         = new PointF(protractorRoi.BoundingBox.Left, protractorRoi.BoundingBox.Top),
                        BottomRight     = new PointF(protractorRoi.BoundingBox.Right, protractorRoi.BoundingBox.Bottom),
                        Name            = graphic.Name,
                        Points          = protractorRoi.Points == null ? null : new List <PointF>(protractorRoi.Points),
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }
                else if (roiGraphic.Roi is LinearRoi)
                {
                    var linearRoi = roiGraphic.Roi as LinearRoi;

                    markup = new MarkupLinear
                    {
                        Vertices        = linearRoi.Points == null ? null : new List <PointF>(linearRoi.Points),
                        Name            = graphic.Name,
                        GraphicHashcode = graphic.GetHashCode(),
                        CalloutLocation = roiGraphic.Callout.TextLocation
                    };
                }

                if (markup != null)
                {
                    markup.CaptionText = roiGraphic.Roi.GetType().Name + Environment.NewLine + roiGraphic.Callout.Text;
                }
            }
            else if (graphic is UserCalloutGraphic)
            {
                var userCalloutGraphic = graphic as UserCalloutGraphic;
                markup = new MarkupPoint
                {
                    Name            = graphic.Name,
                    CaptionText     = userCalloutGraphic.Text,
                    CalloutText     = userCalloutGraphic.Text,
                    CalloutLocation = userCalloutGraphic.TextLocation,
                    Point           = userCalloutGraphic.AnchorPoint,
                    GraphicHashcode = graphic.GetHashCode()
                };
            }
            else if (graphic is CrosshairCalloutGraphic)
            {
                var userCalloutGraphic = graphic as CrosshairCalloutGraphic;
                markup = new MarkupPoint
                {
                    Name            = graphic.Name,
                    CaptionText     = userCalloutGraphic.Text,
                    CalloutText     = userCalloutGraphic.Text,
                    CalloutLocation = userCalloutGraphic.TextLocation,
                    Point           = userCalloutGraphic.AnchorPoint,
                    UseCrosshair    = true,
                    GraphicHashcode = graphic.GetHashCode()
                };
            }
            else if (graphic is InvariantTextPrimitive)
            {
                var textGraphic = (InvariantTextPrimitive)graphic;
                markup = new MarkupPoint
                {
                    Name            = graphic.Name,
                    CaptionText     = textGraphic.Text,
                    CalloutText     = textGraphic.Text,
                    CalloutLocation = textGraphic.Location,
                    Point           = textGraphic.Location,
                    UseCrosshair    = false,
                    GraphicHashcode = graphic.GetHashCode()
                };
            }
            else if (graphic is ContextMenuControlGraphic)
            {
                markup = DoGraphicToIMarkup(((ContextMenuControlGraphic)graphic).Subject);
            }
            else if (graphic is AimGraphic)
            {
                markup = DoGraphicToIMarkup(((AimGraphic)graphic).Graphic);
                // Fix name - not all composite graphics may have the Name set correctly
                if (markup != null)
                {
                    markup.Name = ((AimGraphic)graphic).Graphic.Name;
                }
            }
            else if (graphic is StandardStatefulGraphic)
            {
                markup = DoGraphicToIMarkup(((StandardStatefulGraphic)graphic).Subject);
            }
            else if (graphic is SegFrameImageGraphic)
            {
                // NO-OP
                // TODO: implement IMarkup for this type of graphic if we ever need to have segmentation graphic in the TemplateTree
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Could not create Markup from " + graphic.GetType().Name);
            }

            return(markup);
        }