Creating DICOM Annotations example for C++ 5.0 and later
void CreateAnnotations(ILEADDicomDSPtr& spPresStateDS)
{
SYSTEMTIME SystemTime;
GetLocalTime(&SystemTime);
// Set the attributes that describe the "Presentation State Module"
IDicomPresStateAttributesPtr spPresStateAttribs = spPresStateDS->PresStateAttributes;
spPresStateAttribs->InstanceNumber = 1;
spPresStateAttribs->PresLabel = "SOME_LABEL";
spPresStateAttribs->PresDescription = "Description of the presentation";
spPresStateAttribs->PresCreationDate ->Year = SystemTime.wYear;
spPresStateAttribs->PresCreationDate ->Month = SystemTime.wMonth;
spPresStateAttribs->PresCreationDate ->Day = SystemTime.wDay;
spPresStateAttribs->PresCreationTime ->Hours = SystemTime.wHour;
spPresStateAttribs->PresCreationTime ->Minutes = SystemTime.wMinute;
spPresStateAttribs->PresCreationTime ->Seconds = SystemTime.wSecond;
spPresStateAttribs->PresCreationTime ->Fractions = 0;
spPresStateAttribs->PresCreatorName = "SomeOne";
if (spPresStateDS->SetPresStateAttributes () == DICOM_SUCCESS)
{
MessageBox(NULL, "Presentation State attributes were set successfully.",
"Presentation State Attributes", MB_OK);
}
// Add references to some images (under the "Presentation State Module")
spPresStateDS->AddPresStateImageRef ("C:\\Image1.dic");
spPresStateDS->AddPresStateImageRef ("C:\\Image2.dic");
spPresStateDS->AddPresStateImageRef ("C:\\Image3.dic");
char szMsg[128];
_bstr_t sLayerName;
// Create a layer
IDicomLayerAttributesPtr spLayerAttribs = spPresStateDS->LayerAttributes;
spLayerAttribs->LayerName = "LAYER_0"; // "Graphic Layer"
spLayerAttribs->LayerOrder = 1;
spLayerAttribs->DisplayGrayscaleValue = -1;
spLayerAttribs->DisplayRedValue = -1;
spLayerAttribs->DisplayGreenValue = -1;
spLayerAttribs->DisplayRedValue = -1;
spLayerAttribs->LayerDescription = "Description of the layer";
if (spPresStateDS->CreateLayer () == DICOM_SUCCESS)
{
sLayerName = spLayerAttribs->LayerName;
wsprintf(szMsg, "Layer '%s' was created successfully.",
sLayerName.operator char *());
MessageBox(NULL, szMsg, "Graphic Layer", MB_OK);
// Change one of the attributes and update the layer
spLayerAttribs->LayerOrder = 0;
spPresStateDS->SetLayerAttributes (spPresStateDS->NewLayerIndex);
}
long hGraphicAnnItem = 0;
// Create a Graphic Annotation Item
if (spPresStateDS->CreateGraphicAnnItem (0, sLayerName) == DICOM_SUCCESS)
{
MessageBox(NULL, "A Graphic Annotation Item was created successfully.",
"Graphic Annotation Item", MB_OK);
spPresStateDS->FindFirstGraphicAnnItem ();
hGraphicAnnItem = spPresStateDS->GetCurrentElement()->hElement;
}
_bstr_t sSOPInstanceUID;
// The annotations defined in the Item hGraphicAnnItem will be applied
// only to one of the images listed in the Presentation State Module
if (spPresStateDS->FindFirstPresStateRefSeriesItem () == DICOM_SUCCESS)
{
if (spPresStateDS->GetPresStateImageRefCount () > 0)
{
sSOPInstanceUID = spPresStateDS->GetPresStateImageRefInstanceUID (0);
}
}
spPresStateDS->SetCurrentElement (hGraphicAnnItem);
spPresStateDS->AddLayerImageRef(sSOPInstanceUID);
// Let's create a graphic annotation object
IDicomGraphicObjectAttributesPtr spGraphicObjAttribs;
spGraphicObjAttribs = spPresStateDS->GraphicObjectAttributes;
spGraphicObjAttribs->LayerName = sLayerName;
spGraphicObjAttribs->Units = DICOM_UNIT_PIXEL;
spGraphicObjAttribs->Type = DICOM_GRAPHIC_OBJECT_TYPE_CIRCLE;
spGraphicObjAttribs->Filled = VARIANT_TRUE;
spGraphicObjAttribs->PointCount = 2; // "Number of Graphic Points"
// "Graphic Data":
spGraphicObjAttribs->PointsX [0] = float(252.5);
spGraphicObjAttribs->PointsY [0] = float(252.5);
spGraphicObjAttribs->PointsX [1] = float(209.2);
spGraphicObjAttribs->PointsY [1] = float(199.6);
if (spPresStateDS->CreateGraphicObject(VARIANT_TRUE) == DICOM_SUCCESS)
{
MessageBox(NULL, "A graphic annotation object was created successfully.",
"Graphic Annotation Object", MB_OK);
// Change one of the attributes and update the object
spGraphicObjAttribs->Filled = VARIANT_FALSE;
spPresStateDS->SetGraphicObjectAttributes (0);
}
IDicomTextObjectAttributesPtr spTextObjAttribs;
spTextObjAttribs = spPresStateDS->TextObjectAttributes;
// Let's now create a text annotation object
spTextObjAttribs->LayerName = sLayerName;
spTextObjAttribs->BoundingBoxUsed = VARIANT_TRUE;
spTextObjAttribs->AnchorPointUsed = VARIANT_FALSE;
spTextObjAttribs->BoundingBoxUnits = DICOM_UNIT_PIXEL;
spTextObjAttribs->TextValue = "Text annotation (using a bounding box)";
spTextObjAttribs->BoundingBoxTLHCornerX = float(176.7);
spTextObjAttribs->BoundingBoxTLHCornerY = float(117.7);
spTextObjAttribs->BoundingBoxBRHCornerX = float(320.3);
spTextObjAttribs->BoundingBoxBRHCornerY = float(136.1);
spTextObjAttribs->BoundingBoxTextJustification = DICOM_TEXT_JUSTIFICATION_RIGHT;
if (spPresStateDS->CreateTextObject(VARIANT_TRUE) == DICOM_SUCCESS)
{
MessageBox(NULL, "A text annotation object was created successfully.",
"Text Annotation Object", MB_OK);
// Change one of the attributes and update the object
spTextObjAttribs->BoundingBoxTextJustification = DICOM_TEXT_JUSTIFICATION_LEFT;
spPresStateDS->SetTextObjectAttributes (0);
}
// And another text annotation object
spTextObjAttribs->LayerName = sLayerName;
spTextObjAttribs->AnchorPointUsed = VARIANT_TRUE;
spTextObjAttribs->BoundingBoxUsed = VARIANT_FALSE;
spTextObjAttribs->AnchorPointUnits = DICOM_UNIT_PIXEL;
spTextObjAttribs->TextValue = "Text annotation (using an anchor point)";
spTextObjAttribs->AnchorPointX = float(277.9);
spTextObjAttribs->AnchorPointY = float(382.7);
spTextObjAttribs->AnchorPointVisible = VARIANT_TRUE;
if (spPresStateDS->CreateTextObject(VARIANT_TRUE) == DICOM_SUCCESS)
{
MessageBox(NULL, "Another text annotation object was created successfully.",
"Text Annotation Object", MB_OK);
}
}