Examining Annotations (1) Example for VB.NET

Private Sub ExamineAnnotations1(ByRef objPresStateDS As LTDICLib.LEADDicomDS)
   Dim sMsg As String

   ' Get the attributes that describe the "Presentation State Module"
   If objPresStateDS.GetPresStateAttributes(0) = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
      ' Display some
      With objPresStateDS.PresStateAttributes
         sMsg = "Instance Number: " & .InstanceNumber & vbNewLine & "Presentation Label: " & .PresLabel & vbNewLine & "Presentation Description: " & .PresDescription & vbNewLine & "Presentation Creator’s Name: " & .PresCreatorName
      End With

      MessageBox.Show(sMsg, "Presentation State Attributes")
   End If

   Dim I, lCount, J As Integer

   ' Display the SOP Instance UIDs of all the images referenced in the
   ' "Presentation State Module"
   If objPresStateDS.FindFirstPresStateRefSeriesItem() = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
      sMsg = ""
      Do
         lCount = objPresStateDS.GetPresStateImageRefCount()
         For I = 0 To lCount - 1
            sMsg = sMsg & objPresStateDS.GetPresStateImageRefInstanceUID(I) & vbNewLine
         Next

         sMsg = sMsg & vbNewLine
      Loop While objPresStateDS.MoveNextPresStateRefSeriesItem() = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS

      MessageBox.Show(sMsg, "Referenced SOP Instance UID(s)")
   End If

   ' Enumerate all the layers defined
   lCount = objPresStateDS.LayerCount
   MessageBox.Show("Layer Count: " & lCount)
   For I = 0 To lCount - 1
      ' Display some of the attributes
         If objPresStateDS.GetLayerAttributes(I) = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
            With objPresStateDS.LayerAttributes
               sMsg = "Graphic Layer: " & .LayerName & vbNewLine & "Graphic Layer Order: " & .LayerOrder & vbNewLine & "Graphic Layer Description: " & .LayerDescription
            End With

            MessageBox.Show(sMsg, "Graphic Layer Attributes")
         End If
   Next

   Dim lGraphicObjectCount, lTextObjectCount As Integer

   ' Enumerate all the Graphic Annotation Items
   If objPresStateDS.FindFirstGraphicAnnItem() = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
      Do
         lGraphicObjectCount = objPresStateDS.GetGraphicObjectCount()
         ' Or:
         'lGraphicObjectCount = objPresStateDS.GetLayerGraphicObjectCount ()

         lTextObjectCount = objPresStateDS.GetTextObjectCount()
         ' Or:
         'lTextObjectCount = objPresStateDS.GetLayerTextObjectCount()

         sMsg = "Graphic Layer: " & objPresStateDS.GetLayerName() & vbNewLine & "Graphic object count: " & lGraphicObjectCount & vbNewLine & "Text object count: " & lTextObjectCount & vbNewLine & vbNewLine

         lCount = objPresStateDS.GetLayerImageRefCount()
         If lCount = 0 Then
            sMsg = sMsg & "The annotations defined in this Item apply to all the " & "images listed in the ""Presentation State Module""."
         Else
            sMsg = sMsg & "Referenced SOP Instance UID(s):" & vbNewLine
            For I = 0 To lCount - 1
               sMsg = sMsg & " " & objPresStateDS.GetLayerImageRefInstanceUID(I) & vbNewLine
            Next
         End If

         MessageBox.Show(sMsg, "Graphic Annotation Item")

         ' Enumerate all the graphic objects in the current Item
         For I = 0 To lGraphicObjectCount - 1
            objPresStateDS.GetGraphicObjectAttributes(I)
            With objPresStateDS.GraphicObjectAttributes
               sMsg = "Graphic Annotation Units: "
               Select Case .Units
                  Case LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL
                     sMsg = sMsg & "PIXEL" & vbNewLine
                  Case LTDICLib.DicomMeasureUnits.DICOM_UNIT_DISPLAY
                     sMsg = sMsg & "DISPLAY" & vbNewLine
               End Select

               sMsg = sMsg & "Graphic Type: "
               Select Case .Type
                  Case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_POINT
                     sMsg = sMsg & "POINT" & vbNewLine
                  Case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_POLYLINE
                     sMsg = sMsg & "POLYLINE" & vbNewLine
                  Case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_INTERPOLATED
                     sMsg = sMsg & "INTERPOLATED" & vbNewLine
                  Case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE
                     sMsg = sMsg & "CIRCLE" & vbNewLine
                  Case LTDICLib.DicomGraphicObjectTypes.DICOM_GRAPHIC_OBJECT_TYPE_ELLIPSE
                     sMsg = sMsg & "ELLIPSE" & vbNewLine
               End Select

               If .Filled Then
                  sMsg = sMsg & "Graphic Filled: Y" & vbNewLine
               Else
                  sMsg = sMsg & "Graphic Filled: N" & vbNewLine
               End If

               lCount = .PointCount
               sMsg = sMsg & "Number of Graphic Points: " & lCount & vbNewLine

               If lCount < 10 Then
                  sMsg = sMsg & "Graphic Data: " & vbNewLine
                  For J = 0 To lCount - 1
                     sMsg = sMsg & " " & "X" & J + 1 & ", Y" & J + 1 & " = " & .PointsX(J) & ", " & .PointsY (J) & vbNewLine
                  Next
               End If

               MessageBox.Show(sMsg, "Graphic Annotation Object")
            End With
         Next

         ' Enumerate all the text objects in the current Item
         For I = 0 To lTextObjectCount - 1
            objPresStateDS.GetTextObjectAttributes(I)
            With objPresStateDS.TextObjectAttributes
               If .BoundingBoxUsed Then
                  sMsg = "Unformatted Text Value: " & .TextValue & vbNewLine

                  sMsg = sMsg & "Bounding Box Annotation Units: "
                  Select Case .BoundingBoxUnits
                     Case LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL
                        sMsg = sMsg & "PIXEL" & vbNewLine
                     Case LTDICLib.DicomMeasureUnits.DICOM_UNIT_DISPLAY
                        sMsg = sMsg & "DISPLAY" & vbNewLine
                  End Select

                  sMsg = sMsg & "Bounding Box Top Left Hand Corner: " & .BoundingBoxTLHCornerX & ", " & .BoundingBoxTLHCornerY & vbNewLine

                  sMsg = sMsg & "Bounding Box Bottom Right Hand Corner: " & .BoundingBoxBRHCornerX & ", " & .BoundingBoxBRHCornerY & vbNewLine

                  sMsg = sMsg & "Bounding Box Text Horizontal Justification: "
                  Select Case .BoundingBoxTextJustification
                     Case LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_LEFT
                        sMsg = sMsg & "LEFT" & vbNewLine
                     Case LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_RIGHT
                        sMsg = sMsg & "RIGHT" & vbNewLine
                     Case LTDICLib.DicomTextJustificationTypes.DICOM_TEXT_JUSTIFICATION_CENTER
                        sMsg = sMsg & "CENTER" & vbNewLine
                  End Select
               Else
                  sMsg = "Unformatted Text Value: " & .TextValue & vbNewLine

                  sMsg = sMsg & "Anchor Point Annotation Units: "
                  Select Case .AnchorPointUnits
                     Case LTDICLib.DicomMeasureUnits.DICOM_UNIT_PIXEL
                        sMsg = sMsg & "PIXEL" & vbNewLine
                     Case LTDICLib.DicomMeasureUnits.DICOM_UNIT_DISPLAY
                        sMsg = sMsg & "DISPLAY" & vbNewLine
                  End Select

                  sMsg = sMsg & "Anchor Point: " & .AnchorPointX & ", " & .AnchorPointY & vbNewLine

                  If .AnchorPointVisible Then
                     sMsg = sMsg & "Anchor Point Visibility: Y"
                  Else
                     sMsg = sMsg & "Anchor Point Visibility: N"
                  End If
               End If

               MessageBox.Show(sMsg, "Text Annotation Object")
            End With
         Next
      Loop While objPresStateDS.MoveNextGraphicAnnItem() = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS
   End If
End Sub