Converting LEAD Annotation Objects to DICOM Annotation Objects Example for C#

//This example uses the predefined variable “objPresState” of type “LEADDicomDS” from “"LEADTOOLS Toolkit”.
private void objPresState_OnConvertLEADAnnObjToDicomAnnObj(bool bGraphicObject)
{
   string sMsg = null;

   // Display the attributes of the resulted DICOM annotation object int lCount = 0;
   int I = 0;
   if (bGraphicObject)    // The resulted DICOM annotation object is a graphic object
   {
      sMsg = "Graphic Annotation Units: ";
      switch ( objPresState.GraphicObjectAttributes.Units )
      {
      case LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL:
            sMsg = sMsg + "PIXEL" + System.Environment.NewLine;
            break;
      case LTDICLib.DicomMeasureUnits.DICOM_UNIT_DISPLAY:
            sMsg = sMsg + "DISPLAY" + System.Environment.NewLine;
            break;
      }
      sMsg = sMsg + "Graphic Type: ";
      switch ( objPresState.GraphicObjectAttributes.Type )
      {
         case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_POINT:
               sMsg = sMsg + "POINT" + System.Environment.NewLine;
               break;
         case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_POLYLINE:
               sMsg = sMsg + "POLYLINE" + System.Environment.NewLine;
               break;
         case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_INTERPOLATED:
               sMsg = sMsg + "INTERPOLATED" + System.Environment.NewLine;
               break;
         case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE:
               sMsg = sMsg + "CIRCLE" + System.Environment.NewLine;
               break;
         case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_ELLIPSE:
               sMsg = sMsg + "ELLIPSE" + System.Environment.NewLine;
               break;
      }
   
      sMsg = sMsg + "Graphic Filled: ";
      if (objPresState.GraphicObjectAttributes.Filled)
         sMsg = sMsg + "Y" + System.Environment.NewLine;
      else
         sMsg = sMsg + "N" + System.Environment.NewLine;
      lCount = objPresState.GraphicObjectAttributes.PointCount;
      sMsg = sMsg + "Number of Graphic Points: " + lCount + System.Environment.NewLine;
      if (lCount < 10)
      {
         sMsg = sMsg + "Graphic Data: " + System.Environment.NewLine;
         for (I = 0; I < lCount; I++)
         {
            sMsg = sMsg + " " + "X" + I + 1 + ", Y" + I + 1 + " = " + objPresState.GraphicObjectAttributes.get_PointsX(I) + ", " + objPresState.GraphicObjectAttributes.get_PointsY(I) + System.Environment.NewLine;
         }
      }
      MessageBox.Show(sMsg, "Graphic Annotation Object");
      }
      else
      // The resulted DICOM annotation object is a text object
      {
         if (objPresState.TextObjectAttributes.BoundingBoxUsed)
         {
            sMsg = "Unformatted Text Value: " + objPresState.TextObjectAttributes.TextValue + System.Environment.NewLine;
            sMsg = sMsg + "Bounding Box Annotation Units: ";
            switch ( objPresState.TextObjectAttributes.BoundingBoxUnits )
            {
               case LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL:
                  sMsg = sMsg + "PIXEL" + System.Environment.NewLine;
                  break;
               case LTDICLib.DicomMeasureUnits.DICOM_UNIT_DISPLAY:
                  sMsg = sMsg + "DISPLAY" + System.Environment.NewLine;
                  break;
            }
            sMsg = sMsg + "Bounding Box Top Left Hand Corner: " + objPresState.TextObjectAttributes.BoundingBoxTLHCornerX + ", " + objPresState.TextObjectAttributes.BoundingBoxTLHCornerY + System.Environment.NewLine;
            sMsg = sMsg + "Bounding Box Bottom Right Hand Corner: " + objPresState.TextObjectAttributes.BoundingBoxBRHCornerX + ", " + objPresState.TextObjectAttributes.BoundingBoxBRHCornerY + System.Environment.NewLine;
            sMsg = sMsg + "Bounding Box Text Horizontal Justification: ";
            switch ( objPresState.TextObjectAttributes.BoundingBoxTextJustification )
            {
               case LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_LEFT:
                  sMsg = sMsg + "LEFT" + System.Environment.NewLine;
                  break;
               case LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_RIGHT:
                  sMsg = sMsg + "RIGHT" + System.Environment.NewLine;
                  break;
               case LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_CENTER:
                  sMsg = sMsg + "CENTER" + System.Environment.NewLine;
                  break;
            }
         }
         else
         {
            sMsg = "Unformatted Text Value: " + objPresState.TextObjectAttributes.TextValue + System.Environment.NewLine;
            sMsg = sMsg + "Anchor Point Annotation Units: ";
            switch ( objPresState.TextObjectAttributes.AnchorPointUnits )
            {
               case LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL:
                  sMsg = sMsg + "PIXEL" + System.Environment.NewLine;
                  break;
               case LTDICLib.DicomMeasureUnits.DICOM_UNIT_DISPLAY:
                  sMsg = sMsg + "DISPLAY" + System.Environment.NewLine;
                  break;
            }
            sMsg = sMsg + "Anchor Point: " + objPresState.TextObjectAttributes.AnchorPointX + ", " + objPresState.TextObjectAttributes.AnchorPointY + System.Environment.NewLine; sMsg = sMsg + "Anchor Point Visibility: ";
            if (objPresState.TextObjectAttributes.AnchorPointVisible)
               sMsg = sMsg + "Y";
            else
               sMsg = sMsg + "N";
         }
         MessageBox.Show(sMsg, "Text Annotation Object");
      }
      // If it is desired to stop the conversion process...
      //objPresState.EndConversion (DICOM_ERROR_ANN )
      // Any error code, but not 0
   }
private void LEADAnnToDicomAnn(ref LTDICLib.LEADDicomDS objPresStateDS)
{
   // Update the CurrentElement property with a Graphic Annotation Item so
   // that the resulted DICOM annotation objects are added to the Data Set
   if (objPresStateDS.FindFirstGraphicAnnItem() != 0)
   {
      // (Make sure that the specified layer is already defined in the
      // "Graphic Layer Module") objPresStateDS.CreateGraphicAnnItem(0, "LAYER_0");
      objPresStateDS.FindFirstGraphicAnnItem();
   }
   LTANNLib.LEADRasterAnnotation objRasterAnn = new LTANNLib.LEADRasterAnnotation();
   // Let's create a LEAD rectangle annotation object objRasterAnn.AnnCreate((short)LTANNLib.AnnObjectType.ANN_OBJECT_RECT, false, false);
   objRasterAnn.set_AnnRectLeft(objRasterAnn.AnnObject, 150);
   objRasterAnn.set_AnnRectTop(objRasterAnn.AnnObject, 175);
   objRasterAnn.set_AnnRectWidth(objRasterAnn.AnnObject, 200);
   objRasterAnn.set_AnnRectHeight(objRasterAnn.AnnObject, 100);
   objRasterAnn.AnnSetFillMode(objRasterAnn.AnnObject, (short)LTANNLib.AnnFillModeConstants.ANN_FILLMODE_TRANSPARENT, false);
   // Convert the LEAD annotation object. Now, for each resulted DICOM annotation
   // object, the OnConvertLEADAnnObjToDicomAnnObj event gets fired. By handling
   // the event, you can inspect the resulted object.
   if (objPresStateDS.ConvertLEADAnnObjToDicomAnnObjs(objRasterAnn.AnnObject, 0) == (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
      MessageBox.Show("The LEAD annotation object was converted successfully.");
   // Destroy the LEAD annotation object objRasterAnn.AnnDestroy(objRasterAnn.AnnObject, 0);
}