Converting LEAD Annotation Objects to DICOM Annotation Objects Example for Delphi
procedure TForm1.objPresStateConvertLEADAnnObjToDicomAnnObj(
ASender: TObject; bGraphicObject: WordBool);
var
strMsg: String;
nCount: Integer;
I: Integer;
begin
// Display the attributes of the resulted DICOM annotation object
if(bGraphicObject)then // The resulted DICOM annotation object is a graphic object
begin
with (objPresState.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;
strMsg:= strMsg + 'Graphic Filled: ';
if (Filled) then
strMsg:= strMsg + 'Y' + Chr(13)
else
strMsg:= strMsg + '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 I:= 0 To nCount - 1 do
begin
strMsg:= strMsg + ' ' +
'X' + IntToStr(I) + IntToStr(1) + ', Y' + IntToStr(I) + IntToStr(1) + ':= ' +
FloatToStr(PointsX[I]) + ', ' + FloatToStr(PointsY[I]) + Chr(13);
end;
end;
Application.MessageBox(PChar(strMsg), 'Graphic Annotation Object', MB_OK);
end;
end
else // The resulted DICOM annotation object is a text object
begin
with (objPresState.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);
strMsg:= strMsg + 'Anchor Point Visibility: ';
if(AnchorPointVisible)then
strMsg:= strMsg + 'Y'
else
strMsg:= strMsg + 'N';
end;
Application.MessageBox(PChar(strMsg), 'Text Annotation Object', MB_OK);
end;
end;
// If it is desired to stop the conversion process...
//objPresState.EndConversion DICOM_ERROR_ANN // Any error code, but not 0
end;
Procedure TForm1.LEADAnnToDicomAnn(objPresStateDS: TLEADDicomDS);
var
objRasterAnn: LEADRasterAnnotation;
begin
// 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)then
begin
// (Make sure that the specified layer is already defined in the
// 'Graphic Layer Module')
objPresStateDS.CreateGraphicAnnItem (0, 'LAYER_0');
objPresStateDS.FindFirstGraphicAnnItem ();
end;
objRasterAnn:= coLEADRasterAnnotation.Create();
// Let//s create a LEAD rectangle annotation object
with (objRasterAnn) do
begin
AnnCreate(ANN_OBJECT_RECT, False, False);
AnnRectLeft[AnnObject]:= 150;
AnnRectTop[AnnObject]:= 175;
AnnRectWidth[AnnObject]:= 200;
AnnRectHeight[AnnObject]:= 100;
AnnSetFillMode(AnnObject, ANN_FILLMODE_TRANSPARENT, False);
end;
// 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) = DICOM_SUCCESS)then
ShowMessage('The LEAD annotation object was converted successfully.');
// Destroy the LEAD annotation object
objRasterAnn.AnnDestroy(objRasterAnn.AnnObject, 0);
end;