Converts all of the Graphic Annotation Sequence (DICOM Annotations) stored in a Leadtools.Dicom.DicomDataSet into a LEAD AnnContainer that contains LEAD Leadtools.Annotations.Engine.AnnObject objects.
public AnnContainer FromDataSetToAnnContainer(DicomDataSet ds,DicomElement graphicAnnSqItem)
ds
The Leadtools.Dicom.DicomDataSet that contains the Graphic Annotation Sequence (DICOM Annotations) being converted.
graphicAnnSqItem
Pointer to an item element under the "Graphic Annotation Sequence" (0070,0001) in the "Graphic Annotation Module".
A LEAD Leadtools.Annotations.Engine.AnnContainer that contains LEAD Leadtools.Annotations.Engine.AnnObject.
This method takes Leadtools.Dicom.DicomDataSet as input, and converts all of the DICOM annotations stored in the Graphic Annotation Sequence into LEAD annotations. The LEAD annotations are returned as a Leadtools.Annotations.Engine.AnnContainer. Note that this method preserves any ruler calibrations, as the ruler calibration is stored in the Leadtools.Annotations.Engine.AnnContainer.
using Leadtools;using Leadtools.Dicom;using Leadtools.Dicom.Annotations;using Leadtools.Annotations;using Leadtools.Annotations.Engine;private void DicomAnnotationsUtilities_FromAnnContainerToDataSet(DicomDataSet dsImage, string outfilePresentationState){// Create an AnnRectangleObject (rotated, filled)AnnRectangleObject rectangleObject = new AnnRectangleObject();rectangleObject.Stroke.Stroke = AnnSolidColorBrush.Create("red");rectangleObject.Fill = AnnSolidColorBrush.Create("blue");rectangleObject.Points.Add(GetLeadPointD(100, 100));rectangleObject.Points.Add(GetLeadPointD(200, 100));rectangleObject.Points.Add(GetLeadPointD(200, 200));rectangleObject.Points.Add(GetLeadPointD(100, 200));rectangleObject.Rotate(45.0, GetLeadPointD(150, 150));// Create a pointer objectAnnPolylineObject polylineObject = new AnnPolylineObject();polylineObject.Stroke.Stroke = AnnSolidColorBrush.Create("red");polylineObject.Points.Clear();polylineObject.Points.Add(GetLeadPointD(300, 100));polylineObject.Points.Add(GetLeadPointD(400, 200));// Create a ruler objectAnnPolyRulerObject polyRulerObject = new AnnPolyRulerObject();polyRulerObject.Stroke.Stroke = AnnSolidColorBrush.Create("green");polyRulerObject.Points.Add(GetLeadPointD(100, 300));polyRulerObject.Points.Add(GetLeadPointD(200, 400));polyRulerObject.Points.Add(GetLeadPointD(300, 300));// Add them to the AnnContainerAnnContainer annContainer = new AnnContainer();annContainer.Mapper = new AnnContainerMapper(96, 96, 96, 96);annContainer.Children.Add(rectangleObject);annContainer.Children.Add(polylineObject);annContainer.Children.Add(polyRulerObject);// Create a DicomDataSetDicomDataSet dsPS = new DicomDataSet();dsPS.Initialize(DicomClassType.GrayscaleSoftcopyPresentationState, DicomDataSetInitializeFlags.AddMandatoryModulesOnly | DicomDataSetInitializeFlags.AddMandatoryElementsOnly);// Delete the empty referenced Series SequenceDicomElement referencedSeriesSequence = dsPS.FindFirstElement(null, DicomTag.ReferencedSeriesSequence, true);if (referencedSeriesSequence != null){dsPS.DeleteElement(referencedSeriesSequence);}// Add a new Referenced Series SequencedsPS.AddPresentationStateImageReference(dsImage, null, 0);// Set up the DicomAnnotationsUtilities converterDicomAnnotationsUtilities du = new DicomAnnotationsUtilities();du.ContainerMapper = annContainer.Mapper;du.DefaultObject = new DicomTextObject();du.ImageDpiX = 96.0;du.ImageDpiY = 96.0;du.DisplayWidth = 200;du.DisplayHeight = 200;du.LayerName = "Layer 0";du.OnIncrementGraphicGroupId += new EventHandler(du_OnIncrementGraphicGroupId);du.OnIncrementCompoundGraphicInstanceId += new EventHandler(du_OnIncrementCompoundGraphicInstanceId);// Convert LEAD annotations to DICOM annotationsDicomElement graphicAnnSequenceItem = du.FromAnnContainerToDataSet(dsPS, annContainer);// Save the presentation statedsPS.Save(outfilePresentationState, DicomDataSetSaveFlags.None);// Now you can convert the presentation state dataset back to an AnnContainerAnnContainer annContainerNew = du.FromDataSetToAnnContainer(dsPS, graphicAnnSequenceItem);Console.WriteLine("Presentation State Saved: " + outfilePresentationState);// There should be three objectsAssert.IsTrue(annContainerNew.Children.Count == 3, $"There should be three objects, but there are {annContainerNew.Children.Count}");}LeadPointD GetLeadPointD(double x, double y){double imageDpi = 96.0;return new LeadPointD(x * 720.0 / imageDpi, y * 720.0 / imageDpi);}// Override the default behavior of IncrementGraphicGroupIdvoid du_OnIncrementGraphicGroupId(object sender, EventArgs e){DicomAnnotationsUtilities du = sender as DicomAnnotationsUtilities;if (du != null){du.GraphicGroupId = du.GraphicGroupId + 2;}}// Override the default behavior of IncrementGraphicInstanceIdvoid du_OnIncrementCompoundGraphicInstanceId(object sender, EventArgs e){DicomAnnotationsUtilities du = sender as DicomAnnotationsUtilities;if (du != null){du.CompoundGraphicInstanceId = du.CompoundGraphicInstanceId + 10;}}