protected override void Serialize(IBoundableGraphic graphic, GraphicAnnotationSequenceItem serializationState)
        {
            if (!graphic.Visible)
            {
                return;                 // if the graphic is not visible, don't serialize it!
            }
            GraphicAnnotationSequenceItem.GraphicObjectSequenceItem annotationElement = new GraphicAnnotationSequenceItem.GraphicObjectSequenceItem();

            graphic.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                annotationElement.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                annotationElement.GraphicDimensions      = 2;
                annotationElement.GraphicFilled          = GraphicAnnotationSequenceItem.GraphicFilled.N;

                SizeF halfDims = new SizeF(graphic.Width / 2, graphic.Height / 2);
                if (FloatComparer.AreEqual(graphic.Width, graphic.Height))                 // check if graphic is a circle
                {
                    annotationElement.GraphicType           = GraphicAnnotationSequenceItem.GraphicType.Circle;
                    annotationElement.NumberOfGraphicPoints = 2;

                    PointF[] list = new PointF[2];
                    list[0] = graphic.TopLeft + halfDims;                      // centre of circle
                    list[1] = graphic.TopLeft + new SizeF(0, halfDims.Height); // any point on the circle
                    annotationElement.GraphicData = list;
                }
                else
                {
                    annotationElement.GraphicType           = GraphicAnnotationSequenceItem.GraphicType.Ellipse;
                    annotationElement.NumberOfGraphicPoints = 4;

                    int      offset = graphic.Width < graphic.Height ? 2 : 0;                                    // offset list by 2 if major axis is vertical
                    PointF[] list   = new PointF[4];
                    list[(offset + 0) % 4]        = graphic.TopLeft + new SizeF(0, halfDims.Height);             // left point of horizontal axis
                    list[(offset + 1) % 4]        = graphic.TopLeft + new SizeF(graphic.Width, halfDims.Height); // right point of horizontal axis
                    list[(offset + 2) % 4]        = graphic.TopLeft + new SizeF(halfDims.Width, 0);              // top point of vertical axis
                    list[(offset + 3) % 4]        = graphic.TopLeft + new SizeF(halfDims.Width, graphic.Height); // bottom point of vertical axis
                    annotationElement.GraphicData = list;
                }
            }
            finally
            {
                graphic.ResetCoordinateSystem();
            }

            serializationState.AppendGraphicObjectSequence(annotationElement);
        }
示例#2
0
        protected override void Serialize(DicomEllipseGraphic graphic, GraphicAnnotationSequenceItem serializationState)
        {
            if (!graphic.Visible)
            {
                return;                 // if the graphic is not visible, don't serialize it!
            }
            GraphicAnnotationSequenceItem.GraphicObjectSequenceItem annotationElement = new GraphicAnnotationSequenceItem.GraphicObjectSequenceItem();

            graphic.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                annotationElement.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                annotationElement.GraphicDimensions      = 2;
                annotationElement.GraphicFilled          = GraphicAnnotationSequenceItem.GraphicFilled.N;

                if (graphic.IsRegular)                 // check if graphic is a circle
                {
                    annotationElement.GraphicType           = GraphicAnnotationSequenceItem.GraphicType.Circle;
                    annotationElement.NumberOfGraphicPoints = 2;

                    PointF[] list = new PointF[2];
                    list[0] = Vector.Midpoint(graphic.MajorAxisPoint1, graphic.MajorAxisPoint2); // centre of circle
                    list[1] = graphic.MajorAxisPoint1;                                           // any point on the circle
                    annotationElement.GraphicData = list;
                }
                else
                {
                    annotationElement.GraphicType           = GraphicAnnotationSequenceItem.GraphicType.Ellipse;
                    annotationElement.NumberOfGraphicPoints = 4;

                    PointF[] list = new PointF[4];
                    list[0] = graphic.MajorAxisPoint1;                     // left point of major axis
                    list[1] = graphic.MajorAxisPoint2;                     // right point of major axis
                    list[2] = graphic.MinorAxisPoint1;                     // top point of minor axis
                    list[3] = graphic.MinorAxisPoint2;                     // bottom point of minor axis
                    annotationElement.GraphicData = list;
                }
            }
            finally
            {
                graphic.ResetCoordinateSystem();
            }

            serializationState.AppendGraphicObjectSequence(annotationElement);
        }
        protected override void Serialize(IPointsGraphic graphic, GraphicAnnotationSequenceItem serializationState)
        {
            if (!graphic.Visible)
            {
                return;                 // if the graphic is not visible, don't serialize it!
            }
            GraphicAnnotationSequenceItem.GraphicObjectSequenceItem annotationElement = new GraphicAnnotationSequenceItem.GraphicObjectSequenceItem();

            graphic.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                IList <PointF> polyline = graphic.Points;

                annotationElement.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                annotationElement.GraphicDimensions      = 2;
                annotationElement.GraphicType            = GraphicAnnotationSequenceItem.GraphicType.Interpolated;
                annotationElement.NumberOfGraphicPoints  = polyline.Count;

                // add shape vertices
                List <PointF> list = new List <PointF>(polyline.Count);
                for (int n = 0; n < polyline.Count; n++)
                {
                    list.Add(polyline[n]);
                }
                annotationElement.GraphicData = list.ToArray();

                if (FloatComparer.AreEqual(list[0], list[list.Count - 1]))
                {
                    // shape is closed - we are required to indicate fill state
                    annotationElement.GraphicFilled = GraphicAnnotationSequenceItem.GraphicFilled.N;
                }
            }
            finally
            {
                graphic.ResetCoordinateSystem();
            }

            serializationState.AppendGraphicObjectSequence(annotationElement);
        }
        protected override void Serialize(IBoundableGraphic graphic, GraphicAnnotationSequenceItem serializationState)
        {
            if (!graphic.Visible)
            {
                return;                 // if the graphic is not visible, don't serialize it!
            }
            GraphicAnnotationSequenceItem.GraphicObjectSequenceItem annotationElement = new GraphicAnnotationSequenceItem.GraphicObjectSequenceItem();

            graphic.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                annotationElement.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                annotationElement.GraphicDimensions      = 2;
                annotationElement.GraphicType            = GraphicAnnotationSequenceItem.GraphicType.Polyline;
                annotationElement.NumberOfGraphicPoints  = 5;

                RectangleF bounds = graphic.BoundingBox;

                // add shape vertices
                PointF[] list = new PointF[5];
                list[0] = bounds.Location;
                list[1] = bounds.Location + new SizeF(bounds.Width, 0);
                list[2] = bounds.Location + bounds.Size;
                list[3] = bounds.Location + new SizeF(0, bounds.Height);
                list[4] = bounds.Location;
                annotationElement.GraphicData = list;

                annotationElement.GraphicFilled = GraphicAnnotationSequenceItem.GraphicFilled.N;
            }
            finally
            {
                graphic.ResetCoordinateSystem();
            }

            serializationState.AppendGraphicObjectSequence(annotationElement);
        }
示例#5
0
 private static IList <PointF> GetGraphicDataAsSourceCoordinates(RectangleF displayedArea, GraphicAnnotationSequenceItem.GraphicObjectSequenceItem graphicItem)
 {
     if (graphicItem.GraphicAnnotationUnits == GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Display)
     {
         return(graphicItem.GraphicData.Select(point => GetPointInSourceCoordinates(displayedArea, point)).ToList().AsReadOnly());
     }
     else
     {
         return(graphicItem.GraphicData.Select(point => new PointF(point.X, point.Y)).ToList().AsReadOnly());
     }
 }
示例#6
0
        private static IList <PointF> GetGraphicDataAsSourceCoordinates(RectangleF displayedArea, GraphicAnnotationSequenceItem.GraphicObjectSequenceItem graphicItem)
        {
            List <PointF> list;

            if (graphicItem.GraphicAnnotationUnits == GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Display)
            {
                list = new List <PointF>(graphicItem.NumberOfGraphicPoints);
                foreach (PointF point in graphicItem.GraphicData)
                {
                    list.Add(GetPointInSourceCoordinates(displayedArea, point));
                }
            }
            else
            {
                // offset to account for our 0,0 origin versyus DICOM 1,1 origin
                list = new List <PointF>(graphicItem.NumberOfGraphicPoints);
                foreach (PointF point in graphicItem.GraphicData)
                {
                    list.Add(new PointF(point.X - 1, point.Y - 1));
                }
            }
            return(list.AsReadOnly());
        }