Navigation:  I Want To... > Imaging >

Create a new kind of PresentationImage

Previous pageReturn to chapter overviewNext page

Use Case

You want to create a custom PresentationImage.
BasicPresentationImage and its subclasses are inadequate.

Relevant Architecture

Presentation Images

Relevant Types

PresentationImage
IPresentationImage

Sample Code

using ClearCanvas.ImageViewer;

using ClearCanvas.ImageViewer.Graphics;

using ClearCanvas.ImageViewer.Imaging;

using ClearCanvas.ImageViewer.Rendering;

 

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

 

namespace MyPlugin.Imaging

{

   public class VolumePresentationImage

      : PresentationImage, ISpatialTransformProvider, IVoiLutProvider

   {

      private IDisplaySet _displaySet;

 

      public VolumePresentationImage(IDisplaySet displaySet)

      {

         _displaySet = displaySet;

      }

 

      public override IRenderer ImageRenderer

      {

         get

         {

            // we may need to provide a custom renderer, such as this one

            // (in the ClearCanvas.ImageViewer.Tools.Volume.VTK project)

            if (base.ImageRenderer == null)

            {

               // base.ImageRenderer = new VolumePresentationImageRenderer();

            }

 

            return base.ImageRenderer;

         }

      }

 

      public override IPresentationImage CreateFreshCopy()

      {

         return new VolumePresentationImage(_displaySet);

      }

 

      public IVoiLutManager VoiLutManager

      {

         get

         {

            // IVoiLutProvider implementation

            return null;

         }

      }

 

      public ISpatialTransform SpatialTransform

      {

         get

         {

            // ISpatialTransformProvider implementation

            return null;

         }

      }

   }

}

Remarks

Before subclassing PresentationImage directly, consider whether BasicPresentationImage and its subclasses provide the functionality you need.  They will be adequate for a number of 2D imaging scenarios.  However, there will be some 2D use cases, and all 3D use cases, where BasicPresentationImage and its subclasses are too limiting and will not suffice.  In such cases, you need to subclass PresentationImage directly.

In the example above, we create a new kind of PresentationImage called VolumePresentationImage.  It accepts a DisplaySet at construction; the images which it contains are used to create a volume data set.  A few things are worth noting here:

VolumePresentationImage has its own renderer, called VolumePresentationImageRenderer.  The renderer that comes with BasicPresentationImage (i.e., GdiRenderer) has no idea how to render a VolumePresentationImage, and so we must write a new renderer that does.
VolumePresentationImage implements IVoiLutProvider, which defines a contract for some kind of LUT (e.g. window/level) functionality.  By implementing this interface, existing tools that consume IVoiLutProvider will also work with VolumePresentationImages.

If you're deriving from PresentationImage, you will obviously want to render it at some point.  To do that, you will need to add it to a new DisplaySet and put the DisplaySet in an ImageBox.

Examples in Code Base

ClearCanvas.ImageViewer.Tools.Volume.VTK.VolumePresentationImage