internal static IMarkup GraphicToIMarkup(IGraphic graphic)
        {
            if (graphic == null || graphic.ParentPresentationImage == null)
                return null;

            var markup = DoGraphicToIMarkup(graphic);

            if (markup != null)
            {
                var sopInstanceUid = string.Empty;
                var frameNumber = 1;

                try
                {
                    if (graphic.ParentPresentationImage is IImageSopProvider)
                    {
                        var imageSopProvider = graphic.ParentPresentationImage as IImageSopProvider;

                        sopInstanceUid = imageSopProvider.ImageSop.SopInstanceUid;
                        frameNumber = imageSopProvider.Frame.FrameNumber;
                    }
                    else if (!string.IsNullOrEmpty(graphic.ParentPresentationImage.Uid))
                        sopInstanceUid = graphic.ParentPresentationImage.Uid;
                }
                catch (Exception)
                {
                }
                markup.PresentationImageUid = sopInstanceUid;
                markup.FrameNumber = frameNumber;
                markup.IncludeInAnnotation = true;
                markup.GraphicHashcode = graphic.GetHashCode();
            }

            return markup;
        }
Пример #2
0
        internal static IMarkup GraphicToIMarkup(IGraphic graphic)
        {
            if (graphic == null || graphic.ParentPresentationImage == null)
            {
                return(null);
            }

            var markup = DoGraphicToIMarkup(graphic);

            if (markup != null)
            {
                var sopInstanceUid = string.Empty;
                var frameNumber    = 1;

                try
                {
                    if (graphic.ParentPresentationImage is IImageSopProvider)
                    {
                        var imageSopProvider = graphic.ParentPresentationImage as IImageSopProvider;

                        sopInstanceUid = imageSopProvider.ImageSop.SopInstanceUid;
                        frameNumber    = imageSopProvider.Frame.FrameNumber;
                    }
                    else if (!string.IsNullOrEmpty(graphic.ParentPresentationImage.Uid))
                    {
                        sopInstanceUid = graphic.ParentPresentationImage.Uid;
                    }
                }
                catch (Exception)
                {
                }
                markup.PresentationImageUid = sopInstanceUid;
                markup.FrameNumber          = frameNumber;
                markup.IncludeInAnnotation  = true;
                markup.GraphicHashcode      = graphic.GetHashCode();
            }

            return(markup);
        }
        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;
        }
 internal static bool RoiGraphicAndSegGraphicsMatch(IGraphic roiGraphic, ISegGraphic segGraphic)
 {
     return(roiGraphic.GetHashCode().Equals(segGraphic.GraphicHashCode) &&
            roiGraphic.Name == segGraphic.Label);
 }
 internal static bool RoiGraphicAndSegGraphicsMatch(IGraphic roiGraphic, ISegGraphic segGraphic)
 {
     return roiGraphic.GetHashCode().Equals(segGraphic.GraphicHashCode) &&
            roiGraphic.Name == segGraphic.Label;
 }
Пример #6
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);
        }