Getting the attributes and bitmaps for all overlays inside a DICOM dataset Example for C++ 6.0 and later

   // 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;
   long lOverlayCount = 0;
   long lOverlayIndex = 0;
   ILEADOverlayAttributesPtr pOverlayAttributesDS = NULL;
   ILEADOverlayAttributesPtr pOverlayAttributesRaster = NULL;
   ILEADRasterProcessPtr pRasterProcess = NULL;
   long GroupNumber = 0;
   BOOL bIsOverlayInDataset = FALSE; 
   short iLEADOverlayIndex = 0;
   long lFlags = 0;
   COLORREF crColor;

   m_pLEADDicomDS->GetBitmapValue (0,0,ORDER_BGRORGRAY,0);
   m_LEADRasterView1.GetRaster().SetBitmap(m_pLEADDicomDS->Bitmap);

   CoCreateInstance(CLSID_LEADRasterProcess,
                    NULL,
                    CLSCTX_ALL,
                    IID_ILEADRasterProcess,
                    (void**)&pRasterProcess);
   pRasterProcess->EnableMethodErrors = FALSE;

   //Do we have any overlays at all?
   lOverlayCount = m_pLEADDicomDS->OverlayCount;
   if(lOverlayCount==0)
      return;

   //Go through the overlays one by one
   lOverlayIndex     = 0;
   iLEADOverlayIndex = 0;
   // Reset the overlay bitmap
   if(m_LEADRasterView2.GetRaster().GetBitmap())
      m_LEADRasterView2.GetRaster().Free();
   m_LEADRasterView2.GetRaster().CreateBitmap(1.0f,1.0f,1);
   while(lOverlayIndex < lOverlayCount)
   {  
      GroupNumber         = 0;
      bIsOverlayInDataset = FALSE; 
      lFlags              = 0;
      // Get the attributes of this overlay
      iRet = m_pLEADDicomDS->GetOverlayAttributes (lOverlayIndex, 0);
      if(iRet != 0)
      {
         AfxMessageBox("error");
         return;
      }
      GroupNumber = m_pLEADDicomDS->GetOverlayGroupNumber(lOverlayIndex, 0);
      bIsOverlayInDataset = m_pLEADDicomDS->IsOverlayInDataSet(lOverlayIndex, 0);

      if(!bIsOverlayInDataset)
      {
         lOverlayIndex++;
         continue;
      }

      pOverlayAttributesDS = m_pLEADDicomDS->GetOverlayAttributes ();
      pOverlayAttributesRaster = pRasterProcess->GetOverlayAttributes ();

      // Auto paint and process overlays
      lFlags = pOverlayAttributesDS->Flags;
      lFlags |= OVERLAY_AUTOPAINT|OVERLAY_AUTOPROCESS;
      pOverlayAttributesRaster->Flags                 = lFlags;
      pOverlayAttributesRaster->OriginX               = pOverlayAttributesDS->OriginX;
      pOverlayAttributesRaster->OriginY               = pOverlayAttributesDS->OriginY;
      crColor = RGB(0xFF,0xFF,0xFF); 
      pOverlayAttributesRaster->Color                 = crColor;
      pOverlayAttributesRaster->BitPosition           = pOverlayAttributesDS->BitPosition;
      pOverlayAttributesRaster->Rows                  = pOverlayAttributesDS->Rows;
      pOverlayAttributesRaster->Columns               = pOverlayAttributesDS->Columns;
      pOverlayAttributesRaster->Type                  = pOverlayAttributesDS->Type;
      pOverlayAttributesRaster->BitsAllocated         = pOverlayAttributesDS->BitsAllocated;
      pOverlayAttributesRaster->Subtype               = pOverlayAttributesDS->Subtype;
      pOverlayAttributesRaster->Label                 = pOverlayAttributesDS->Label;
      pOverlayAttributesRaster->ROIArea               = pOverlayAttributesDS->ROIArea;
      pOverlayAttributesRaster->ROIMean               = pOverlayAttributesDS->ROIMean;
      pOverlayAttributesRaster->ROIStandardDeviation  = pOverlayAttributesDS->ROIStandardDeviation;
      pOverlayAttributesRaster->NumberFramesInOverlay = pOverlayAttributesDS->NumberFramesInOverlay;
      pOverlayAttributesRaster->ImageFrameOrigin      = pOverlayAttributesDS->ImageFrameOrigin;
      pOverlayAttributesRaster->ActivationLayer       = pOverlayAttributesDS->ActivationLayer;
      pOverlayAttributesRaster->Description           = pOverlayAttributesDS->Description;

      iRet = pRasterProcess->SetOverlayAttributes(m_LEADRasterView1.GetRaster(), iLEADOverlayIndex, 0);
      if(iRet != 0)
      {
         AfxMessageBox("error");
         return;
      }

      // Is the overlay embedded inside the image data ?
      lFlags = pOverlayAttributesDS->Flags;
      if(lFlags & OVERLAY_USEBITPLANE)
      {
         // Add this overlay to the list of overlays in the bitmap handle
         iRet = pRasterProcess->SetOverlayAttributes(m_LEADRasterView1.GetRaster(),
                                                     iLEADOverlayIndex, 
                                                     OVERLAYATTRIBUTES_FLAGS    |
                                                     OVERLAYATTRIBUTES_BITINDEX |
                                                     OVERLAYATTRIBUTES_ORIGIN   |
                                                     OVERLAYATTRIBUTES_DICOM    |   
                                                     OVERLAYATTRIBUTES_COLOR);
         if(iRet != 0)
         {
            AfxMessageBox("error");
            return;
         }

         // Make sure to extract the overlay data from the image data
         iRet = pRasterProcess->UpdateOverlayBits(m_LEADRasterView1.GetRaster(),
                                                  iLEADOverlayIndex,
                                                  SETOVERLAYBITS_FROMBITMAP);
         if(iRet != 0)
         {
            AfxMessageBox("error");
            return;
         }
      }
      // The overlay is inside overlay data
      else
      {         
         // Add this overlay to the list of overlays in the bitmap handle
         iRet = pRasterProcess->SetOverlayAttributes(m_LEADRasterView1.GetRaster(),
                                                     iLEADOverlayIndex,
                                                     OVERLAYATTRIBUTES_FLAGS    |                                       
                                                     OVERLAYATTRIBUTES_ORIGIN   |
                                                     OVERLAYATTRIBUTES_DICOM    |   
                                                     OVERLAYATTRIBUTES_COLOR);
         if(iRet != 0)
         {
            AfxMessageBox("error");
            return;
         }

         // Get the overlay bitmap from the overlay data
         iRet = m_pLEADDicomDS->GetOverlayBitmap (lOverlayIndex, 0);
         if(iRet != 0)
         {
            AfxMessageBox("error");
            return;
         }
         //store it temp. in RasterView2
         if(m_LEADRasterView2.GetRaster().GetBitmap())
            m_LEADRasterView2.GetRaster().Free();
         m_LEADRasterView2.GetRaster().SetBitmap(m_pLEADDicomDS->OverlayBitmap);

         // Set the bitmap for this overlay inside the 
         // list of overlays we have in the bitmap handle

         iRet = pRasterProcess->SetOverlayBitmap (m_LEADRasterView1.GetRaster(),
                                                 iLEADOverlayIndex,
                                                 m_LEADRasterView2.GetRaster(),
                                                 OVERLAY_COPY);
         if(iRet != 0)
         {
            AfxMessageBox("error");
            return;
         }
      } 
      lOverlayIndex++;
      iLEADOverlayIndex++;
   }  
   return;