Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
Annotation Module

Annotations

The annotations in MITK are a simple way to display additional information on the render windows. A class, deriving from mitk::Annotation represents an arbitrary 2D or 3D object that can be rendered as an Annotation. This can for example be used for the annotation of 3D points or to Annotation despriptions in the window corners. Instances of the MicroService mitk::AbstractAnnotationRenderer are used to add the annotations to the renderwindows, updating them and depending on their implementation, organize them in a layout. This module contains implementations for mitk::AbstractAnnotationRenderer as well as mitk::Annotation. Currently, the following features are realized within the Annotation module.

  1. 2D and 3D textelements are already defined in the Annotation module and are using VTK to create custom annotations.
  2. 2D and 3D annotations can be placed freely by providing a display position
  3. 2D annotations can be placed in a layout, which organizes the annotations in the display corners.

Usage of Predefined Annotations

mitkTextAnnotation2D

This exemplary Annotation can render text as a 2D Annotation which can be placed with the LayoutAnnotationRenderer

// Create a textAnnotation2D
mitk::TextAnnotation2D::Pointer textAnnotation = mitk::TextAnnotation2D::New();
textAnnotation->SetText("Test!"); // set UTF-8 encoded text to render
textAnnotation->SetFontSize(40);
textAnnotation->SetColor(1, 0, 0); // Set text color to red
textAnnotation->SetOpacity(1);
// The position of the Annotation can be set to a fixed coordinate on the display.
pos[0] = 10;
pos[1] = 20;
textAnnotation->SetPosition2D(pos);
std::string rendererID = renderWindow.GetRenderer()->GetName();
// The LayoutAnnotationRenderer can place the TextAnnotation2D at some defined corner positions
textAnnotation, rendererID, mitk::LayoutAnnotationRenderer::TopLeft, 5, 5, 1);

mitkTextAnnotation3D

This Annotation displays labels in 3D coordinates. The labels always face the camera.

// This vector is used to define an offset for the annotations, in order to show them with a margin to the actual
// coordinate.
mitk::Point3D offset;
offset[0] = .5;
offset[1] = .5;
offset[2] = .5;
// save references to Annotations so that they do not get deregistered
std::vector<mitk::TextAnnotation3D::Pointer> annotationReferences;
// Just a loop to create some points
for (unsigned long i = 0; i < 10; i++)
{
// To each point, a TextAnnotation3D is created
mitk::TextAnnotation3D::Pointer textAnnotation3D = mitk::TextAnnotation3D::New();
point[0] = i * 20;
point[1] = i * 30;
point[2] = i * -50;
pointset->InsertPoint(i, point);
textAnnotation3D->SetText("A Point");
// The Position is set to the point coordinate to create an annotation to the point in the PointSet.
textAnnotation3D->SetPosition3D(point);
// move the annotation away from the actual point
textAnnotation3D->SetOffsetVector(offset);
annotationReferences.push_back(textAnnotation3D);
}
// Get the MicroserviceID of the registered textAnnotation
std::string serviceID = textAnnotation->GetMicroserviceID();
// The AnnotationUtils can retrieve any registered annotations by their microservice ID
// This way, it is possible to change the properties of Annotations without knowing their implementation
annotation->SetText("changed text!");
// also show the created pointset
datanode->SetData(pointset);
datanode->SetName("pointSet");
ds->Add(datanode);

Implement a Custom Annotation

A new custom Annotation should derive from mitkAnnotation or one of the later mentioned subclasses VtkAnnotation2D oder VtkAnnotation3D. There should always be an implementation for the methods AddToBaseRenderer, AddToRenderer, RemoveFromBaseRenderer RemoveFromRenderer and Update. UpdateAnnotation is the procedure that is called when the Annotation properties have changed. If the Annotation is rendered by VTK, this method only applies the properties to the representation. If the custom Annotation requires additional properties, they should be made accessible by getters and setters for a better usability:

{
SetProperty("Position3D", position3dProperty,renderer);
}
{
mitk::Point3D position3D;
GetPropertyValue<mitk::Point3D>("Position3D", position3D, renderer);
return position3D;
}

VTK 2D Annotation

VTK based Annotations which are meant to be displayed in 2D over the render window should derive from the mitk::VtkAnnotation2D. The mitk::VtkAnnotation2D is a subclass of Vtk::Annotation, that uses VTK to render the Annotation. This class creates the Annotation representation as a vtkActor2D, and is very easy to implement because only UpdateVtkAnnotation2D and GetVtkActor2D have to be implemented. The add, update and remove methods are implemented in the superclasses. UpdateVtkAnnotation2D only needs to apply the specific properties and GetVtkActor2D simply returns the created vtkActor.

VTK 3D Annotation

The mitkVtkAnnotation3D works just like mitkVtkAnnotation2D, but it is designed for arbitrary 3D objects which derive from vtkProp,

mitk::Annotation
Base class for all Annotation This class is to be implemented in order to create Annotation which are...
Definition: mitkAnnotation.h:27
mitk::Point3dProperty::New
static Pointer New()
mitk::VtkAnnotation3D::GetPosition3D
Point3D GetPosition3D() const
mitk::LayoutAnnotationRenderer::AddAnnotation
static void AddAnnotation(Annotation *annotation, const std::string &rendererID, Alignment alignment=TopLeft, double marginX=5, double marginY=5, int priority=-1)
mitk::VtkAnnotation3D::SetPosition3D
void SetPosition3D(const Point3D &position3D)
mitk::RenderWindowBase::GetRenderer
virtual mitk::VtkPropRenderer * GetRenderer()
mitk::Annotation::SetText
void SetText(std::string text)
itk::SmartPointer< Self >
mitk::PointSet::New
static Pointer New()
mitk::AnnotationUtils::GetAnnotation
static mitk::Annotation * GetAnnotation(const std::string &AnnotationID)
GetAnnotation returns a registered Annotation for a specified ID.
mitk::Annotation::SetProperty
void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
mitk::TextAnnotation2D::New
static Pointer New()
mitk::ManualPlacementAnnotationRenderer::AddAnnotation
static void AddAnnotation(Annotation *Annotation, const std::string &rendererID)
mitk::BaseRenderer::GetName
const char * GetName() const
Return the name of the base renderer.
Definition: mitkBaseRenderer.h:326
mitk::TextAnnotation3D::New
static Pointer New()
mitk::Point< ScalarType, 2 >
mitk::Point3D
Point< ScalarType, 3 > Point3D
Definition: mitkPoint.h:113
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
mitk::LayoutAnnotationRenderer::TopLeft
@ TopLeft
Definition: mitkLayoutAnnotationRenderer.h:41
mitk::DataNode::New
static Pointer New()