Getting the attributes and bitmaps for all overlays inside a DICOM dataset Example for C#
//LEADDICOM1 is a DICOM Dataset defined outside this method
//This example uses the predefined variable “LEADRasterView1” of type “AxLEADRasterView”
from “LEADTOOLS Toolkit”.
//This example uses the predefined variable “LEADRasterView2” of type “AxLEADRasterView”
from “LEADTOOLS Toolkit”.
private void GettingAttributesAndBitmapsForAllOverlaysInsideDICOMDataset()
{
// 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.
short iRet = 0;
int lOverlayCount = 0;
int lOverlayIndex = 0;
LTRASTERPROCLib.LEADOverlayAttributes OverlayAttributesDS
= null;
LTRASTERPROCLib.LEADOverlayAttributes OverlayAttributesRaster
= null;
LTRASTERPROCLib.LEADRasterProcess RasterProcess = new
LTRASTERPROCLib.LEADRasterProcess();
int GroupNumber = 0;
bool bIsOverlayInDataSet = false;
short iLEADOverlayIndex = 0;
int lFlags = 0;
int crColor = 0;
lOverlayCount = 0;
lOverlayIndex = 0;
GroupNumber = 0;
bIsOverlayInDataSet = false;
iLEADOverlayIndex = 0;
lFlags = 0;
LEADDICOM1.GetBitmapValue(0,
0, (short)LTDICLib.DicomColorOrderConstants.ORDER_BGRORGRAY, 0);
LEADRasterView1.Raster.Bitmap = LEADDICOM1.Bitmap;
// Do we have any overlays at all?
lOverlayCount = LEADDICOM1.OverlayCount;
if (lOverlayCount == 0)
return;
// Go through the overlays one by one
lOverlayIndex = 0;
iLEADOverlayIndex = 0;
// Reset the overlay bitmap
if (LEADRasterView2.Raster.Bitmap > 0)
LEADRasterView2.Raster.Free();
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)
{
MessageBox.Show("error");
return;
}
GroupNumber = LEADDICOM1.get_OverlayGroupNumber(lOverlayIndex,
0);
bIsOverlayInDataSet = LEADDICOM1.IsOverlayInDataSet(lOverlayIndex,
0);
if (bIsOverlayInDataSet == false)
{
lOverlayIndex = lOverlayIndex
+ 1;
goto NEXTINDEX;
}
OverlayAttributesDS = LEADDICOM1.OverlayAttributes;
OverlayAttributesRaster = RasterProcess.OverlayAttributes;
// Auto paint and process overlays
lFlags = OverlayAttributesDS.Flags;
lFlags = lFlags | (int)LTRASTERPROCLib.OverlayAttributesFlagsConstants.OVERLAY_AUTOPAINT
| (int)LTRASTERPROCLib.OverlayAttributesFlagsConstants.OVERLAY_AUTOPROCESS;
OverlayAttributesRaster.Flags = lFlags;
OverlayAttributesRaster.OriginX = OverlayAttributesDS.OriginX;
OverlayAttributesRaster.OriginY = OverlayAttributesDS.OriginY;
crColor = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
OverlayAttributesRaster.Color = System.Convert.ToUInt32(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)
{
MessageBox.Show("error");
return;
}
// Is the overlay embedded inside the
image data ?
lFlags = OverlayAttributesDS.Flags;
if ((lFlags & (int)LTRASTERPROCLib.OverlayAttributesFlagsConstants.OVERLAY_USEBITPLANE)
!= 0)
{
// Add this overlay
to the list of overlays in the bitmap handle
iRet = RasterProcess.SetOverlayAttributes(LEADRasterView1.Raster,
iLEADOverlayIndex, (int)(LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_FLAGS
| LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_BITINDEX
| LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_ORIGIN
| LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_DICOM |
LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_COLOR));
if (iRet != 0)
{
MessageBox.Show("error");
return;
}
// Make sure to extract
the overlay data from the image data
iRet = RasterProcess.UpdateOverlayBits(LEADRasterView1.Raster,
iLEADOverlayIndex, (int)LTRASTERPROCLib.OverlayBitsConstants.SETOVERLAYBITS_FROMBITMAP);
if (iRet != 0)
{
MessageBox.Show("error");
return;
}
// 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, (int)(LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_FLAGS
| LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_ORIGIN
| LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_DICOM |
LTRASTERPROCLib.OverlayAttributesConstants.OVERLAYATTRIBUTES_COLOR));
if (iRet != 0)
{
MessageBox.Show("error");
return;
}
// Get the overlay
bitmap from the overlay data
iRet = LEADDICOM1.GetOverlayBitmap(lOverlayIndex,
0);
if (iRet != 0)
{
MessageBox.Show("error");
return;
}
// store it temp.
in RasterView2
if (LEADRasterView2.Raster.Bitmap
> 0)
LEADRasterView2.Raster.Free();
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, (int)LTRASTERPROCLib.OverlayConstants.OVERLAY_COPY);
if (iRet != 0)
{
MessageBox.Show("error");
return;
}
}
lOverlayIndex = lOverlayIndex + 1;
iLEADOverlayIndex = (short)(iLEADOverlayIndex
+ 1);
}
}