Creating DICOM Annotations Example for Delphi
Procedure TForm1.CreateAnnotations(objPresStateDS: TLEADDicomDS);
var
vOpt: TVarData;
strLayerName: String;
hGraphicAnnItem: LongInt;
strSOPInstanceUID: String;
begin
hGraphicAnnItem:= 0;
// Set the attributes that describe the "Presentation State Module"
with (objPresStateDS.PresStateAttributes) do
begin
InstanceNumber:= 1;
PresLabel:= 'SOME_LABEL';
PresDescription:= 'Description of the presentation';
with (PresCreationDate) do
begin
Year:= YearOf(Date);
Month:= MonthOf(Date);
Day:= DayOf(Date);
end;
with (PresCreationTime) do
begin
Hours:= HourOf(Time);
Minutes:= MinuteOf(Time);
Seconds:= SecondOf(Time);
Fractions:= 0;
end;
PresCreatorName:= 'SomeOne';
end;
if(objPresStateDS.SetPresStateAttributes () = DICOM_SUCCESS)then
ShowMessage('Presentation State attributes were set successfully.');
vOpt.VType:= varError;
vOpt.VError:= DISP_E_PARAMNOTFOUND;
// Add references to some images (under the "Presentation State Module")
objPresStateDS.AddPresStateImageRef ('C:\Image1.dic', OleVariant(vOpt));
objPresStateDS.AddPresStateImageRef('C:\Image2.dic', OleVariant(vOpt));
objPresStateDS.AddPresStateImageRef('C:\Image3.dic', OleVariant(vOpt));
// Create a layer
with (objPresStateDS.LayerAttributes) do
begin
LayerName:= 'LAYER_0'; // 'Graphic Layer'
LayerOrder:= 1;
DisplayGrayscaleValue:= -1;
DisplayRedValue:= -1;
DisplayGreenValue:= -1;
DisplayRedValue:= -1;
LayerDescription:= 'Description of the layer';
end;
if(objPresStateDS.CreateLayer () = DICOM_SUCCESS)then
begin
strLayerName:= objPresStateDS.LayerAttributes.LayerName;
ShowMessage('Layer `' + strLayerName + '` was created successfully.');
// Change one of the attributes and update the layer
objPresStateDS.LayerAttributes.LayerOrder:= 0;
objPresStateDS.SetLayerAttributes (objPresStateDS.NewLayerIndex);
end;
// Create a Graphic Annotation Item
if(objPresStateDS.CreateGraphicAnnItem (0, strLayerName) = DICOM_SUCCESS)then
begin
ShowMessage('A Graphic Annotation Item was created successfully.');
objPresStateDS.FindFirstGraphicAnnItem ();
hGraphicAnnItem:= objPresStateDS.DefaultInterface.Get_CurrentElement ().hElement;
end;
// The annotations defined in the Item hGraphicAnnItem will be applied
// only to one of the images listed in the Presentation State Module
if(objPresStateDS.FindFirstPresStateRefSeriesItem () = DICOM_SUCCESS)then
begin
if(objPresStateDS.GetPresStateImageRefCount () > 0)then
strSOPInstanceUID:= objPresStateDS.GetPresStateImageRefInstanceUID (0);
end;
objPresStateDS.SetCurrentElement (hGraphicAnnItem);
objPresStateDS.AddLayerImageRef(strSOPInstanceUID);
// Let//s create a graphic annotation object
with(objPresStateDS.GraphicObjectAttributes) do
begin
LayerName:= strLayerName;
Units:= DICOM_UNIT_PIXEL;
type_:= DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE;
Filled:= True;
PointCount:= 2; // "Number of Graphic Points"
// 'Graphic Data':
PointsX[0]:= 252.5;
PointsY[0]:= 252.5;
PointsX[1]:= 209.2;
PointsY[1]:= 199.6;
end;
if(objPresStateDS.CreateGraphicObject(True) = DICOM_SUCCESS)then
begin
ShowMessage('A graphic annotation object was created successfully.');
// Change one of the attributes and update the object
objPresStateDS.GraphicObjectAttributes.Filled:= False;
objPresStateDS.SetGraphicObjectAttributes(0);
end;
// Let//s now create a text annotation object
with (objPresStateDS.TextObjectAttributes) do
begin
LayerName:= strLayerName;
BoundingBoxUsed:= True;
AnchorPointUsed:= False;
BoundingBoxUnits:= DICOM_UNIT_PIXEL;
TextValue:= 'Text annotation (using a bounding box)';
BoundingBoxTLHCornerX:= 176.7;
BoundingBoxTLHCornerY:= 117.7;
BoundingBoxBRHCornerX:= 320.3;
BoundingBoxBRHCornerY:= 136.1;
BoundingBoxTextJustification:= DICOM_TEXT_JUSTIFICATION_RIGHT;
end;
if(objPresStateDS.CreateTextObject(True) = DICOM_SUCCESS)then
begin
ShowMessage('A text annotation object was created successfully.');
// Change one of the attributes and update the object
objPresStateDS.TextObjectAttributes. BoundingBoxTextJustification:= DICOM_TEXT_JUSTIFICATION_LEFT;
objPresStateDS.SetTextObjectAttributes(0);
end;
// And another text annotation object
with (objPresStateDS.TextObjectAttributes) do
begin
LayerName:= strLayerName;
AnchorPointUsed:= True;
BoundingBoxUsed:= False;
AnchorPointUnits:= DICOM_UNIT_PIXEL;
TextValue:= 'Text annotation (using an anchor point)';
AnchorPointX:= 277.9;
AnchorPointY:= 382.7;
AnchorPointVisible:= True;
end;
if(objPresStateDS.CreateTextObject(True) = DICOM_SUCCESS)then
ShowMessage('Another text annotation object was created successfully.');
end;