Examining Annotations (1) Example for Delphi

Procedure TForm1.ExamineAnnotations1(objPresStateDS: TLEADDicomDS);
var
   strMsg: String;
   nCount: Integer;
   I: Integer;
   J: Integer;
   nGraphicObjectCount: Integer;
   nTextObjectCount: Integer;
begin
   // Get the attributes that describe the 'Presentation State Module'
   if(objPresStateDS.GetPresStateAttributes (0) = DICOM_SUCCESS)then
   begin
      // Display some
      with(objPresStateDS.PresStateAttributes) do
      begin
         strMsg:= 'Instance Number: ' + IntToStr(InstanceNumber) + Chr(13) +
                  'Presentation Label: ' + PresLabel + Chr(13) +
                  'Presentation Description: ' + PresDescription + Chr(13) + 
                  'Presentation Creator//s Name: ' + PresCreatorName;
      end;

      Application.MessageBox(PChar(strMsg), 'Presentation State Attributes', MB_OK);
   end;
 
   // Display the SOP Instance UIDs of all the images referenced in the
   // 'Presentation State Module'
   if(objPresStateDS.FindFirstPresStateRefSeriesItem () = DICOM_SUCCESS)then
   begin
      strMsg:= '';
      Repeat
         nCount:= objPresStateDS.GetPresStateImageRefCount ();
         for I:= 0 To nCount - 1 do
         begin
            strMsg:= strMsg +
                     objPresStateDS.GetPresStateImageRefInstanceUID (I) +
                     Chr(13);
         end;
         
         strMsg:= strMsg + Chr(13);
      Until(objPresStateDS.MoveNextPresStateRefSeriesItem () <> DICOM_SUCCESS);
      
      Application.MessageBox(PChar(strMsg), 'Referenced SOP Instance UID(s)', MB_OK);
   end;
   
   // Enumerate all the layers defined
   nCount:= objPresStateDS.LayerCount;
   ShowMessage('Layer Count: ' + IntToStr(nCount));
   for I:= 0 to nCount - 1 do
   begin
      // Display some of the attributes
      if(objPresStateDS.GetLayerAttributes (I) = DICOM_SUCCESS)then
      begin
         with(objPresStateDS.LayerAttributes) do
         begin
            strMsg:= 'Graphic Layer: ' + LayerName + Chr(13) +
                     'Graphic Layer Order: ' + IntToStr(LayerOrder) + Chr(13) +
                     'Graphic Layer Description: ' + LayerDescription;
         end;
         
         Application.MessageBox(PChar(strMsg), 'Graphic Layer Attributes', MB_OK);
      end;
   end;

   // Enumerate all the Graphic Annotation Items
   if(objPresStateDS.FindFirstGraphicAnnItem () = DICOM_SUCCESS)then
   begin
      Repeat
         nGraphicObjectCount:= objPresStateDS.GetGraphicObjectCount ();
         // Or:
         //lGraphicObjectCount = objPresStateDS.GetLayerGraphicObjectCount ()
         
         nTextObjectCount:= objPresStateDS.GetTextObjectCount ();
         // Or:
         //lTextObjectCount = objPresStateDS.GetLayerTextObjectCount ()

         strMsg:= 'Graphic Layer: ' + objPresStateDS.GetLayerName() + Chr(13) +
                  'Graphic object count: ' + IntToStr(nGraphicObjectCount) + Chr(13) +
                  'Text object count: ' + IntToStr(nTextObjectCount) + Chr(13) + Chr(13);
                
         nCount:= objPresStateDS.GetLayerImageRefCount();
         if(nCount = 0)then
         begin
            strMsg:= strMsg +
                     'The annotations defined in this Item apply to all the ' +
                     'images listed in the ''Presentation State Module''.';
         end
         else
         begin
            strMsg:= strMsg + 'Referenced SOP Instance UID(s):' + Chr(13);
            for I:= 0 to nCount - 1 do
            begin
               strMsg:= strMsg + '   ' +
                        objPresStateDS.GetLayerImageRefInstanceUID(I) + Chr(13);
            end;
         end;

         Application.MessageBox(PChar(strMsg), 'Graphic Annotation Item', MB_OK);
         
         // Enumerate all the graphic objects in the current Item
         for I:= 0 to nGraphicObjectCount - 1 do
         begin
            objPresStateDS.GetGraphicObjectAttributes (I);
            with (objPresStateDS.GraphicObjectAttributes) do
            begin
               strMsg:= 'Graphic Annotation Units: ';
               Case (Units) of
                  DICOM_UNIT_PIXEL:
                     strMsg:= strMsg + 'PIXEL' + Chr(13);

                  DICOM_UNIT_DISPLAY:
                     strMsg:= strMsg + 'DISPLAY' + Chr(13);
               end;

               strMsg:= strMsg + 'Graphic Type: ';
               Case (type_) of
                  DICOM_GRAPHIC_OBJECT_TYPE_POINT:
                     strMsg:= strMsg + 'POINT' + Chr(13);

                  DICOM_GRAPHIC_OBJECT_TYPE_POLYLINE:
                     strMsg:= strMsg + 'POLYLINE' + Chr(13);

                  DICOM_GRAPHIC_OBJECT_TYPE_INTERPOLATED:
                     strMsg:= strMsg + 'INTERPOLATED' + Chr(13);

                  DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE:
                     strMsg:= strMsg + 'CIRCLE' + Chr(13);

                  DICOM_GRAPHIC_OBJECT_TYPE_ELLIPSE:
                     strMsg:= strMsg + 'ELLIPSE' + Chr(13);
               end;

               if(Filled)then
                  strMsg:= strMsg + 'Graphic Filled: Y' + Chr(13)
               else
                  strMsg:= strMsg + 'Graphic Filled: N' + Chr(13);
               
               nCount:= PointCount;
               strMsg:= strMsg + 'Number of Graphic Points: ' + IntToStr(nCount) + Chr(13);
               
               if(nCount < 10)then
               begin
                  strMsg:= strMsg + 'Graphic Data: ' + Chr(13);
                  for J:= 0 to nCount - 1 do
                  begin
                     strMsg:= strMsg + '   ' +
                            'X' + IntToStr(J) + IntToStr(1) + ', Y' + IntToStr(J) + IntToStr(1) + ' = ' +
                            FloatToStr(PointsX[J]) + ', ' + FloatToStr(PointsY[J]) + Chr(13);
                  end;
               end;

               Application.MessageBox(PChar(strMsg), 'Graphic Annotation Object', MB_OK);
            end;
         end;

         // Enumerate all the text objects in the current Item
         for I:= 0 to nTextObjectCount - 1 do
         begin
            objPresStateDS.GetTextObjectAttributes(I);
            with (objPresStateDS.TextObjectAttributes) do
            begin
               if(BoundingBoxUsed)then
               begin
                  strMsg:= 'Unformatted Text Value: ' + TextValue + Chr(13);

                  strMsg:= strMsg + 'Bounding Box Annotation Units: ';
                  Case (BoundingBoxUnits) of
                     DICOM_UNIT_PIXEL:
                        strMsg:= strMsg + 'PIXEL' + Chr(13);

                     DICOM_UNIT_DISPLAY:
                        strMsg:= strMsg + 'DISPLAY' + Chr(13);
                  end;

                  strMsg:= strMsg +
                           'Bounding Box Top Left Hand Corner: ' +
                           FloatToStr(BoundingBoxTLHCornerX) + ', ' +
                           FloatToStr(BoundingBoxTLHCornerY) + Chr(13);

                  strMsg:= strMsg +
                           'Bounding Box Bottom Right Hand Corner: ' + 
                           FloatToStr(BoundingBoxBRHCornerX) + ', ' +
                           FloatToStr(BoundingBoxBRHCornerY) + Chr(13);

                  strMsg:= strMsg + 'Bounding Box Text Horizontal Justification: ';
                  Case (BoundingBoxTextJustification) of
                     DICOM_TEXT_JUSTIFICATION_LEFT:
                        strMsg:= strMsg + 'LEFT' + Chr(13);

                     DICOM_TEXT_JUSTIFICATION_RIGHT:
                        strMsg:= strMsg + 'RIGHT' + Chr(13);

                     DICOM_TEXT_JUSTIFICATION_CENTER:
                        strMsg:= strMsg + 'CENTER' + Chr(13);
                  end;
               end
               else
               begin
                  strMsg:= 'Unformatted Text Value: ' + TextValue + Chr(13);

                  strMsg:= strMsg + 'Anchor Point Annotation Units: ';
                  Case (AnchorPointUnits) of
                     DICOM_UNIT_PIXEL:
                        strMsg:= strMsg + 'PIXEL' + Chr(13);

                     DICOM_UNIT_DISPLAY:
                        strMsg:= strMsg + 'DISPLAY' + Chr(13);
                  end;

                  strMsg:= strMsg + 'Anchor Point: ' +
                           FloatToStr(AnchorPointX) + ', ' +
                           FloatToStr(AnchorPointY) + Chr(13);

                  if(AnchorPointVisible)then
                     strMsg:= strMsg + 'Anchor Point Visibility: Y'
                  else
                     strMsg:= strMsg + 'Anchor Point Visibility: N';
               end;

               Application.MessageBox(PChar(strMsg), 'Text Annotation Object', MB_OK);
            end;
         end;
      Until(objPresStateDS.MoveNextGraphicAnnItem() <> DICOM_SUCCESS);
   end;
end;