ImFusion SDK 4.3
View Class Reference

#include <ImFusion/GUI/View.h>

Base interface for a rendering view (e.g. More...

+ Inheritance diagram for View:

Detailed Description

Base interface for a rendering view (e.g.

single anatomical plane) that can be hosted inside a Display.

A View takes care of rendering a scene consisting of any number of compatible datasets, scene objects and overlays, and of receiving and dispatching incoming input events to the individual elements. This is achieved by combining the following interfaces:

  • It wraps one GlView that implements the actual rendering of the datasets using OpenGL.
  • Any number of ViewObject instances that describe additional objects of the rendered scene. In contrast to the plain GlObject that can be attached directly to the GlView, the ViewObject supports attaching input event handlers so that the user can interact with the scene object.
  • Any number of ViewOverlay instances that are rendered on top of the scene. They reside in viewport space and are automatically layouted wrt. to their assigned anchor in a fashion that they don't overlap.

The generic interface to display datasets inside a View is setVisibleData(). The default implementation will use the DataDisplayHandler interface to determine if and how how dataset can be is visualized in a concrete view type. A DataDisplayHandler will then usually forward to member functions of the concrete GlView or create a suitable GlObject renderer instance and register it with the view.

Usually, the viewport() size of a View is automatically determined by the layouting algorithm of the parent Display from which it also receives the input events. Incoming input events are dispatched in the following logic until one EventResult indicates to stop propagation:

  1. all registered overlays() in reverse order
  2. all registered objects() in reverse order
  3. all registered eventHandlers() in original order

You can optionally define a background color, as well as a rectangular border that should be rendered around the content.

Classes

struct  BorderConfig
 Record for specifying if and how to render a border frame surrounding the view. More...
 
class  EventHandler
 Interface to be used as base class for event handlers of Views. More...
 

Public Member Functions

 View (std::unique_ptr< GlView > glView)
 Instantiate a new View using the given GlView as renderer; glView must not be null.
 
virtual void render ()
 Will render the view into the viewport() of the current framebuffer by drawing the optional background color, the optional border, the underlying GlView, and finally all overlays().
 
const GlViewglView () const
 Returns the underlying GlView.
 
GlViewglView ()
 Returns the underlying GlView.
 
virtual void setViewport (const GL::Viewport &rect)
 Sets the area where this view is drawn in render() wrt. the attached framebuffer.
 
const GL::Viewportviewport () const
 Returns the area where this view is drawn in render() wrt. the attached framebuffer.
 
bool isVisible () const
 Returns whether this view has a non-zero viewport and can therefore be considered visible.
 
std::optional< vec3 > backgroundColor () const
 Returns the optional background color used to clear the viewport before rendering anything.
 
void setBackgroundColor (std::optional< vec3 > value)
 Sets the optional background color used to clear the viewport before rendering anything.
 
const BorderConfigborderConfig () const
 Returns the BorderConfig struct defining if and how to render a border frame surrounding the view.
 
virtual void setBorderConfig (const BorderConfig &value)
 Sets the BorderConfig struct defining if and how to render a border frame surrounding the view.
 
bool showsOverlays () const
 Returns the flag whether to show overlays or not.
 
void setShowOverlays (bool value)
 Sets the flag whether to show overlays or not.
 
void setWatermark (const SharedImage &image)
 Sets a watermark image to be rendered on top of the view.
 
virtual EventResult handleInputEvent (const InputEvent &event)
 Called by the parent Display if a user input event has happened on this view.
 
void setDataDisplayDispatcher (std::shared_ptr< DataDisplayDispatcher > ddd)
 Sets a common DataDisplayDispatcher so that it can be shared across views.
 
const DataDisplayDispatcher * dataDisplayDispatcher () const
 Returns the DataDisplayDispatcher used by this view.
 
- Public Member Functions inherited from Configurable
virtual void configure (const Properties *p)
 Configure this object instance by de-serializing the given Properties.
 
virtual void configuration (Properties *p) const
 Serialize the current object configuration into the given Properties object.
 
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 
- Public Member Functions inherited from SignalReceiver
 SignalReceiver ()=default
 Default constructor.
 
 SignalReceiver (const SignalReceiver &other)
 Copy constructor, does not copy any existing signal connections from other.
 
SignalReceiveroperator= (SignalReceiver rhs)
 Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs.
 
virtual ~SignalReceiver ()
 Virtual destructor disconnects from all connected signals.
 

Public Attributes

Signal signalUpdateRequested
 Emitted when this view or one of its overlays has become outdated and needs to be re-rendered.
 
Signal< const DataList &, const DataList & > signalVisibleDataChanged
 Emitted when visibleData() has changed.
 
- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 

Protected Member Functions

virtual EventResult dispatchToViewOverlays (const InputEvent &event)
 Dispatch event to all known ViewOverlays considering m_mouseEventFocusObject and m_touchEventFocusObject.
 
virtual EventResult dispatchToViewObjects (const InputEvent &event)
 Dispatch event to all known ViewObjects considering m_mouseEventFocusObject and m_touchEventFocusObject.
 
virtual EventResult dispatchToViewEventHandlers (const InputEvent &event)
 Dispatch event to all known View::EventHandlers considering m_mouseEventFocusObject and m_touchEventFocusObject.
 
void updateEventFocus (const InputEvent &event, const void *newTarget)
 Update the internal bookkeeping of "focus" event handlers:
 
bool filterEventFocus (const InputEvent &event, const void *target) const
 Checks if the object target should receive the given event based on the event type and current "focus" object.
 
virtual void showDataImpl (Data *data)
 Override this function to implement custom logic whenever a dataset is added to the list of visible data.
 
virtual void hideDataImpl (const Data *data)
 Override this function to implement custom logic whenever a dataset is removed from the list of visible data.
 
- Protected Member Functions inherited from SignalReceiver
void disconnectAll ()
 Disconnects all existing connections.
 

Protected Attributes

std::unique_ptr< GlViewm_glView
 
std::unique_ptr< ViewOverlayLayouter > m_overlayLayouter
 
std::vector< std::unique_ptr< EventHandler > > m_eventHandlers
 
std::vector< std::unique_ptr< ViewOverlay > > m_overlays
 
std::vector< ViewObject * > m_objects
 
DataList m_visibleData
 
GL::Viewport m_viewport
 
const void * m_mouseEventFocusObject = nullptr
 Pointer to the event receiver that shall receive MouseEvent::Type::Move events exclusively.
 
const void * m_touchEventFocusObject = nullptr
 Pointer to the event receiver that shall receive TouchEvent::Type::Update events exclusively.
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Setting the shown datasets in a generic fashion

virtual bool acceptsData (const Data *data) const
 Returns whether this view is capable of displaying the given data.
 
void setVisibleData (const DataList &data)
 Set the data that should be shown in this view.
 
const DataListvisibleData () const
 Returns a list of the currently displayed data.
 
bool showData (Data *data)
 Appends the given Data instance to the list of visible data.
 
void hideData (const Data *data)
 Removes the given Data instance to the list of visible data.
 

Configure the set of input event handlers reacting to user inputs

void setEventHandlers (std::vector< std::unique_ptr< EventHandler > > eventHandlers)
 Replace all existing EventHandlers with the ones in eventHandlers.
 
void addEventHandler (std::unique_ptr< EventHandler > eventHandler, int where=-1)
 Add an EventHandler at the given position (default is at the end).
 
std::unique_ptr< EventHandlerremoveEventHandler (EventHandler *interaction)
 Delete the given interaction, if it exists. Note: This will make the pointer invalid.
 
std::vector< EventHandler * > eventHandlers () const
 Returns all view interactions of this view.
 
template<typename T>
T * findEventHandler () const
 Returns the first EventHandler that dynamic_casts to T, or nullptr if no such EventHandler exists.
 

Configure the set of overlays rendered on top of this view

void addOverlay (std::unique_ptr< ViewOverlay > overlay, ViewOverlay::Anchor anchor, int position=-1)
 Inserts overlay into the list of overlays of this view at position of the given anchor.
 
virtual std::unique_ptr< ViewOverlayremoveOverlay (ViewOverlay *overlay)
 Remove a previously added overlay from this view again.
 
std::vector< ViewOverlay * > overlays () const
 Returns all InteractiveOverlays of this view.
 
void setOverlayAnchor (ViewOverlay *overlay, ViewOverlay::Anchor anchor)
 Set the anchor point to use for the given overlay.
 
void setOverlayLayoutDirection (ViewOverlay::Anchor anchor, ViewOverlay::LayoutDirection direction)
 Sets in which direction multiple overlays at one anchor are laid out.
 

Configure the set of interactive scene objects

virtual void addObject (ViewObject *object)
 Will add the underlying GlObject to the GlView and register the event handler.
 
virtual void removeObject (ViewObject *object)
 Remove the given ViewObject from this view.
 
std::vector< ViewObject * > objects () const
 Returns all ViewObjects of this view.
 

Original access API for compatibility with derived class InteractiveView

const GlViewview () const
 
GlViewview ()
 Return associated GlView object.
 

Member Function Documentation

◆ acceptsData()

virtual bool acceptsData ( const Data * data) const
virtual

Returns whether this view is capable of displaying the given data.

The default implementation checks whether there is any registered DataDisplayHandler that accepts this data for this type of view.

Reimplemented in CurveEditorView, and PlotView.

◆ setVisibleData()

void setVisibleData ( const DataList & data)

Set the data that should be shown in this view.

The default implementation relies on DataDisplayHandler interface to determine if and how a Data instance is visualized in this view. It is not an error if a particular Data type is not visualizable (i.e. acceptsData() returns false), however it will be silently dropped and not be part of visibleData() afterwards. If the new data is different from the current visibleData() the visibleDataChanged signal is emitted.

◆ addEventHandler()

void addEventHandler ( std::unique_ptr< EventHandler > eventHandler,
int where = -1 )

Add an EventHandler at the given position (default is at the end).

Note that events will be forwarded to the view interactions in the given order, and the first one accepting it will consume it. Thus, subsequent interactions will not receive events already taken care of.

◆ addOverlay()

void addOverlay ( std::unique_ptr< ViewOverlay > overlay,
ViewOverlay::Anchor anchor,
int position = -1 )

Inserts overlay into the list of overlays of this view at position of the given anchor.

A negative position indicates to insert it at the end of the list.

◆ removeOverlay()

virtual std::unique_ptr< ViewOverlay > removeOverlay ( ViewOverlay * overlay)
virtual

Remove a previously added overlay from this view again.

Reimplemented in InteractiveView.

◆ addObject()

virtual void addObject ( ViewObject * object)
virtual

Will add the underlying GlObject to the GlView and register the event handler.

Reimplemented in InteractiveView.

◆ removeObject()

virtual void removeObject ( ViewObject * object)
virtual

Remove the given ViewObject from this view.

Reimplemented in InteractiveView.

◆ render()

virtual void render ( )
virtual

Will render the view into the viewport() of the current framebuffer by drawing the optional background color, the optional border, the underlying GlView, and finally all overlays().

Reimplemented in ImageView2D.

◆ view()

const GlView * view ( ) const
inline

Return associated GlView object

◆ setViewport()

virtual void setViewport ( const GL::Viewport & rect)
virtual

Sets the area where this view is drawn in render() wrt. the attached framebuffer.

Reimplemented in SliceView, and InteractiveView.

◆ setBorderConfig()

virtual void setBorderConfig ( const BorderConfig & value)
virtual

Sets the BorderConfig struct defining if and how to render a border frame surrounding the view.

Reimplemented in SliceView.

◆ handleInputEvent()

virtual EventResult handleInputEvent ( const InputEvent & event)
virtual

Called by the parent Display if a user input event has happened on this view.

The default implementation will forward the event to the sub-objects in the following order:

◆ setDataDisplayDispatcher()

void setDataDisplayDispatcher ( std::shared_ptr< DataDisplayDispatcher > ddd)

Sets a common DataDisplayDispatcher so that it can be shared across views.

Note
Normally, you do not need to call this function manually because Display::addView() will do it for you.

◆ dispatchToViewOverlays()

virtual EventResult dispatchToViewOverlays ( const InputEvent & event)
protectedvirtual

Dispatch event to all known ViewOverlays considering m_mouseEventFocusObject and m_touchEventFocusObject.

Reimplemented in InteractiveView.

◆ dispatchToViewObjects()

virtual EventResult dispatchToViewObjects ( const InputEvent & event)
protectedvirtual

Dispatch event to all known ViewObjects considering m_mouseEventFocusObject and m_touchEventFocusObject.

Reimplemented in InteractiveView.

◆ dispatchToViewEventHandlers()

virtual EventResult dispatchToViewEventHandlers ( const InputEvent & event)
protectedvirtual

Dispatch event to all known View::EventHandlers considering m_mouseEventFocusObject and m_touchEventFocusObject.

Reimplemented in InteractiveView.

◆ updateEventFocus()

void updateEventFocus ( const InputEvent & event,
const void * newTarget )
protected

Update the internal bookkeeping of "focus" event handlers:

  • If event is a mouse press event, m_mouseEventFocusObject is set to newTarget.
  • If event is a mouse release event, m_mouseEventFocusObject is set to nullptr.
  • If event is a touch begin event, m_touchEventFocusObject is set to newTarget.
  • If event is a touch end event, m_touchEventFocusObject is set to nullptr.
    See also
    filterEventFocus()

◆ filterEventFocus()

bool filterEventFocus ( const InputEvent & event,
const void * target ) const
protected

Checks if the object target should receive the given event based on the event type and current "focus" object.

  • Returns true if current focus object is nullptr or matches target.
  • Returns true if event is not a mouse-move or touch-update event.
  • Returns false if event is a mouse-move or touch-update event and target does not match the current focus object.
    See also
    updateEventFocus()

◆ showDataImpl()

virtual void showDataImpl ( Data * data)
protectedvirtual

Override this function to implement custom logic whenever a dataset is added to the list of visible data.

The default implementation will call DataDisplayDispatcher::show() and add data to m_visibleData.

Reimplemented in SliceView, and ImageView2D.

◆ hideDataImpl()

virtual void hideDataImpl ( const Data * data)
protectedvirtual

Override this function to implement custom logic whenever a dataset is removed from the list of visible data.

The default implementation will call DataDisplayDispatcher::hide() and remove data to m_visibleData.

Reimplemented in ImageView2D.

Member Data Documentation

◆ m_mouseEventFocusObject

const void* m_mouseEventFocusObject = nullptr
protected

Pointer to the event receiver that shall receive MouseEvent::Type::Move events exclusively.

The default implementation will set this to any object/overlay/interaction that handles (EventResult::stopPropagation == true) a MouseButtonPress event. The default implementation will reset this to nullptr on any MouseEvent::Type::Release event.

◆ m_touchEventFocusObject

const void* m_touchEventFocusObject = nullptr
protected

Pointer to the event receiver that shall receive TouchEvent::Type::Update events exclusively.

The default implementation will set this to any object/overlay/interaction that handles (EventResult::stopPropagation == true) a TouchBegin event. The default implementation will reset this to nullptr on any TouchEvent::Type::End or TouchEvent::Type::Cancel event.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close