![]() |
ImFusion C++ SDK 4.4.0
|
#include <ImFusion/GUI/View.h>
Base interface for a rendering view (e.g. More...
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:
The generic interface to display datasets inside a View is setVisibleData(). The default implementation will use the DataDisplayHandler interface to determine if and 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:
You can optionally define a background color, as well as a rectangular border that should be rendered around the content.
Classes | |
| class | EventHandler |
| Interface to be used as base class for event handlers of Views. More... | |
| struct | BorderConfig |
| Record for specifying if and how to render a border frame surrounding the view. 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 GlView & | glView () const |
| Returns the underlying GlView. | |
| GlView & | glView () |
| 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::Viewport & | viewport () 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 BorderConfig & | borderConfig () 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 ImFusion::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 | |
| Configurable & | operator= (const Configurable &) |
| Configurable & | operator= (Configurable &&) noexcept |
| Public Member Functions inherited from ImFusion::SignalReceiver | |
| SignalReceiver ()=default | |
| Default constructor. | |
| SignalReceiver (const SignalReceiver &other) | |
| Copy constructor, does not copy any existing signal connections from other. | |
| SignalReceiver & | operator= (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 ImFusion::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 ImFusion::SignalReceiver | |
| void | disconnectAll () |
| Disconnects all existing connections. | |
Protected Attributes | |
| std::unique_ptr< GlView > | m_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 ImFusion::Configurable | |
| std::vector< Param > | m_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 list of datasets that should be shown in this view. | |
| const DataList & | visibleData () const |
| Returns the list of currently displayed datasets. | |
| bool | showData (Data *data) |
| Appends the given dataset to the list of visible datasets. | |
| void | hideData (const Data *data) |
| Removes the given dataset from the list of visible datasets. | |
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< EventHandler > | removeEventHandler (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< ViewOverlay > | removeOverlay (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 (const ViewObject *object) |
| Remove the given ViewObject from this view unregistering both the GlObject renderer and the event handler. | |
| std::vector< ViewObject * > | objects () const |
| Returns all currently registered ViewObjects of this view. | |
Original access API for compatibility with derived class InteractiveView | |
| const GlView * | view () const |
| GlView * | view () |
| Return associated GlView object. | |
|
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 ImFusion::CurveEditorView, and ImFusion::PlotView.
| void ImFusion::GUI::View::setVisibleData | ( | const DataList & | data | ) |
Set the list of datasets 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 visible data is different from the current visibleData() signalVisibleDataChanged is emitted.
| const DataList & ImFusion::GUI::View::visibleData | ( | ) | const |
Returns the list of currently displayed datasets.
| bool ImFusion::GUI::View::showData | ( | Data * | data | ) |
Appends the given dataset to the list of visible datasets.
| void ImFusion::GUI::View::hideData | ( | const Data * | data | ) |
Removes the given dataset from the list of visible datasets.
| void ImFusion::GUI::View::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.
| void ImFusion::GUI::View::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.
|
virtual |
Remove a previously added overlay from this view again.
Reimplemented in ImFusion::InteractiveView.
|
virtual |
Will add the underlying GlObject to the GlView and register the event handler.
This function is in the GUI layer and registers a GUI::ViewObject (combining a GlObject renderer with event handling logic) with a GUI::View (hosting a GlView for rendering and dispatching input events). There is a similar function GlView::addObject() in the GL layer that you can use in case you have a plain/unwrapped GlObject without event handling.
Reimplemented in ImFusion::InteractiveView.
|
virtual |
Remove the given ViewObject from this view unregistering both the GlObject renderer and the event handler.
Reimplemented in ImFusion::InteractiveView.
| std::vector< ViewObject * > ImFusion::GUI::View::objects | ( | ) | const |
Returns all currently registered ViewObjects of this view.
|
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 ImFusion::ImageView2D.
|
virtual |
Sets the area where this view is drawn in render() wrt. the attached framebuffer.
Reimplemented in ImFusion::GUI::SliceView, and ImFusion::InteractiveView.
|
virtual |
Sets the BorderConfig struct defining if and how to render a border frame surrounding the view.
Reimplemented in ImFusion::GUI::SliceView.
|
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:
| void ImFusion::GUI::View::setDataDisplayDispatcher | ( | std::shared_ptr< DataDisplayDispatcher > | ddd | ) |
Sets a common DataDisplayDispatcher so that it can be shared across views.
|
protectedvirtual |
Dispatch event to all known ViewOverlays considering m_mouseEventFocusObject and m_touchEventFocusObject.
Reimplemented in ImFusion::InteractiveView.
|
protectedvirtual |
Dispatch event to all known ViewObjects considering m_mouseEventFocusObject and m_touchEventFocusObject.
Reimplemented in ImFusion::InteractiveView.
|
protectedvirtual |
Dispatch event to all known View::EventHandlers considering m_mouseEventFocusObject and m_touchEventFocusObject.
Reimplemented in ImFusion::InteractiveView.
|
protected |
Update the internal bookkeeping of "focus" event handlers:
|
protected |
Checks if the object target should receive the given event based on the event type and current "focus" object.
|
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 ImFusion::GUI::SliceView, and ImFusion::ImageView2D.
|
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 ImFusion::ImageView2D.
|
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.
|
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.