Interacting with the Display

Warning

The Display and annotations are currently only available when using the imfusion module inside the ImFusion Suite.

The imfusion.Display is the central widget in the ImFusion Suite that visualizes the loaded datasets. It consists of several imfusion.View which show the datasets in different perspectives or in different ways. The imfusion.Display instance can be accessed through the imfusion.ApplicationController. The following example makes all views visible, switches to different layout and shows the 3D view as the prominent view.

>>> display = imfusion.app.display()
>>> for view in display.views():
...     view.visible = True
>>> display.layout_mode = imfusion.LayoutMode.LAYOUT_FOCUS_PLUS_STACK
>>> display.focus_view = display.views3d()[0]

Creating Annotations

With the imfusion.Display it possible to add annotations such as lines or circles to a dataset. This functionality is available through the imfusion.AnnotationModel, which holds all annotations similar to the imfusion.DataModel. To create a line imfusion.Annotation:

>>> am = imfusion.app.annotationModel()
>>> annotation = am.createAnnotation(imfusion.AnnotationType.LINE)
>>> annotation.color = (1.0, 0.0, 0.0)  # make it red
>>> annotation.points = [(0.0, 0.0, 0.0), (100.0, 100.0, 0.0)]

The last command assigns the points of the line in world coordinates. Depending on the type of the imfusion.Annotation, you will need a certain amount of points. You can query how many points an annotation supports through the imfusion.Annotation.max_points property.

The Python interface currently provides the following types:

  • imfusion.AnnotationType.CIRCLE

  • imfusion.AnnotationType.LINE

  • imfusion.AnnotationType.POINT

  • imfusion.AnnotationType.PLOY_LINE

  • imfusion.AnnotationType.RECTANGLE

It is also possible to set the points of an annotation interactively on the display:

>>> annotation = am.create_annotation(imfusion.AnnotationType.LINE)
>>> annotation.start_editing()

You can register a callback which will be called once the user finished editing the annotation (i.e. when it’s completely defined):

>>> def callback():
...     printf("All points are defined:", a.points)
>>> a.on_editing_finished(callback)

Ideally you would add the callback before calling imfusion.Annotation.start_editing(). Alternatively, you can also listen for all changes to imfusion.Annotation.points:

>>> def callback():
...     printf("Points changed to", a.points)
>>> a.on_points_changed(callback)