Getting the attributes and bitmaps for all overlays inside a DICOM dataset Example for Visual Basic
' This example will extract the overlays from a
' DICOM dataset and associate them with a bitmap,
' the bitmap is assumed to be extracted from the
' same DICOM dataset.
Dim iRet As Integer
Dim lOverlayCount As Long
Dim lOverlayIndex As Long
Dim OverlayAttributesDS As LEADOverlayAttributes
Dim OverlayAttributesRaster As LEADOverlayAttributes
Dim RasterProcess As New LEADRasterProcess
Dim GroupNumber As Long
Dim bIsOverlayInDataSet As Boolean
Dim iLEADOverlayIndex As Integer
Dim lFlags As Long
Dim crColor As Long
lOverlayCount = 0
lOverlayIndex = 0
GroupNumber = 0
bIsOverlayInDataSet = False
iLEADOverlayIndex = 0
lFlags = 0
LEADDICOM1.GetBitmapValue 0, 0, ORDER_BGRORGRAY, 0
LEADRasterView1.Raster.Bitmap = LEADDICOM1.Bitmap
' Do we have any overlays at all?
lOverlayCount = LEADDICOM1.OverlayCount
If (lOverlayCount = 0) Then
Exit Sub
End If
' Go through the overlays one by one
lOverlayIndex = 0
iLEADOverlayIndex = 0
' Reset the overlay bitmap
If (LEADRasterView2.Raster.Bitmap > 0) Then
LEADRasterView2.Raster.Free
End If
LEADRasterView2.Raster.CreateBitmap 1, 1, 1
While (lOverlayIndex < lOverlayCount)
NEXTINDEX:
GroupNumber = 0
bIsOverlayInDataSet = False
lFlags = 0
' Get the attributes of this overlay
iRet = LEADDICOM1.GetOverlayAttributes (lOverlayIndex, 0)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
GroupNumber = LEADDICOM1.OverlayGroupNumber(lOverlayIndex, 0)
bIsOverlayInDataSet = LEADDICOM1.IsOverlayInDataset(lOverlayIndex, 0)
If (bIsOverlayInDataSet = False) Then
lOverlayIndex = lOverlayIndex + 1
GoTo NEXTINDEX
End If
Set OverlayAttributesDS = LEADDICOM1.OverlayAttributes
Set OverlayAttributesRaster = RasterProcess.OverlayAttributes
' Auto paint and process overlays
lFlags = OverlayAttributesDS.Flags
lFlags = lFlags Or OVERLAY_AUTOPAINT Or OVERLAY_AUTOPROCESS
OverlayAttributesRaster.Flags = lFlags
OverlayAttributesRaster.OriginX = OverlayAttributesDS.OriginX
OverlayAttributesRaster.OriginY = OverlayAttributesDS.OriginY
crColor = vbWhite
OverlayAttributesRaster.Color = crColor
OverlayAttributesRaster.BitPosition = OverlayAttributesDS.BitPosition
OverlayAttributesRaster.Rows = OverlayAttributesDS.Rows
OverlayAttributesRaster.Columns = OverlayAttributesDS.Columns
OverlayAttributesRaster.Type = OverlayAttributesDS.Type
OverlayAttributesRaster.BitsAllocated = OverlayAttributesDS.BitsAllocated
OverlayAttributesRaster.Subtype = OverlayAttributesDS.Subtype
OverlayAttributesRaster.Label= OverlayAttributesDS.Label
OverlayAttributesRaster.ROIArea = OverlayAttributesDS.ROIArea
OverlayAttributesRaster.ROIMean = OverlayAttributesDS.ROIMean
OverlayAttributesRaster.ROIStandardDeviation = OverlayAttributesDS.ROIStandardDeviation
OverlayAttributesRaster.NumberFramesInOverlay = OverlayAttributesDS.NumberFramesInOverlay
OverlayAttributesRaster.ImageFrameOrigin= OverlayAttributesDS.ImageFrameOrigin
OverlayAttributesRaster.ActivationLayer = OverlayAttributesDS.ActivationLayer
OverlayAttributesRaster.Description = OverlayAttributesDS.Description
iRet = RasterProcess.SetOverlayAttributes (LEADRasterView1.Raster, iLEADOverlayIndex, 0)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
' Is the overlay embedded inside the image data ?
lFlags = OverlayAttributesDS.Flags
If (lFlags And OVERLAY_USEBITPLANE) Then
' Add this overlay to the list of overlays in the bitmap handle
iRet = RasterProcess.SetOverlayAttributes (LEADRasterView1.Raster, _
iLEADOverlayIndex, _
OVERLAYATTRIBUTES_FLAGS Or _
OVERLAYATTRIBUTES_BITINDEX Or _
OVERLAYATTRIBUTES_ORIGIN Or _
OVERLAYATTRIBUTES_DICOM Or _
OVERLAYATTRIBUTES_COLOR)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
' Make sure to extract the overlay data from the image data
iRet = RasterProcess.UpdateOverlayBits(LEADRasterView1.Raster, _
iLEADOverlayIndex, _
SETOVERLAYBITS_FROMBITMAP)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
' The overlay is inside overlay data
Else
' Add this overlay to the list of overlays in the bitmap handle
iRet = RasterProcess.SetOverlayAttributes (LEADRasterView1.Raster, _
iLEADOverlayIndex, _
OVERLAYATTRIBUTES_FLAGS Or _
OVERLAYATTRIBUTES_ORIGIN Or _
OVERLAYATTRIBUTES_DICOM Or _
OVERLAYATTRIBUTES_COLOR)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
' Get the overlay bitmap from the overlay data
iRet = LEADDICOM1.GetOverlayBitmap (lOverlayIndex, 0)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
' store it temp. in RasterView2
If (LEADRasterView2.Raster.Bitmap > 0) Then
LEADRasterView2.Raster.Free
End If
LEADRasterView2.Raster.Bitmap = LEADDICOM1.OverlayBitmap
' Set the bitmap for this overlay inside the
' list of overlays we have in the bitmap handle
iRet = RasterProcess.SetOverlayBitmap (LEADRasterView1.Raster, _
iLEADOverlayIndex, _
LEADRasterView2.Raster, _
OVERLAY_COPY)
If (iRet <> 0) Then
MsgBox "error"
Exit Sub
End If
End If
lOverlayIndex = lOverlayIndex + 1
iLEADOverlayIndex = iLEADOverlayIndex + 1
Wend