FromAnnContainerToDataSet(DicomDataSet,AnnContainer) Method

Summary

Converts all the LEAD Annotation objects in an AnnContainer into one or more DICOM annotation objects, and stores the result in a Leadtools.Dicom.DicomDataSet.

Syntax
C#
C++/CLI
public DicomElement FromAnnContainerToDataSet( 
   DicomDataSet ds, 
   AnnContainer annContainer 
) 
public: 
DicomElement^ FromAnnContainerToDataSet(  
   DicomDataSet^ ds, 
   AnnContainer^ annContainer 
)  

Parameters

ds
The Leadtools.Dicom.DicomDataSet where the resulting DICOM Annotation objects are stored.

annContainer
The Leadtools.Annotations.Engine.AnnContainer that contains a list of Leadtools.Annotations.Engine.AnnObject objects that are to be converted.

Return Value

A Leadtools.Dicom.DicomElement that represents GraphicAnnotationSequence item that contains the DICOM Annotations.

Remarks

This function converts a LEAD Leadtools.Annotations.Engine.AnnContainer of Leadtools.Annotations.Engine.AnnObject objects into one or more DICOM annotation objects (text, graphic, and compound graphic), and stores the result in a new Graphic Annotation Sequence Item Element inside the ds parameter.

If any of the resulting DICOM annotation object is a "Compound Graphic " then it will be added under the "Compound Graphic Sequence" and for backward compatibility (as per the DICOM Specification) it will also be added under the "Graphic Object Sequence".

If the resulting DICOM annotation object is a "Text Object" then it will be added under the "Text Object Sequence".

If the resulting DICOM annotation object is a "Graphic Object" then it will be added under the "Graphic Object Sequence".

Note: when converting a Leadtools.Annotations.Engine.AnnPolyRulerObject, Leadtools.Annotations.Engine.AnnProtractorObject, or Leadtools.Annotations.Engine.AnnCrossProductObject, the result will be one or more 'grouped' Leadtools.Dicom.DicomAnnotationObject objects which have the same Leadtools.Dicom.DicomAnnotationObject.GraphicGroupId. In this case, a corresponding Graphic Group Sequence item (0070,0234) will be inserted into the ds.

Example

This example does the following:

  1. Creates a Leadtools.Annotations.Engine.AnnRectangleObject, a Leadtools.Annotations.Engine.AnnPolylineObject, and a Leadtools.Annotations.Engine.AnnPolyRulerObject.
  2. Creates an Leadtools.Annotations.Engine.AnnContainer and adds the three objects
  3. Creates a converter
  4. Converts the Leadtools.Annotations.Engine.AnnContainer to DICOM Annotations, and stores the result in a file that contains a Grayscale Softcopy Presentation
C#
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 object 
   AnnPolylineObject 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 object 
   AnnPolyRulerObject 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 AnnContainer 
   AnnContainer 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 DicomDataSet 
   DicomDataSet dsPS = new DicomDataSet(); 
   dsPS.Initialize(DicomClassType.GrayscaleSoftcopyPresentationState, DicomDataSetInitializeFlags.AddMandatoryModulesOnly | DicomDataSetInitializeFlags.AddMandatoryElementsOnly); 
 
   // Delete the empty referenced Series Sequence 
   DicomElement referencedSeriesSequence = dsPS.FindFirstElement(null, DicomTag.ReferencedSeriesSequence, true); 
   if (referencedSeriesSequence != null) 
   { 
      dsPS.DeleteElement(referencedSeriesSequence); 
   } 
 
   // Add a new Referenced Series Sequence 
   dsPS.AddPresentationStateImageReference(dsImage, null, 0); 
 
   // Set up the DicomAnnotationsUtilities converter 
   DicomAnnotationsUtilities 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 annotations 
   DicomElement graphicAnnSequenceItem = du.FromAnnContainerToDataSet(dsPS, annContainer); 
 
   // Save the presentation state 
   dsPS.Save(outfilePresentationState, DicomDataSetSaveFlags.None); 
 
   // Now you can convert the presentation state dataset back to an AnnContainer 
   AnnContainer annContainerNew = du.FromDataSetToAnnContainer(dsPS, graphicAnnSequenceItem); 
 
   Console.WriteLine("Presentation State Saved: " + outfilePresentationState); 
 
   // There should be three objects 
   Assert.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 IncrementGraphicGroupId 
void du_OnIncrementGraphicGroupId(object sender, EventArgs e) 
{ 
   DicomAnnotationsUtilities du = sender as DicomAnnotationsUtilities; 
   if (du != null) 
   { 
      du.GraphicGroupId = du.GraphicGroupId + 2; 
   } 
} 
 
// Override the default behavior of IncrementGraphicInstanceId 
void du_OnIncrementCompoundGraphicInstanceId(object sender, EventArgs e) 
{ 
   DicomAnnotationsUtilities du = sender as DicomAnnotationsUtilities; 
   if (du != null) 
   { 
      du.CompoundGraphicInstanceId = du.CompoundGraphicInstanceId + 10; 
   } 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom.Annotations Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.