A common use of a medical image viewer is to draw a region of interest and mark up parts of the underlying image with various notes, measurements and statistics. As such, having built-in support for creating such mark up is very important, since it gives developers a standard and easy way to setup the graphics without having a large amount of duplicate code. Support for this is provided in the Framework by the AnnotationGraphic class which consists of the graphic with which the note or measurement is associated and a callout graphic, which is simply a text graphic containing the note or measurement, and a line pointing to the associated graphic. Since the annotation graphic decorates the subject with a callout that provides a certain amount of user interactivity, it will probably not surprise you that an AnnotationGraphic is implemented under the hood as a control graphic.

The AnnotationGraphic class embodies a very generic concept of such annotations in that it places no restriction on the type of graphic that it can decorate, and the callouts it attaches to the subject have text content that is determined by the creating tool. However, as noted earlier, a frequent use of the graphics is to make measurements and compute statistics about a ROI graphic. Rather than have each tool potentially duplicate all the code for algorithms and formatting the callout text in a consistent way, it would make much more sense to create a special type of extensible AnnotationGraphic that can take custom algorithms and automatically format the output for display in the callout text. In the Framework, this specialization of annotation graphics for ROIs is embodied in the ClearCanvas.ImageViewer.RoiGraphics namespace.
At the heart of this namespace is the RoiGraphic class, which specializes the AnnotationGraphic with a Roi, which is an informational object containing the pixels of the image in the region of interest, and a RoiCalloutGraphic which runs its collection of analysis algorithms on the ROI and formats the output to produce the final callout text content.

Each Roi contains a fixed definition of the region of interest – such as the pixel cooordinates of the end points of a line segment or the vertices of a closed polygon – and a reference to the source image pixel data. For convenience, the concrete Roi classes also provide some standard statistics about the region of interest such as area and mean. Whenever the region of interest changes (either programmatically or by the user via the control graphics), the RoiCalloutGraphic asks its analyzers to reprocess the current Roi object. The analyzers can use any of the methods and properties available on the Roi to perform its analysis and return a result to be displayed by the callout.

Programmatically creating region of interest measurement graphics can be achieved by simply creating the appropriate vector graphic to represent the ROI, decorating it with the necessary control graphics including the RoiGraphic, and then customizing the list of analyzers on the callout. The following class diagram illustrates the built-in measurement tools, the types of Roi objects created by their graphics, and the key analyzers for the specific Roi types.
