Navigation:  I Want To... > Imaging >

Add a measurement graphic

Previous pageReturn to chapter overviewNext page

Use Case

You want to mark up an image with measurements and annotations.

Relevant Architecture

Graphics
Vector Graphics
Control Graphics
ROI and Annotation Graphics

Relevant Types

VectorGraphic
IVectorGraphic
CompositeGraphic
LinePrimitive
BoundableGraphic
IBoundableGraphic
RectanglePrimitive
EllipsePrimitive
ArcPrimitive
PointPrimitive
IArcGraphic
InvariantBoundablePrimitive
InvariantRectanglePrimitive
InvariantEllipsePrimitive
InvariantArcPrimitive
ControlGraphic
RoiGraphic

Sample Code

using System.Drawing;

using ClearCanvas.Common;

using ClearCanvas.Desktop;

using ClearCanvas.Desktop.Actions;

using ClearCanvas.ImageViewer;

using ClearCanvas.ImageViewer.BaseTools;

using ClearCanvas.ImageViewer.Graphics;

using ClearCanvas.ImageViewer.InteractiveGraphics;

using ClearCanvas.ImageViewer.RoiGraphics;

 

// ... (other using namespace statements here)

 

namespace MyPlugin.Imaging

{

   [ButtonAction("apply""global-toolbars/ToolbarStandard/AddMeasurementTool""Apply")]

   [IconSet("apply", IconScheme.Colour, "Icons.MyToolSmall.png""Icons.MyToolMedium.png""Icons.MyToolLarge.png")]

   // ... (other action attributes here)

   [ExtensionOf(typeof (ImageViewerToolExtensionPoint))]

   public class AddMeasurementTool : ImageViewerTool

   {

      public void Apply()

      {

         if (this.SelectedOverlayGraphicsProvider == null)

            return;

 

         // Create a rectangle

         RectanglePrimitive rect = new RectanglePrimitive();

         rect.TopLeft = new PointF(510);

         rect.BottomRight = new PointF(2025);

 

         // Add the rectangle to a move control graphic so that the user can move the entire rectangle around

         // and a resize control graphic so that the user can resize the rectangle

         MoveControlGraphic rectangleMoveControlGraphic = new MoveControlGraphic(rect);

         BoundableResizeControlGraphic rectangleResizeControlGraphic = new BoundableResizeControlGraphic(rectangleMoveControlGraphic);

 

         // Add the controlled rectangle to a ROI graphic

         RoiGraphic roiGraphic = new RoiGraphic(rectangleResizeControlGraphic);

 

         // Add the rectangular ROI to the selected presentation image's scene graph      

         this.SelectedOverlayGraphicsProvider.OverlayGraphics.Add(roiGraphic);

 

         // Now render

         this.SelectedPresentationImage.Draw();

      }

   }

}

Remarks

Measurements and annotations are actually just special cases of interactive graphics – annotations (AnnotationGraphic) are simply interactive graphics with an attached callout text, and measurements (RoiGraphic) are simply annotations where the callout text is determined automatically by installed analyzer extensions that compute and display various statistics about the selected region.  Both AnnotationGraphic and RoiGraphic are ControlGraphics since they add control to the underlying shape, and are used in a similar manner to wrap another control graphic or subject.

Examples in Code Base

No start-to-finish examples of a ROI graphic tool, but ClearCanvas.ImageViewer.Tools.Measurement.RectangularRoiTool and ClearCanvas.ImageViewer.Tools.Measurement.MeasurementTool shows the individual steps of how a ROI graphic can be built up from a VectorGraphics and multiple ControlGraphics.