LEADTOOLS Medical (Leadtools.Dicom assembly)
LEAD Technologies, Inc

CreateLayer Method

Example 







A Graphic Layer attributes , which holds the attributes of the layer to be created.
Adds a new item under the "Graphic Layer Sequence" (0070,0060) in the Graphic Layer Module". .NET support WinRT support Silverlight support
Syntax
public int CreateLayer( 
   DicomGraphicLayer graphicLayer
)
'Declaration
 
Public Function CreateLayer( _
   ByVal graphicLayer As DicomGraphicLayer _
) As Integer
'Usage
 
Dim instance As DicomDataSet
Dim graphicLayer As DicomGraphicLayer
Dim value As Integer
 
value = instance.CreateLayer(graphicLayer)
public int CreateLayer( 
   DicomGraphicLayer graphicLayer
)
ObjectiveC Syntax
 function Leadtools.Dicom.DicomDataSet.CreateLayer( 
   graphicLayer 
)
public:
int CreateLayer( 
   DicomGraphicLayer^ graphicLayer
) 

Parameters

graphicLayer
A Graphic Layer attributes , which holds the attributes of the layer to be created.

Return Value

The index of the newly created layer.
Remarks
If for example there are already 2 items under the "Graphic Layer Sequence" (0070,0060) and we call this method, then the index of the new layer will be 2.

This method will fail and throw a DicomExceptionCode.Parameter exception if a layer with the same name as the new layer already exists in the Data Set.

Example
Copy CodeCopy Code  
Public Sub DicomLayerSample()
      'Make sure to initialize the DICOM engine, this needs to be done only once 
      'In the whole application
      DicomEngine.Startup()

      Dim dicomDataset As DicomDataSet = New DicomDataSet()
      Using (dicomDataset)
         ' We can also initialize in here the "Grayscale Softcopy Presentation State" class
         dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian)

         'We can remove individual layers by calling RemoveLayerByIndex and RemoveLayerByName
         dicomDataset.RemoveAllLayers(True)

         Dim graphicLayer As DicomGraphicLayer = New DicomGraphicLayer()

         graphicLayer.LayerOrder = 1
         graphicLayer.LayerDescription = "First Layer"
         graphicLayer.LayerName = "LAYER0"
         graphicLayer.Grayscale = 0
         graphicLayer.RgbLayerColor = 255

         dicomDataset.CreateLayer(graphicLayer)

         Debug.Assert(dicomDataset.GetLayerIndex("LAYER0") = 0)

         Dim graphicLayer1 As DicomGraphicLayer = dicomDataset.GetLayerInformation(0)
         Debug.Assert(Not graphicLayer1 Is Nothing)
         Debug.Assert(graphicLayer1.LayerOrder = 1)

         graphicLayer.LayerName = "LAYER1"
         dicomDataset.SetLayerInformation(0, graphicLayer)

         Debug.Assert(dicomDataset.LayerCount = 1)

         '  We can also call GetLayerElementByName to get the layer elemnt
         Dim layer As DicomElement = dicomDataset.GetLayerElementByIndex(0)
         Debug.Assert(Not layer Is Nothing)

         dicomDataset.RemoveLayerGraphicObjects(layer)
         Debug.Assert(dicomDataset.GetLayerGraphicObjectCount(layer) = 0)

         dicomDataset.RemoveLayerTextObjects(layer)
         Debug.Assert(dicomDataset.GetLayerTextObjectCount(layer) = 0)

         dicomDataset.Save(Path.Combine(LEAD_VARS.ImagesDir, "PresentationState.dcm"), DicomDataSetSaveFlags.None)
      End Using

      DicomEngine.Shutdown()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void DicomLayerSample()
   {
      //Make sure to initialize the DICOM engine, this needs to be done only once 
      //In the whole application
      DicomEngine.Startup();
      using (DicomDataSet dicomDataset = new DicomDataSet())
      {
         // We can also initialize in here the "Grayscale Softcopy Presentation State" class
         dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian);

         //We can remove individual layers by calling RemoveLayerByIndex and RemoveLayerByName
         dicomDataset.RemoveAllLayers(true);

         DicomGraphicLayer graphicLayer = new DicomGraphicLayer();

         graphicLayer.LayerOrder = 1;
         graphicLayer.LayerDescription = "First Layer";
         graphicLayer.LayerName = "LAYER0";
         graphicLayer.Grayscale = 0;
         graphicLayer.RgbLayerColor = 255;

         dicomDataset.CreateLayer(graphicLayer);

         Debug.Assert(dicomDataset.GetLayerIndex("LAYER0") == 0);

         DicomGraphicLayer graphicLayer1 = dicomDataset.GetLayerInformation(0);
         Debug.Assert(graphicLayer1 != null);
         Debug.Assert(graphicLayer1.LayerOrder == 1);

         graphicLayer.LayerName = "LAYER1";
         dicomDataset.SetLayerInformation(0, graphicLayer);

         Debug.Assert(dicomDataset.LayerCount == 1);

         //  We can also call GetLayerElementByName to get the layer elemnt
         DicomElement layer = dicomDataset.GetLayerElementByIndex(0);
         Debug.Assert(layer != null);

         dicomDataset.RemoveLayerGraphicObjects(layer);
         Debug.Assert(dicomDataset.GetLayerGraphicObjectCount(layer) == 0);

         dicomDataset.RemoveLayerTextObjects(layer);
         Debug.Assert(dicomDataset.GetLayerTextObjectCount(layer) == 0);

         dicomDataset.Save(Path.Combine(LEAD_VARS.ImagesDir, "PresentationState.dcm"), DicomDataSetSaveFlags.None);
      }
      DicomEngine.Shutdown();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async void DicomLayerSample()
{
   //Make sure to initialize the DICOM engine, this needs to be done only once 
   //In the whole application
   DicomEngine.Startup();
   using (DicomDataSet dicomDataset = new DicomDataSet())
   {
      // We can also initialize in here the "Grayscale Softcopy Presentation State" class
      dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian);
      //We can remove individual layers by calling RemoveLayerByIndex and RemoveLayerByName
      dicomDataset.RemoveAllLayers(true);

      DicomGraphicLayer graphicLayer = new DicomGraphicLayer();

      graphicLayer.LayerOrder = 1;
      graphicLayer.LayerDescription = "First Layer";
      graphicLayer.LayerName = "LAYER0";
      graphicLayer.Grayscale = 0;
      graphicLayer.RgbLayerColor = 255;

      dicomDataset.CreateLayer(graphicLayer);

      Debug.Assert(dicomDataset.GetLayerIndex("LAYER0") == 0);

      DicomGraphicLayer graphicLayer1 = dicomDataset.GetLayerInformation(0);
      Debug.Assert(graphicLayer1 != null);
      Debug.Assert(graphicLayer1.LayerOrder == 1);

      graphicLayer.LayerName = "LAYER1";
      dicomDataset.SetLayerInformation(0, graphicLayer);

      Debug.Assert(dicomDataset.LayerCount == 1);

      //  We can also call GetLayerElementByName to get the layer elemnt
      DicomElement layer = dicomDataset.GetLayerElementByIndex(0);
      Debug.Assert(layer != null);

      dicomDataset.RemoveLayerGraphicObjects(layer);
      Debug.Assert(dicomDataset.GetLayerGraphicObjectCount(layer) == 0);

      dicomDataset.RemoveLayerTextObjects(layer);
      Debug.Assert(dicomDataset.GetLayerTextObjectCount(layer) == 0);

      string dicomFileNameOutput = "PresentationState.dcm";
      StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(dicomFileNameOutput);
      ILeadStream streamOutput = LeadStreamFactory.Create(saveFile);
      using (IDisposable disposableOUT = streamOutput as IDisposable)
      {
         await dicomDataset.SaveAsync(streamOutput, DicomDataSetSaveFlags.None);
      }
   }
   DicomEngine.Shutdown();
}
public void DicomLayerSample(Stream outputStream)
{
   //Make sure to initialize the DICOM engine, this needs to be done only once 
   //In the whole application
   DicomEngine.Startup();
   using (DicomDataSet dicomDataset = new DicomDataSet())
   {
      // We can also initialize in here the "Grayscale Softcopy Presentation State" class
      dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian);
      //We can remove individual layers by calling RemoveLayerByIndex and RemoveLayerByName
      dicomDataset.RemoveAllLayers(true);

      DicomGraphicLayer graphicLayer = new DicomGraphicLayer();

      graphicLayer.LayerOrder = 1;
      graphicLayer.LayerDescription = "First Layer";
      graphicLayer.LayerName = "LAYER0";
      graphicLayer.Grayscale = 0;
      graphicLayer.RgbLayerColor = 255;

      dicomDataset.CreateLayer(graphicLayer);

      Debug.Assert(dicomDataset.GetLayerIndex("LAYER0") == 0);

      DicomGraphicLayer graphicLayer1 = dicomDataset.GetLayerInformation(0);
      Debug.Assert(graphicLayer1 != null);
      Debug.Assert(graphicLayer1.LayerOrder == 1);

      graphicLayer.LayerName = "LAYER1";
      dicomDataset.SetLayerInformation(0, graphicLayer);

      Debug.Assert(dicomDataset.LayerCount == 1);

      //  We can also call GetLayerElementByName to get the layer elemnt
      DicomElement layer = dicomDataset.GetLayerElementByIndex(0);
      Debug.Assert(layer != null);

      dicomDataset.RemoveLayerGraphicObjects(layer);
      Debug.Assert(dicomDataset.GetLayerGraphicObjectCount(layer) == 0);

      dicomDataset.RemoveLayerTextObjects(layer);
      Debug.Assert(dicomDataset.GetLayerTextObjectCount(layer) == 0);

      dicomDataset.Save(outputStream, DicomDataSetSaveFlags.None);
   }
   DicomEngine.Shutdown();
}
Public Sub DicomLayerSample(ByVal outputStream As Stream)
   'Make sure to initialize the DICOM engine, this needs to be done only once 
   'In the whole application
   DicomEngine.Startup()
   Using dicomDataset As DicomDataSet = New DicomDataSet()
      ' We can also initialize in here the "Grayscale Softcopy Presentation State" class
      dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian)
      'We can remove individual layers by calling RemoveLayerByIndex and RemoveLayerByName
      dicomDataset.RemoveAllLayers(True)

      Dim graphicLayer As DicomGraphicLayer = New DicomGraphicLayer()

      graphicLayer.LayerOrder = 1
      graphicLayer.LayerDescription = "First Layer"
      graphicLayer.LayerName = "LAYER0"
      graphicLayer.Grayscale = 0
      graphicLayer.RgbLayerColor = 255

      dicomDataset.CreateLayer(graphicLayer)

      Debug.Assert(dicomDataset.GetLayerIndex("LAYER0") = 0)

      Dim graphicLayer1 As DicomGraphicLayer = dicomDataset.GetLayerInformation(0)
      Debug.Assert(Not graphicLayer1 Is Nothing)
      Debug.Assert(graphicLayer1.LayerOrder = 1)

      graphicLayer.LayerName = "LAYER1"
      dicomDataset.SetLayerInformation(0, graphicLayer)

      Debug.Assert(dicomDataset.LayerCount = 1)

      '  We can also call GetLayerElementByName to get the layer elemnt
      Dim layer As DicomElement = dicomDataset.GetLayerElementByIndex(0)
      Debug.Assert(Not layer Is Nothing)

      dicomDataset.RemoveLayerGraphicObjects(layer)
      Debug.Assert(dicomDataset.GetLayerGraphicObjectCount(layer) = 0)

      dicomDataset.RemoveLayerTextObjects(layer)
      Debug.Assert(dicomDataset.GetLayerTextObjectCount(layer) = 0)

      dicomDataset.Save(outputStream, DicomDataSetSaveFlags.None)
   End Using
   DicomEngine.Shutdown()
End Sub
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

DicomDataSet Class
DicomDataSet Members
GetLayerInformation Method
SetLayerInformation Method
RemoveLayerByIndex Method
RemoveLayerByName Method
RemoveAllLayers Method
LayerCount Property
GetLayerIndex Method
GetLayerGraphicObjectCount Method
RemoveLayerGraphicObjects Method
GetLayerTextObjectCount Method
RemoveLayerTextObjects Method
GetLayerElementByIndex Method
GetLayerElementByName Method

 

 


Products | Support | Contact Us | Copyright Notices

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

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