Computer Assited Medical Intervention Tool Kit  version 5.0
camitk::Viewer Class Referenceabstract

Viewer is an abstract class that is the base class for all viewers. More...

#include <Viewer.h>

+ Inheritance diagram for camitk::Viewer:
+ Collaboration diagram for camitk::Viewer:

Public Types

enum  ViewerType { EMBEDDED, DOCKED }
 

Signals

void selectionChanged ()
 this signal is emitted when the current selection was changed by the viewer More...
 

Public Member Functions

QStringList getComponents ()
 get the list of Component class manages by this viewer (default is set to "Component", i.e. More...
 
QString getDescription () const
 get the name of the viewer More...
 
QDockWidget * getDockWidget ()
 Get the QDockWidget* where this viewer is currently docked (or nullptr if it is not docked anywhere or if the viewer is of type EMBEDDED) More...
 
QLayout * getEmbedder ()
 Get the QLayout* where this viewer is currently embedded (or nullptr if it is not embedded anywhere or if the viewer is of type DOCKED) More...
 
virtual QPixmap getIcon ()
 get the viewer icon More...
 
virtual QMenu * getMenu ()
 get the viewer menu (returns nullptr by default, i.e. there are no default edit menu) More...
 
QString getName () const
 get the name of the viewer More...
 
virtual QObject * getPropertyObject ()
 get the viewer property object (returns nullptr by default, i.e. there are no property to edit) More...
 
virtual QToolBar * getToolBar ()
 get the viewer toolbar (returns nullptr by default, i.e. there are no default toolbar) More...
 
bool getToolBarVisibility ()
 get the current value of the toolbar visibility More...
 
ViewerType getType ()
 get the viewer layout More...
 
 Q_ENUM (ViewerType) Viewer(QString name
 default constructor More...
 
virtual void refresh (Viewer *whoIsAsking=nullptr)=0
 refresh the view (can be interesting to know which other viewer is calling this) More...
 
bool setDockWidget (QDockWidget *)
 If the viewer type is DOCKED, dock the widget inside the given dock widget (do nothing if the type is EMBEDDED or if the viewer has already been docked before) Note that once set, the dock widget cannot be modified. More...
 
bool setEmbedder (QLayout *)
 If the viewer type is EMBEDDED, embed the viewer widget in the given layout (do nothing if the type is DOCKED) Note that you can call this method any time you want to move the viewer's widget to another layout (but there is only one embedder at a time) More...
 
void setToolBarVisibility (bool)
 set the visibility of the toolbar in the main window (true by default). More...
 
void setType (ViewerType)
 set the viewer layout (the type can be changed dynamically to fit the developer's purpose) More...
 
void setVisible (bool)
 set the visibility of the viewer (show or hide its widget) More...
 
virtual ~Viewer () override
 default destructor More...
 

Public Attributes

ViewerType type = EMBEDDED)
 this viewer's layout More...
 

Protected Member Functions

void clearSelection ()
 clear the selection More...
 
virtual QWidget * getWidget ()=0
 get the viewer widget. More...
 
void selectionChanged (Component *comp)
 the selection has changed to be just one comp More...
 
void selectionChanged (ComponentList &compSet)
 The selection has changed to the given ComponentList. More...
 
void setComponents (QStringList)
 set the list of component class names managed by this viewer More...
 
void setDescription (QString)
 set the viewer's description More...
 
void setIcon (QPixmap icon)
 set the default icon for the viewer extension More...
 

Private Attributes

QStringList components
 list of Component class name managed by this viewer More...
 
QString description
 description of the viewer More...
 
QDockWidget * dockWidget
 if layout is of type DOCKED, then this is the widget where the viewer's widget is docked More...
 
ViewerDockStyledockWidgetStyle
 the style for the dock widget More...
 
QLayout * embedder
 if layout is of type EMBEDDED, this is the layout where the viewer's widget is embedded in More...
 
QPixmap icon
 the Viewer pixmap icon More...
 
QString name
 current viewer's name More...
 
bool toolbarVisibility
 the current toolbar visibility More...
 

Detailed Description

Viewer is an abstract class that is the base class for all viewers.

There are two types of viewers:

  • the embedded viewer (their widgets are inside a given layout), this is the default type
  • the docked viewer (their widgets are inside a dock widget).

The type of a viewer can be changed at any time using setType(..). To define where is the viewer embedded or docked use setEmbedder(..) or setDockWidget(..)

A viewer can embed other viewers in its own widget. Example of viewer are: Explorer, PropertyExplorer, MedicalImageViewer (which embed the default InteractiveGeometryViewer and default InteractiveSliceViewers).

A viewer can be added to MainWindow either in the dock or the central viewer (depending on its type). MainWindow will include its menu in the "View" menu and its toolbar in the application toolbar.

The default viewed component are set so that the viewer is updated every time the current component selection is modified.

If your viewer does not view components (for instance, in the very rare/special case it views actions), then you need to call the setComponents(...) method with an empty list. An empty list means that this viewer is going to be also notified/refreshed every time the current selected action is changed (i.e., anytime an action is triggered)

In the scope of an Application, a viewer should be registered if you want to use it to display component facets. Registered viewers are going to be refreshed automatically when Application::refresh() is called or when a new top level component is opened/closed.

The viewer's icon is displayed inside the dock window.

Unregistered viewers are managed independently of the CamiTK Application logic. In this case it should be managed separately and it is not connected to the automatic refresh chain. This is a special (rare) use case. If you think this is what you need, then you will have to programmatically/specifically manage the content of the viewer and its refresh logic.

The viewer's property object can be used to manage the properties of the viewer (for instance background colors or other display options). (camitk-imp for instance presents the viewer properties in the setting dialog)

The viewer's menu should present the properties in a QMenu to enable the user to easily modify the viewer properties (camitk-imp for instance shows the viewer menus in the application "View" menu)

A viewer toolbar is meant to be displayed in the main window toolbar area when the viewer's widget is visible (in a Dock or as the central widget). The viewer toolbar is visible by default. If you don't want to show the viewer toolbar in your main window, even if the viewer's widget is visible, set its visibility to false.

Using viewers

In a viewer extension, the default behaviour is to have (at least) one instance of the new Viewer inheriting class. It is very easy to access this instance with Application::getViewer()

E.g. if FooBarViewer inherits from the Viewer class, then one default instance of the class, called "Foo Bar Viewer", is available when the extension is loaded.

To get the default FooBarViewer instance, use Application::getViewer("Foo Bar Viewer").

One simple way of checking that a viewer extension is available, is to check the return value of Application::getViewer(...), e.g. some code inside a MainWindow inherited class constructor:

#include <FooBarViewer.h>
#include <Log.h>
...
FooBarViewer* fooBarViewer = dynamic_cast<FooBarViewer*>(Application::getViewer("Foo Bar Viewer"));
if (fooBarViewer != nullptr) {
// everything is ok, the FooBar viewer extension is available, add it to the right docker, not visibile by default
addDockViewer(Qt::RightDockWidgetArea, fooBarViewer);
showDockViewer(fooBarViewer, false);
}
else {
CAMITK_ERROR(tr("Cannot find \"Foo Bar Viewer\". This viewer is mandatory for running this application."))
// may be you wanted to create a new instance of FooBarViewer, just see below
}
Note
If your action or component requires a specific viewer, you need to add the following argument to the camitk_extension(..) macro of your extension's CMakeLists.txt:
camitk_extension(...
NEEDS_VIEWER_EXTENSION foobarviewer
...
)
See also
Application::getViewer()

Creating new viewer instances

It is very easy to create a new instance of a given viewer type (of a loaded viewer extension): just use the viewer extension factory. See Application::getNewViewer().

The following example creates a new instance of the InteractiveGeometryViewer viewer called "My Extra 3D Viewer" and embed it in a specific layout:

...
QVBoxLayout* myLayout;
...
InteractiveGeometryViewer* extra3DViewer = dynamic_cast<InteractiveGeometryViewer*>(Application::getNewViewer("My Extra 3D Viewer", "InteractiveGeometryViewer"));
extra3DViewer->toggleLogo(false); // for instance: remove the CamiTK logo
// any other InteractiveGeometryViewer customization/tweaking goes here
// embed the new viewer in custom layout (e.g. an Action widget)
extra3DViewer->setEmbedder(ui.illustrationLayout);
...
// add a prop to the 3D viewer
extra3DViewer->getRendererWidget()->addProp(myVTKActor);
Note
Application::getNewViewer() does not register the viewer's new instance automatically. Use Application::registerViewer() to register your viewer if you want it to be refreshed automatically when Application::refresh() is called (e.g., when a new component is opened or closed)
See also
ReorientImage gives an example of embeding an InteractiveGeometryViewer in an action widget
Application::getNewViewer()

Creating a new viewer extension

The simplest way to create a new viewer extension is to run camitk-wizard to obtain a working skeleton. Feel free to check the two examples provided in the tutorial CEP (as well as the code of the viewer extensions provided by the SDK).

Member Enumeration Documentation

◆ ViewerType

describes where this viewer should appear

Enumerator
EMBEDDED 

this viewer is meant to be embedded inside a layout (of another viewer or widget), use embedIn(..) to set the layout it is embedded in (this is the default viewer type)

DOCKED 

this viewer is meant to be docked, use dockIn() to get the dock widget

Constructor & Destructor Documentation

◆ ~Viewer()

camitk::Viewer::~Viewer ( )
overridevirtual

default destructor

References description.

Member Function Documentation

◆ clearSelection()

void camitk::Viewer::clearSelection ( )
protected

clear the selection

◆ getComponents()

QStringList camitk::Viewer::getComponents ( )

get the list of Component class manages by this viewer (default is set to "Component", i.e.

all type of Component)

Referenced by camitk::Application::getViewers().

+ Here is the caller graph for this function:

◆ getDescription()

QString camitk::Viewer::getDescription ( ) const
inline

get the name of the viewer

References description.

Referenced by camitk::Application::registerViewer().

+ Here is the caller graph for this function:

◆ getDockWidget()

QDockWidget * camitk::Viewer::getDockWidget ( )

Get the QDockWidget* where this viewer is currently docked (or nullptr if it is not docked anywhere or if the viewer is of type EMBEDDED)

Referenced by ImageLutWidget::drawGraphics().

+ Here is the caller graph for this function:

◆ getEmbedder()

QLayout * camitk::Viewer::getEmbedder ( )

Get the QLayout* where this viewer is currently embedded (or nullptr if it is not embedded anywhere or if the viewer is of type DOCKED)

Referenced by ImpMainWindow::updateViewMenu().

+ Here is the caller graph for this function:

◆ getIcon()

QPixmap camitk::Viewer::getIcon ( )
virtual

get the viewer icon

Referenced by ImpMainWindow::updateViewMenu().

+ Here is the caller graph for this function:

◆ getMenu()

virtual QMenu* camitk::Viewer::getMenu ( )
inlinevirtual

get the viewer menu (returns nullptr by default, i.e. there are no default edit menu)

Reimplemented in camitk::InteractiveViewer, MedicalImageViewer, and Explorer.

Referenced by ImpMainWindow::updateViewMenu().

+ Here is the caller graph for this function:

◆ getName()

QString camitk::Viewer::getName ( ) const
inline

◆ getPropertyObject()

virtual QObject* camitk::Viewer::getPropertyObject ( )
inlinevirtual

get the viewer property object (returns nullptr by default, i.e. there are no property to edit)

Reimplemented in camitk::InteractiveViewer, MedicalImageViewer, and PropertyExplorer.

Referenced by ImpMainWindow::editSettings().

+ Here is the caller graph for this function:

◆ getToolBar()

virtual QToolBar* camitk::Viewer::getToolBar ( )
inlinevirtual

get the viewer toolbar (returns nullptr by default, i.e. there are no default toolbar)

Reimplemented in camitk::InteractiveViewer, MedicalImageViewer, and BitmapViewer.

◆ getToolBarVisibility()

bool camitk::Viewer::getToolBarVisibility ( )

get the current value of the toolbar visibility

◆ getType()

Viewer::ViewerType camitk::Viewer::getType ( )

get the viewer layout

Referenced by ImpMainWindow::updateViewMenu().

+ Here is the caller graph for this function:

◆ getWidget()

virtual QWidget* camitk::Viewer::getWidget ( )
protectedpure virtual

get the viewer widget.

this method is protected and to be redefined in the inheriting class.

Note
to show the viewer's widget in the GUI, use dockIn() or embedIn(...) to set where the viewer is displayed

Implemented in camitk::InteractiveViewer, MedicalImageViewer, ActionViewer, PropertyExplorer, Explorer, FrameExplorer, BitmapViewer, and ActionStateViewer.

◆ Q_ENUM()

camitk::Viewer::Q_ENUM ( ViewerType  )

default constructor

◆ refresh()

virtual void camitk::Viewer::refresh ( Viewer whoIsAsking = nullptr)
pure virtual

refresh the view (can be interesting to know which other viewer is calling this)

Implemented in camitk::InteractiveViewer, PropertyExplorer, Explorer, and BitmapViewer.

◆ selectionChanged [1/3]

void camitk::Viewer::selectionChanged ( )
signal

this signal is emitted when the current selection was changed by the viewer

Referenced by MedicalImageViewer::getWidget(), and MedicalImageViewer::synchronizeSelection().

+ Here is the caller graph for this function:

◆ selectionChanged() [2/3]

void camitk::Viewer::selectionChanged ( Component comp)
protected

the selection has changed to be just one comp

◆ selectionChanged() [3/3]

void camitk::Viewer::selectionChanged ( camitk::ComponentList compSet)
protected

The selection has changed to the given ComponentList.

This method updates the Component::selection and emit the modified signal. This method should be called by the inheriting class which can select Components (e.g.: Explorer).

◆ setComponents()

void camitk::Viewer::setComponents ( QStringList  components)
protected

set the list of component class names managed by this viewer

Note
Default is set to "Component" (all type of components)

References camitk::Component::setSelected().

Referenced by ActionStateViewer::ActionStateViewer(), ActionViewer::ActionViewer(), BitmapViewer::BitmapViewer(), and InteractiveSliceViewer::InteractiveSliceViewer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDescription()

void camitk::Viewer::setDescription ( QString  description)
protected

set the viewer's description

Referenced by ActionViewer::ActionViewer(), BitmapViewer::BitmapViewer(), Explorer::Explorer(), FrameExplorer::FrameExplorer(), InteractiveGeometryViewer::InteractiveGeometryViewer(), InteractiveSliceViewer::InteractiveSliceViewer(), MedicalImageViewer::MedicalImageViewer(), and PropertyExplorer::PropertyExplorer().

+ Here is the caller graph for this function:

◆ setDockWidget()

bool camitk::Viewer::setDockWidget ( QDockWidget *  dockWidget)

If the viewer type is DOCKED, dock the widget inside the given dock widget (do nothing if the type is EMBEDDED or if the viewer has already been docked before) Note that once set, the dock widget cannot be modified.

The dock widget object's name, window title and icons are modified using the viewer's name and icon

Returns
true if the docking operation was successful

◆ setEmbedder()

bool camitk::Viewer::setEmbedder ( QLayout *  embedder)

If the viewer type is EMBEDDED, embed the viewer widget in the given layout (do nothing if the type is DOCKED) Note that you can call this method any time you want to move the viewer's widget to another layout (but there is only one embedder at a time)

Returns
true if the embedding operation was successful

Referenced by camitk::MainWindow::addDockViewer(), and ReorientImage::initDialog().

+ Here is the caller graph for this function:

◆ setIcon()

void camitk::Viewer::setIcon ( QPixmap  icon)
protected

set the default icon for the viewer extension

References camitk::Component::setSelected().

Referenced by ActionViewer::ActionViewer(), Explorer::Explorer(), FrameExplorer::FrameExplorer(), and PropertyExplorer::PropertyExplorer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setToolBarVisibility()

void camitk::Viewer::setToolBarVisibility ( bool  toolbarVisibility)

set the visibility of the toolbar in the main window (true by default).

If the visibility is set to false, the next call to setCentralViewer(..) or addDockViwer(...) will remove it

Referenced by MedicalImageViewer::setToolbarAutoVisibility(), and MedicalImageViewer::updateLayout().

+ Here is the caller graph for this function:

◆ setType()

void camitk::Viewer::setType ( Viewer::ViewerType  type)

set the viewer layout (the type can be changed dynamically to fit the developer's purpose)

◆ setVisible()

void camitk::Viewer::setVisible ( bool  visible)

set the visibility of the viewer (show or hide its widget)

Member Data Documentation

◆ components

QStringList camitk::Viewer::components
private

list of Component class name managed by this viewer

◆ description

QString camitk::Viewer::description
private

description of the viewer

◆ dockWidget

QDockWidget* camitk::Viewer::dockWidget
private

if layout is of type DOCKED, then this is the widget where the viewer's widget is docked

◆ dockWidgetStyle

ViewerDockStyle* camitk::Viewer::dockWidgetStyle
private

the style for the dock widget

◆ embedder

QLayout* camitk::Viewer::embedder
private

if layout is of type EMBEDDED, this is the layout where the viewer's widget is embedded in

◆ icon

QPixmap camitk::Viewer::icon
private

the Viewer pixmap icon

◆ name

QString camitk::Viewer::name
private

◆ toolbarVisibility

bool camitk::Viewer::toolbarVisibility
private

the current toolbar visibility

◆ type

ViewerType camitk::Viewer::type = EMBEDDED)

this viewer's layout


The documentation for this class was generated from the following files:
InteractiveGeometryViewer.h
InteractiveGeometryViewer
Interactive 3D viewer.
Definition: InteractiveGeometryViewer.h:56
Log.h
camitk::Application::getViewer
static Viewer * getViewer(QString name)
get the pointer to a registered viewer given its name
Definition: Application.cpp:882
CAMITK_ERROR
#define CAMITK_ERROR(MSG)
Log for error verbosity (the minimum verbosity) Will always appear.
Definition: Log.h:276
camitk::InteractiveViewer::toggleLogo
void toggleLogo(bool)
show/hide the logo at the bottom right corner
Definition: InteractiveViewer.cpp:2013
camitk::Application::getNewViewer
static Viewer * getNewViewer(QString name, QString className)
instantiate a new viewer of the given name and given class name (Viewer inheriting class).
Definition: Application.cpp:960