LEADTOOLS Medical
LEAD Technologies, Inc

FromAnnContainerToDataSet Method

Example 





The Leadtools.Dicom.DicomDataSet where the resulting DICOM Annotation objects are stored.
The Leadtools.Annotations.Core.AnnContainer that contains a list of Leadtools.Annotations.Core.AnnObject objects that are to be converted.
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
public DicomElement FromAnnContainerToDataSet( 
   DicomDataSet ds,
   AnnContainer annContainer
)
'Declaration
 
Public Function FromAnnContainerToDataSet( _
   ByVal ds As DicomDataSet, _
   ByVal annContainer As AnnContainer _
) As DicomElement
'Usage
 
Dim instance As DicomAnnotationsUtilities
Dim ds As DicomDataSet
Dim annContainer As AnnContainer
Dim value As DicomElement
 
value = instance.FromAnnContainerToDataSet(ds, annContainer)
public DicomElement FromAnnContainerToDataSet( 
   DicomDataSet ds,
   AnnContainer annContainer
)
 function Leadtools.Dicom.Annotations.Core.DicomAnnotationsUtilities.FromAnnContainerToDataSet( 
   ds ,
   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.Core.AnnContainer that contains a list of Leadtools.Annotations.Core.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.Core.AnnContainer of Leadtools.Annotations.Core.AnnObject objects into one or more DICOM annotation objects (text, graphic, and compound graphic), and stores the result in 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.Core.AnnPolyRulerObject, Leadtools.Annotations.Core.AnnProtractorObject, or Leadtools.Annotations.Core.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 %%
Example
 
Private Sub DicomAnnotationsUtilities_FromAnnContainerToDataSet(ByVal dsImage As DicomDataSet, ByVal outfilePresentationState As String)
   ' Create an AnnRectangleObject (rotated, filled)
   Dim rectangleObject As 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
   Dim pointerObject As New AnnPointerObject()
   pointerObject.Stroke.Stroke = AnnSolidColorBrush.Create("red")
   pointerObject.Points.Clear()
   pointerObject.Points.Add(GetLeadPointD(300, 100))
   pointerObject.Points.Add(GetLeadPointD(400, 200))
   pointerObject.PointerPosition = AnnPointerPosition.End

   ' Create a ruler object
   Dim polyRulerObject As 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
   Dim annContainer As New AnnContainer()
   annContainer.Mapper = New AnnContainerMapper(96, 96, 96, 96)
   annContainer.Children.Add(rectangleObject)
   annContainer.Children.Add(pointerObject)
   annContainer.Children.Add(polyRulerObject)

   ' Create a DicomDataSet
   Dim dsPS As New DicomDataSet()
   dsPS.Initialize(DicomClassType.GrayscaleSoftcopyPresentationState, DicomDataSetInitializeFlags.AddMandatoryModulesOnly Or DicomDataSetInitializeFlags.AddMandatoryElementsOnly)

   ' Delete the empty referenced Series Sequence
   Dim referencedSeriesSequence As DicomElement = dsPS.FindFirstElement(Nothing, DicomTag.ReferencedSeriesSequence, True)
   If referencedSeriesSequence IsNot Nothing Then
      dsPS.DeleteElement(referencedSeriesSequence)
   End If

   ' Add a new Referenced Series Sequence
   dsPS.AddPresentationStateImageReference(dsImage, Nothing, 0)

   ' Set up the DicomAnnotationsUtilities converter
   Dim du As 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"

   AddHandler du.OnIncrementGraphicGroupId, AddressOf du_OnIncrementGraphicGroupId
   AddHandler du.OnIncrementCompoundGraphicInstanceId, AddressOf du_OnIncrementCompoundGraphicInstanceId


   ' Convert LEAD annotations to DICOM annotations
   Dim graphicAnnSequenceItem As DicomElement = 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
   Dim annContainerNew As AnnContainer = du.FromDataSetToAnnContainer(dsPS, graphicAnnSequenceItem)

   ' There should be three objects
   Debug.Assert(annContainerNew.Children.Count = 3)

   MessageBox.Show("Presentation State Saved: " & outfilePresentationState)
End Sub

Private Function GetLeadPointD(ByVal x As Double, ByVal y As Double) As LeadPointD
   Dim imageDpi As Double = 96.0
   Return New LeadPointD(x * 720.0 / imageDpi, y * 720.0 / imageDpi)
End Function

' Override the default behavior of IncrementGraphicGroupId
Private Sub du_OnIncrementGraphicGroupId(ByVal sender As Object, ByVal e As EventArgs)
   Dim du As DicomAnnotationsUtilities = TryCast(sender, DicomAnnotationsUtilities)
   If du IsNot Nothing Then
      du.GraphicGroupId = du.GraphicGroupId + 2
   End If
End Sub

' Override the default behavior of IncrementGraphicInstanceId
Private Sub du_OnIncrementCompoundGraphicInstanceId(ByVal sender As Object, ByVal e As EventArgs)
   Dim du As DicomAnnotationsUtilities = TryCast(sender, DicomAnnotationsUtilities)
   If du IsNot Nothing Then
      du.CompoundGraphicInstanceId = du.CompoundGraphicInstanceId + 10
   End If
End Sub
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
  AnnPointerObject pointerObject = new AnnPointerObject();
  pointerObject.Stroke.Stroke = AnnSolidColorBrush.Create("red");
  pointerObject.Points.Clear();
  pointerObject.Points.Add(GetLeadPointD(300, 100));
  pointerObject.Points.Add(GetLeadPointD(400,200));
  pointerObject.PointerPosition = AnnPointerPosition.End;

  // 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(pointerObject);
  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);

  // There should be three objects
  Debug.Assert(annContainerNew.Children.Count == 3);

  MessageBox.Show("Presentation State Saved: " + outfilePresentationState);
}

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: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DicomAnnotationsUtilities Class
DicomAnnotationsUtilities Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Dicom.Annotations.Core requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features