Пример #1
0
 protected override void Serialize(CompositeGraphic graphic, GraphicAnnotationSequenceItem serializationState)
 {
     foreach (IGraphic subgraphic in graphic.Graphics)
     {
         SerializeGraphic(subgraphic, serializationState);
     }
 }
        protected override void Serialize(ITextGraphic textGraphic, GraphicAnnotationSequenceItem serializationState)
        {
            // if the callout is not visible, don't serialize it!
            if (!textGraphic.Visible)
            {
                return;
            }

            if (string.IsNullOrEmpty(textGraphic.Text))
            {
                return;
            }

            GraphicAnnotationSequenceItem.TextObjectSequenceItem text = new GraphicAnnotationSequenceItem.TextObjectSequenceItem();

            textGraphic.CoordinateSystem = CoordinateSystem.Source;
            try
            {
                RectangleF boundingBox = RectangleUtilities.ConvertToPositiveRectangle(textGraphic.BoundingBox);
                text.BoundingBoxAnnotationUnits             = GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Pixel;
                text.BoundingBoxTextHorizontalJustification = GraphicAnnotationSequenceItem.BoundingBoxTextHorizontalJustification.Left;
                text.BoundingBoxTopLeftHandCorner           = boundingBox.Location;
                text.BoundingBoxBottomRightHandCorner       = boundingBox.Location + boundingBox.Size;
                text.UnformattedTextValue = textGraphic.Text;
            }
            finally
            {
                textGraphic.ResetCoordinateSystem();
            }

            serializationState.AppendTextObjectSequence(text);
        }
Пример #3
0
        protected override void Serialize(AnnotationGraphic annotationGraphic, GraphicAnnotationSequenceItem serializationState)
        {
            Platform.CheckForNullReference(annotationGraphic, "annotationGraphic");
            Platform.CheckForNullReference(serializationState, "serializationState");

            SerializeGraphic(annotationGraphic.Callout, serializationState);
            SerializeGraphic(annotationGraphic.Subject, serializationState);
        }
        private static bool AnyContent(GraphicAnnotationSequenceItem annotation)
        {
            var graphicObjectSequenceItems = annotation.GraphicObjectSequence;
            var textObjectSequenceItems    = annotation.TextObjectSequence;

            return((graphicObjectSequenceItems != null && graphicObjectSequenceItems.Length > 0) ||
                   (textObjectSequenceItems != null && textObjectSequenceItems.Length > 0));
        }
        /// <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);
        }
        private static void SetAllSpecificCharacterSets(GraphicAnnotationSequenceItem annotation, string specificCharacterSet)
        {
            if (annotation.TextObjectSequence == null)
            {
                return;
            }

            foreach (var textItem in annotation.TextObjectSequence)
            {
                var attributeCollection = textItem.DicomAttributeProvider as DicomAttributeCollection;
                if (attributeCollection != null)
                {
                    attributeCollection.SpecificCharacterSet = specificCharacterSet;
                }
            }
        }
        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);
        }
Пример #8
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 void SerializeGraphicAnnotation(GraphicAnnotationModuleIod graphicAnnotationModule, DicomPresentationImageCollection <T> images)
        {
            List <GraphicAnnotationSequenceItem> annotations = new List <GraphicAnnotationSequenceItem>();

            foreach (T image in images)
            {
                DicomGraphicsPlane psGraphic = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false);
                if (psGraphic != null)
                {
                    foreach (ILayer layerGraphic in (IEnumerable <ILayer>)psGraphic.Layers)
                    {
                        foreach (IGraphic graphic in layerGraphic.Graphics)
                        {
                            GraphicAnnotationSequenceItem annotation = new GraphicAnnotationSequenceItem();
                            if (GraphicAnnotationSerializer.SerializeGraphic(graphic, annotation) && AnyContent(annotation))
                            {
                                SetAllSpecificCharacterSets(annotation, DataSet.SpecificCharacterSet);
                                annotation.GraphicLayer            = layerGraphic.Id.ToUpperInvariant();
                                annotation.ReferencedImageSequence = new[] { CreateImageSopInstanceReference(image.Frame) };
                                annotations.Add(annotation);
                            }
                        }
                    }
                }

                foreach (IGraphic graphic in image.OverlayGraphics)
                {
                    GraphicAnnotationSequenceItem annotation = new GraphicAnnotationSequenceItem();
                    if (GraphicAnnotationSerializer.SerializeGraphic(graphic, annotation) && AnyContent(annotation))
                    {
                        SetAllSpecificCharacterSets(annotation, DataSet.SpecificCharacterSet);
                        annotation.GraphicLayer            = _annotationsLayerId;
                        annotation.ReferencedImageSequence = new[] { CreateImageSopInstanceReference(image.Frame) };
                        annotations.Add(annotation);
                    }
                }
            }

            if (annotations.Count > 0)
            {
                graphicAnnotationModule.GraphicAnnotationSequence = annotations.ToArray();
            }
        }
        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);
        }
Пример #11
0
            private static void SerializeCallout(ICalloutGraphic calloutGraphic, GraphicAnnotationSequenceItem serializationState)
            {
                calloutGraphic.CoordinateSystem = CoordinateSystem.Source;
                try
                {
                    RectangleF textBoundingBox = RectangleUtilities.ConvertToPositiveRectangle(calloutGraphic.TextBoundingBox);

                    TextObject text = new TextObject();
                    text.BoundingBoxAnnotationUnits             = GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Pixel;
                    text.BoundingBoxBottomRightHandCorner       = new PointF(textBoundingBox.Right, textBoundingBox.Bottom);
                    text.BoundingBoxTextHorizontalJustification = GraphicAnnotationSequenceItem.BoundingBoxTextHorizontalJustification.Center;
                    text.BoundingBoxTopLeftHandCorner           = textBoundingBox.Location;
                    text.UnformattedTextValue = calloutGraphic.Text;
                    serializationState.AppendTextObjectSequence(text);

                    // draw the callout line manually instead of anchoring the text,
                    // since we do not want the text to be moveable as permitted if we have an anchor point
                    SerializeDashedLine(calloutGraphic.TextLocation, calloutGraphic.AnchorPoint, calloutGraphic.SpatialTransform, serializationState, false);
                }
                finally
                {
                    calloutGraphic.ResetCoordinateSystem();
                }
            }
        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);
        }
Пример #13
0
        public static DicomGraphicAnnotation CreateGraphicAnnotation(Frame frame, GraphicAnnotationSequenceItem sequenceItem, RectangleF displayedArea, bool interactive = false)
        {
            ImageSopInstanceReferenceDictionary dictionary = new ImageSopInstanceReferenceDictionary(sequenceItem.ReferencedImageSequence, true);

            return(dictionary.ReferencesFrame(frame.ParentImageSop.SopInstanceUid, frame.FrameNumber) ? DicomGraphicAnnotation.Create(sequenceItem, displayedArea) : null);
        }
Пример #14
0
            private static void SerializeDashedLine(PointF point1, PointF point2, SpatialTransform spatialTransform, GraphicAnnotationSequenceItem serializationState, bool showHashes)
            {
                // these control parameters are in screen pixels at the nominal presentation zoom level
                const float period    = 8;
                const float amplitude = 0.5f;

                SizeF normalVector;
                SizeF dashVector;
                float periods;

                // compute the dash vector and cross hash vector to be sized relative to screen pixels at nominal presentation zoom level
                {
                    PointF dstLineVector = spatialTransform.ConvertToDestination(new SizeF(point2) - new SizeF(point1)).ToPointF();
                    float  dstMagnitude  = (float)Math.Sqrt(dstLineVector.X * dstLineVector.X + dstLineVector.Y * dstLineVector.Y);
                    periods          = dstMagnitude / period;
                    dstLineVector.X /= dstMagnitude;
                    dstLineVector.Y /= dstMagnitude;
                    dashVector       = spatialTransform.ConvertToSource(new SizeF(dstLineVector.X * period / 2, dstLineVector.Y * period / 2));
                    normalVector     = spatialTransform.ConvertToSource(new SizeF(-dstLineVector.Y * amplitude, dstLineVector.X * amplitude));
                }

                PointF start = point1;
                int    limit = (int)periods;

                for (int n = 0; n < limit; n++)
                {
                    PointF midPeriod = start + dashVector;
                    start = midPeriod + dashVector;

                    GraphicObject dash = new GraphicObject();
                    dash.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                    dash.GraphicData            = new PointF[] { midPeriod, start };
                    dash.GraphicDimensions      = 2;
                    dash.GraphicFilled          = GraphicAnnotationSequenceItem.GraphicFilled.N;
                    dash.GraphicType            = GraphicAnnotationSequenceItem.GraphicType.Polyline;
                    dash.NumberOfGraphicPoints  = 2;
                    serializationState.AppendGraphicObjectSequence(dash);
                }

                // the first half of each period has no line, so this is only necessary if the residual is over half a period
                if (periods - limit > 0.5f)
                {
                    GraphicObject dash = new GraphicObject();
                    dash.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                    dash.GraphicData            = new PointF[] { start + dashVector, point2 };
                    dash.GraphicDimensions      = 2;
                    dash.GraphicFilled          = GraphicAnnotationSequenceItem.GraphicFilled.N;
                    dash.GraphicType            = GraphicAnnotationSequenceItem.GraphicType.Polyline;
                    dash.NumberOfGraphicPoints  = 2;
                    serializationState.AppendGraphicObjectSequence(dash);
                }

                if (showHashes)
                {
                    GraphicObject hash1 = new GraphicObject();
                    hash1.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                    hash1.GraphicData            = new PointF[] { point1 - normalVector, point1 + normalVector };
                    hash1.GraphicDimensions      = 2;
                    hash1.GraphicFilled          = GraphicAnnotationSequenceItem.GraphicFilled.N;
                    hash1.GraphicType            = GraphicAnnotationSequenceItem.GraphicType.Polyline;
                    hash1.NumberOfGraphicPoints  = 2;
                    serializationState.AppendGraphicObjectSequence(hash1);

                    GraphicObject hash2 = new GraphicObject();
                    hash2.GraphicAnnotationUnits = GraphicAnnotationSequenceItem.GraphicAnnotationUnits.Pixel;
                    hash2.GraphicData            = new PointF[] { point2 - normalVector, point2 + normalVector };
                    hash2.GraphicDimensions      = 2;
                    hash2.GraphicFilled          = GraphicAnnotationSequenceItem.GraphicFilled.N;
                    hash2.GraphicType            = GraphicAnnotationSequenceItem.GraphicType.Polyline;
                    hash2.NumberOfGraphicPoints  = 2;
                    serializationState.AppendGraphicObjectSequence(hash2);
                }
            }
Пример #15
0
 private static void SerializeDashedLine(ILineSegmentGraphic lineSegmentGraphic, GraphicAnnotationSequenceItem serializationState)
 {
     lineSegmentGraphic.CoordinateSystem = CoordinateSystem.Source;
     try
     {
         SerializeDashedLine(lineSegmentGraphic.Point1, lineSegmentGraphic.Point2, lineSegmentGraphic.SpatialTransform, serializationState, true);
     }
     finally
     {
         lineSegmentGraphic.ResetCoordinateSystem();
     }
 }
Пример #16
0
            protected override void Serialize(ShowAnglesToolGraphic showAnglesToolGraphic, GraphicAnnotationSequenceItem serializationState)
            {
                if (!showAnglesToolGraphic.Visible)
                {
                    return;
                }

                foreach (IGraphic graphic in showAnglesToolGraphic.Graphics)
                {
                    if (!graphic.Visible)
                    {
                        continue;
                    }

                    if (graphic is ILineSegmentGraphic)
                    {
                        SerializeDashedLine((ILineSegmentGraphic)graphic, serializationState);
                    }
                    else if (graphic is ICalloutGraphic)
                    {
                        SerializeCallout((ICalloutGraphic)graphic, serializationState);
                    }
                }
            }
Пример #17
0
        /// <summary>
        /// Constructs a new <see cref="IGraphic"/> whose contents are constructed based on a <see cref="GraphicAnnotationSequenceItem">DICOM Graphic Annotation Sequence Item</see>.
        /// </summary>
        /// <param name="graphicAnnotationSequenceItem">The DICOM graphic annotation sequence item to render.</param>
        /// <param name="displayedArea">The image's displayed area with which to </param>
        public static DicomGraphicAnnotation Create(GraphicAnnotationSequenceItem graphicAnnotationSequenceItem, RectangleF displayedArea)
        {
            var subjectGraphic = new SubjectGraphic();
            var dataPoints     = new List <PointF>();

            if (graphicAnnotationSequenceItem.GraphicObjectSequence != null)
            {
                foreach (var graphicItem in graphicAnnotationSequenceItem.GraphicObjectSequence)
                {
                    try
                    {
                        var points  = GetGraphicDataAsSourceCoordinates(displayedArea, graphicItem);
                        var graphic = CreateGraphic(graphicItem.GraphicType, points, true);
                        if (graphic != null)
                        {
                            subjectGraphic.Graphics.Add(new ElementGraphic(graphic));
                        }
                        dataPoints.AddRange(points);
                    }
                    catch (Exception ex)
                    {
                        Platform.Log(LogLevel.Warn, ex, "DICOM Softcopy Presentation State Deserialization Fault (Graphic Object Type {0}). Reprocess with log level DEBUG to see DICOM data dump.", graphicItem.GraphicType);
                        Platform.Log(LogLevel.Debug, graphicItem.DicomSequenceItem.Dump());
                    }
                }
            }

            var annotations      = new List <IGraphic>();
            var annotationBounds = RectangleF.Empty;

            if (dataPoints.Count > 0)
            {
                annotationBounds = RectangleUtilities.ComputeBoundingRectangle(dataPoints.ToArray());
            }
            if (graphicAnnotationSequenceItem.TextObjectSequence != null)
            {
                foreach (var textItem in graphicAnnotationSequenceItem.TextObjectSequence)
                {
                    try
                    {
                        annotations.Add(CreateCalloutText(annotationBounds, displayedArea, textItem));
                    }
                    catch (Exception ex)
                    {
                        Platform.Log(LogLevel.Warn, ex, "DICOM Softcopy Presentation State Deserialization Fault (Text Object). Reprocess with log level DEBUG to see DICOM data dump.");
                        Platform.Log(LogLevel.Debug, textItem.DicomSequenceItem.Dump());
                    }
                }
            }

            var calloutGraphic = annotations.FirstOrDefault() as ICalloutGraphic;

            if (subjectGraphic.Graphics.Count == 1 && annotations.Count == 1 && calloutGraphic != null)
            {
                // disable the subject graphics before we add the callout, because we want the callout to be moveable
                subjectGraphic.SetEnabled(false);

                var subjectElement = (ElementGraphic)subjectGraphic.Graphics.Single();
                subjectElement.Graphics.Add(calloutGraphic);
                subjectElement.Callout = calloutGraphic;
            }
            else
            {
                subjectGraphic.Graphics.AddRange(annotations.Where(g => !(g is ICalloutGraphic)).Select(g => new TextEditControlGraphic(g)));
                subjectGraphic.Graphics.AddRange(annotations.OfType <ICalloutGraphic>().Select(g => new UserCalloutGraphic
                {
                    AnchorPoint   = g.AnchorPoint,
                    TextLocation  = g.TextLocation,
                    Text          = g.Text,
                    ShowArrowhead = !(g is CalloutGraphic) || ((CalloutGraphic)g).ShowArrowhead
                }));

                // disable both subject graphiucs and any callouts
                subjectGraphic.SetEnabled(false);
            }

            subjectGraphic.SetColor(Color.LemonChiffon);
            return(new DicomGraphicAnnotation(subjectGraphic));
        }
Пример #18
0
        /// <summary>
        /// Constructs a new <see cref="IGraphic"/> whose contents are constructed based on a <see cref="GraphicAnnotationSequenceItem">DICOM Graphic Annotation Sequence Item</see>.
        /// </summary>
        /// <param name="graphicAnnotationSequenceItem">The DICOM graphic annotation sequence item to render.</param>
        /// <param name="displayedArea">The image's displayed area with which to </param>
        public DicomGraphicAnnotation(GraphicAnnotationSequenceItem graphicAnnotationSequenceItem, RectangleF displayedArea)
        {
            this.CoordinateSystem = CoordinateSystem.Source;
            _layerId = graphicAnnotationSequenceItem.GraphicLayer ?? string.Empty;

            try
            {
                List <PointF> dataPoints = new List <PointF>();
                if (graphicAnnotationSequenceItem.GraphicObjectSequence != null)
                {
                    foreach (GraphicAnnotationSequenceItem.GraphicObjectSequenceItem graphicItem in graphicAnnotationSequenceItem.GraphicObjectSequence)
                    {
                        try
                        {
                            IList <PointF> points = GetGraphicDataAsSourceCoordinates(displayedArea, graphicItem);
                            switch (graphicItem.GraphicType)
                            {
                            case GraphicAnnotationSequenceItem.GraphicType.Interpolated:
                                base.Graphics.Add(CreateInterpolated(points));
                                break;

                            case GraphicAnnotationSequenceItem.GraphicType.Polyline:
                                base.Graphics.Add(CreatePolyline(points));
                                break;

                            case GraphicAnnotationSequenceItem.GraphicType.Point:
                                base.Graphics.Add(CreatePoint(points[0]));
                                break;

                            case GraphicAnnotationSequenceItem.GraphicType.Circle:
                                base.Graphics.Add(CreateCircle(points[0], (float)Vector.Distance(points[0], points[1])));
                                break;

                            case GraphicAnnotationSequenceItem.GraphicType.Ellipse:
                                base.Graphics.Add(CreateEllipse(points[0], points[1], points[2], points[3]));
                                break;

                            default:
                                break;
                            }
                            dataPoints.AddRange(points);
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Warn, ex, "DICOM Softcopy Presentation State Deserialization Fault (Graphic Object Type {0}). Reprocess with log level DEBUG to see DICOM data dump.", graphicItem.GraphicType);
                            Platform.Log(LogLevel.Debug, graphicItem.DicomSequenceItem.Dump());
                        }
                    }
                }

                RectangleF annotationBounds = RectangleF.Empty;
                if (dataPoints.Count > 0)
                {
                    annotationBounds = RectangleUtilities.ComputeBoundingRectangle(dataPoints.ToArray());
                }
                if (graphicAnnotationSequenceItem.TextObjectSequence != null)
                {
                    foreach (GraphicAnnotationSequenceItem.TextObjectSequenceItem textItem in graphicAnnotationSequenceItem.TextObjectSequence)
                    {
                        try
                        {
                            base.Graphics.Add(CreateCalloutText(annotationBounds, displayedArea, textItem));
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Warn, ex, "DICOM Softcopy Presentation State Deserialization Fault (Text Object). Reprocess with log level DEBUG to see DICOM data dump.");
                            Platform.Log(LogLevel.Debug, textItem.DicomSequenceItem.Dump());
                        }
                    }
                }
            }
            finally
            {
                this.ResetCoordinateSystem();
            }

            OnColorChanged();
        }
 protected override void Serialize(XStatefulGraphic graphic, GraphicAnnotationSequenceItem serializationState)
 {
     SerializeGraphic(graphic.Subject, serializationState);
 }
Пример #20
0
 protected override void Serialize(IDecoratorGraphic controlGraphic, GraphicAnnotationSequenceItem serializationState)
 {
     SerializeGraphic(controlGraphic.DecoratedGraphic, serializationState);
 }
 /// <summary>
 /// Serializes the specified 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>
 protected abstract void Serialize(IGraphic graphic, GraphicAnnotationSequenceItem serializationState);