ImFusion SDK 4.3

User interaction with views and overlays. More...

+ Collaboration diagram for Interactions:

Detailed Description

User interaction with views and overlays.

Interaction is the top-most class for handling user interaction with views and overlays. It is the base class for ViewInteraction and OverlayInteraction, and contains methods for creating and evaluating context menus as well as handing user inputs such as mouse events. Each InteractiveView has a ViewInteraction object for handing its interactions, and similarly, every InteractiveOverlay has an OverlayInteraction.

DisplayWidget filters all the QEvents inside the display area and sends them to corresponding InteractiveViews based on the mouse position and type of the event. sceneEvent method in InteractiveView receives the QEvent; the event is first sent to handleOverlayEvent method in ViewInteraction to check if it belongs to one of the overlays of that view. If the overlays do not accept the event then it will be passed to sceneEvent method in ViewInteraction. The QEvent is then processed by the sceneEvent method of ViewInteraction and changes are applied to the view.

Mouse Interactions

Standard view action types such as pan, zoom, rotate, etc. are defined in ViewActionType enum in the ViewInteraction header file.

// Basic action types applied on the views
enum ViewActionType {
PAN = 0, // Translation of camera in 2D/3D views
ZOOMSLICE = 1, // Zooming in 2D views
ROTATESLICE3D = 2, // 3D rotation of a slice in MPR views
ROTATESLICE2D = 3, // Rotation of 2D views inside their plane
SWEEPSLICE3D = 4, // Moving a MPR 2D slice along its third dimension
SWEEPSLICE2D = 5, // Changing the focus of SharedImageSet in a 2D view
ROTATE3D = 6, // Rotation of camera in 3D views
ZOOM3D = 7, // Zooming in 3D views
WINDOW = 8, // Changing the window and level of a view
BLEND = 9 // Changing the blend factor of a 2D view
};

A mapping between these actions and combination of a mouse button and keyboard modifiers {control, shift, alt} is defined in the base ViewInteraction class. This global mapping is used by all the 2D and 3D views and it can be modified either in settings dialog in run-time or by using the API methods defined in ViewInteraction class. Creating a custom interaction mapping can be done in a sub-class of ViewInteraction similar to the following code:

void MyViewInteraction::defineCustomInteractionMapping()
{
viewActionMapGlobal.clear();
addMappedViewAction(ViewActionType::PAN, Qt::MouseButton::RightButton, Qt::KeyboardModifier::NoModifier);
addMappedViewAction(ViewActionType::ZOOMSLICE, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier);
addMappedViewAction(ViewActionType::ROTATESLICE3D, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::ControlModifier);
addMappedViewAction(ViewActionType::ROTATESLICE2D, Qt::MouseButton::MiddleButton, Qt::KeyboardModifier::ControlModifier);
addMappedViewAction(ViewActionType::SWEEPSLICE3D, Qt::MouseButton::MiddleButton, Qt::KeyboardModifier::NoModifier);
addMappedViewAction(ViewActionType::SWEEPSLICE2D, Qt::MouseButton::MiddleButton, Qt::KeyboardModifier::NoModifier);
addMappedViewAction(ViewActionType::ROTATE3D, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier);
addMappedViewAction(ViewActionType::ZOOM3D, Qt::MouseButton::MiddleButton, Qt::KeyboardModifier::NoModifier);
addMappedViewAction(ViewActionType::WINDOW, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::ShiftModifier);
addMappedViewAction(ViewActionType::BLEND, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::AltModifier);
}

This mapping is used in the sceneEvent method of view interaction classes to apply desired changes to GlView of the InteractiveView.

Defining more specific interactions can be achieved by overriding the sceneEvent method in ViewInteraction and handling the QEvent passed to this method. The events can be handled similar to this example:

bool MyInteractionView2D::sceneEvent(QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *e = dynamic_cast<QMouseEvent*>(event);
m_dragging = false;
m_mouseDrag = e->button();
m_mousePX = e->pos().x();
m_mousePY = e->pos().y();
m_mouseDX = 0.0;
m_mouseDY = 0.0;
event->accept();
return true;
}
else if (event->type() == QEvent::MouseMove)
{
QMouseEvent *e = dynamic_cast<QMouseEvent*>(event);
if (e->buttons() != Qt::NoButton && !m_dragging)
{
m_dragging = true;
}
if (m_mouseDrag)
{
m_mouseDX = e->pos().x() - m_mousePX;
m_mouseDY = e->pos().y() - m_mousePY;
}
m_mousePX = e->pos().x();
m_mousePY = e->pos().y();
if (matchMappedActions(ViewActionType::PAN,(Qt::MouseButton)m_mouseDrag,e->modifiers()))
{
// Apply the panning transformation to the view's matrix
}
...
}
}

Context Menu

Additional actions can be added to the context menu of a view and be handled in overridden contextMenuEvaluate method of ViewInteraction. In order to keep the context menu functionality of the base interaction classes, call the contextMenuCreate and contextMenuEvaluate methods of the base class in your overridden methods. Adding a new action to view's context menu and handling it can be achieved similar to the following code:

bool MyInteractionView2D::createActions()
{
QActionGroup *actions = new QActionGroup(this);
actions->setExclusive(false);
QAction* a = new QAction(tr("Action1 Text"), actions);
m_actions["Action1"] = a;
a = new QAction(tr("Action2 Text"), actions);
m_actions["Action2"] = a;
connect(actions,SIGNAL(triggered(QAction*)),this,SLOT(contextMenuEvaluate(QAction*)));
}
bool MyInteractionView2D::contextMenuCreate()
{
// Assuming that this class is derived from InteractionView2D
InteractionView2D::contextMenuCreate(m);
m.addSeparator();
m.addAction(m_actions["Action1"]);
m.addAction(m_actions["Action2"]);
}
void MyInteractionView2D::contextMenuEvaluate(QAction* a)
{
if (a == 0)
return;
InteractionView2D::contextMenuEvaluate(a);
if (a == m_actions["Action1"])
{
// Handle Action1 here
}
else if (a == m_actions["Action2"])
{
// Handle Action2 here
}
}

Classes

class  Interaction
 Base interface class for view and overlay interactions. More...
 
class  InteractionPlotView
 Interaction class for plot view. More...
 
class  InteractionView3D
 Standard 2D/3D view interaction. More...
 
class  OverlayInteraction
 Base class for all overlay interactions. More...
 
class  ViewInteraction
 Base class for all view interactions. More...
 

Enumerations

enum  ViewActionType {
  PAN = 0 , ZOOMSLICE = 1 , ROTATESLICE3D = 2 , ROTATESLICE2D = 3 ,
  SWEEPSLICE3D = 4 , SWEEPSLICE2D = 5 , ROTATE3D = 6 , ZOOM3D = 7 ,
  WINDOW = 8 , BLEND = 9
}
 Basic actions which are applied on the views. More...
 

Enumeration Type Documentation

◆ ViewActionType

#include <ImFusion/GUI/ViewInteraction.h>

Basic actions which are applied on the views.

Enumerator
PAN 

Translation of camera in 2D/3D views.

ZOOMSLICE 

Zooming in 2D views.

ROTATESLICE3D 

3D rotation of a slice in MPR views

ROTATESLICE2D 

Rotation of 2D views inside their plane.

SWEEPSLICE3D 

Moving a MPR 2D slice along its third dimension.

SWEEPSLICE2D 

Changing the focus of SharedImageSet in a 2D view.

ROTATE3D 

Rotation of camera in 3D views.

ZOOM3D 

Zooming in 3D views.

WINDOW 

Changing the window and level of a view.

BLEND 

Changing the blend factor of a 2D view.

Search Tab / S to search, Esc to close