public static IMarkup ToMarkup2D(aim4_dotnet.GeometricShapeEntity geometricShape, string markupText)
        {
            if (geometricShape == null)
                return null;

            if (geometricShape is aim4_dotnet.TwoDimensionPoint)
            {
                var point = (aim4_dotnet.TwoDimensionPoint)geometricShape;

                var markup = new MarkupPoint();
                markup.Name = markupText;
                markup.IncludeInAnnotation = point.IncludeFlag;
                markup.Point = AsPointF(point.Center);
                markup.CalloutText = string.Empty; // markupText;
                markup.CalloutLocation = markup.Point - new SizeF(30, 30);
                SetMarkupImageReference(markup, point);

                return markup;
            }
            if (geometricShape is aim4_dotnet.TwoDimensionCircle)
            {
                var circle = (aim4_dotnet.TwoDimensionCircle)geometricShape;

                PointF centerPt = AsPointF(circle.Center);
                PointF radiusPt = AsPointF(circle.RadiusPoint);
                double radiusLength = Vector.Distance(centerPt, radiusPt);

                var markup = new MarkupEllipse();
                markup.Name = markupText;
                markup.IncludeInAnnotation = circle.IncludeFlag;
                markup.TopLeft = new PointF((float)(centerPt.X - radiusLength), (float)(centerPt.Y - radiusLength));
                markup.BottomRight = new PointF((float)(centerPt.X + radiusLength), (float)(centerPt.Y + radiusLength));
                markup.CalloutLocation = markup.TopLeft - new SizeF(30, 30);
                SetMarkupImageReference(markup, circle);

                return markup;
            }
            if (geometricShape is aim4_dotnet.TwoDimensionEllipse)
            {
                var ellipse = (aim4_dotnet.TwoDimensionEllipse)geometricShape;

                Debug.Assert(ellipse.TwoDimensionSpatialCoordinateCollection.Count == 4, "Ellipse must have four points");
                var firstMajorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[0]);
                var secondMajorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[1]);
                var firstMinorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[2]);
                var secondMinorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[3]);

                var markup = new MarkupEllipse();
                markup.Name = markupText;
                markup.IncludeInAnnotation = ellipse.IncludeFlag;
                markup.TopLeft = new PointF(firstMajorAxisPt.X, firstMinorAxisPt.Y);
                markup.BottomRight = new PointF(secondMajorAxisPt.X, secondMinorAxisPt.Y);
                markup.CalloutLocation = markup.TopLeft - new SizeF(30, 30);
                SetMarkupImageReference(markup, ellipse);

                return markup;
            }
            if (geometricShape is aim4_dotnet.TwoDimensionPolyline)
            {
                var polyline = (aim4_dotnet.TwoDimensionPolyline)geometricShape;

                // Check if this is a non-rotated rectangle
                if (polyline.TwoDimensionSpatialCoordinateCollection.Count == 4)
                {
                    PointF twoDPoint1 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[0]);
                    PointF twoDPoint2 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[1]);
                    PointF twoDPoint3 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[2]);
                    PointF twoDPoint4 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[3]);
                    // If it's a rectangle with sides parallel to the axes
                    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))
                    {
                        var markupRectangle = new MarkupRectangle();
                        markupRectangle.TopLeft = twoDPoint1;
                        markupRectangle.BottomRight = twoDPoint3;
                        markupRectangle.Name = markupText;
                        markupRectangle.IncludeInAnnotation = polyline.IncludeFlag;
                        markupRectangle.CalloutLocation = markupRectangle.TopLeft - new SizeF(30, 30);
                        SetMarkupImageReference(markupRectangle, polyline);

                        return markupRectangle;
                    }
                }

                var points = new List<PointF>();
                foreach (var spatialCoordinate in polyline.TwoDimensionSpatialCoordinateCollection)
                    if (spatialCoordinate != null)
                        points.Add(AsPointF(spatialCoordinate));

                var markup = new MarkupPolygonal();
                markup.Vertices = points;
                markup.Name = markupText;
                markup.IncludeInAnnotation = polyline.IncludeFlag;
                markup.CalloutLocation = markup.Vertices[0] - new SizeF(30, 30);
                SetMarkupImageReference(markup, polyline);

                return markup;
            }
            if (geometricShape is aim4_dotnet.TwoDimensionMultiPoint)
            {
                var multiPoint = (aim4_dotnet.TwoDimensionMultiPoint)geometricShape;

                IMarkup markup;
                switch (multiPoint.TwoDimensionSpatialCoordinateCollection.Count)
                {
                    case 2:
                        {
                            // Line
                            var markupLinear = new MarkupLinear();
                            markupLinear.Vertices = new List<PointF>(2);
                            markupLinear.Vertices.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[0]));
                            markupLinear.Vertices.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[1]));
                            markupLinear.CalloutLocation = markupLinear.Vertices[0] - new SizeF(30, 30);
                            markup = markupLinear;
                        }
                        break;
                    case 3:
                        {
                            // Protractor
                            var markupProtractor = new MarkupProtractor();
                            markupProtractor.Points = new List<PointF>(3);
                            markupProtractor.Points.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[0]));
                            markupProtractor.Points.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[1]));
                            markupProtractor.Points.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[2]));
                            markupProtractor.CalloutLocation = markupProtractor.Points[0] - new SizeF(30, 30);
                            markup = markupProtractor;
                        }
                        break;
                    default:
                        throw new NotImplementedException("Reading non-linear or non-triangular MultiPoint shape is not implemented");
                }

                markup.Name = markupText;
                markup.IncludeInAnnotation = multiPoint.IncludeFlag;
                SetMarkupImageReference(markup, multiPoint);
                return markup;
            }

            // TODO - 3D GeoShapes Conversions

            throw new NotImplementedException();
            return null;
        }
        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;
        }
Beispiel #3
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);
        }