Computer Assisted Medical Intervention Tool Kit  version 5.2
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 }
 describes where this viewer should appear More...
 

Signals

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

Public Member Functions

*get the list of Component class manages by this viewer *default is set to i e all type of Component *QStringList getComponentClassNames ()
 
QString getDescription () const
 get the name of the viewer More...
 
virtual 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...
 
virtual 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 PropertyObjectgetPropertyObject ()
 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...
 
virtual 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...
 
virtual 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...
 
virtual 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...
 
virtual 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...
 
virtual void setVisible (bool)
 set the visibility of the viewer (show or hide its widget) More...
 
virtual ~Viewer () override
 default destructor More...
 

Public Attributes

*get the list of Component class manages by this viewer *default is set to Component
 
ViewerType type = EMBEDDED)
 this viewer's layout More...
 

Protected Member Functions

void clearSelection ()
 clear the selection More...
 
*set the list of component class names managed by this viewer *note Default is set to Component (all type of components) */void setComponentClassNames(QStringList)
 
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 setDescription (QString)
 set the viewer's description More...
 
void setIcon (QPixmap icon)
 set the default icon for the viewer extension 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 setComponentClassNames(...) 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 visible 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
}
#define CAMITK_ERROR(MSG)
Log for error verbosity (the minimum verbosity) Will always appear.
Definition: Log.h:253
static Viewer * getViewer(QString name)
get the pointer to a registered viewer given its name
Definition: Application.cpp:921
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);
Interactive 3D viewer.
Definition: InteractiveGeometryViewer.h:56
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:999
void toggleLogo(bool)
show/hide the logo at the bottom right corner
Definition: InteractiveViewer.cpp:2009
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 embedding 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

Member Function Documentation

◆ clearSelection()

void camitk::Viewer::clearSelection ( )
protected

clear the selection

Referenced by camitk::InteractiveViewer::keyPressEvent().

+ Here is the caller graph for this function:

◆ Component()

* set the list of component class names managed by this viewer* note Default is set to camitk::Viewer::Component ( all type of  components)
protected

◆ getComponentClassNames()

QStringList camitk::Viewer::getComponentClassNames ( )

Referenced by camitk::Application::getViewers(), and camitk::MainWindow::refresh().

+ 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 ( )
virtual

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)

◆ getEmbedder()

QLayout * camitk::Viewer::getEmbedder ( )
virtual

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(), and camitk::ViewerDockStyle::ViewerDockStyle().

+ 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 MedicalImageViewer, Explorer, and camitk::InteractiveViewer.

Referenced by ImpMainWindow::updateViewMenu().

+ Here is the caller graph for this function:

◆ getName()

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

get the name of the viewer

Referenced by PropertyExplorer::refresh(), camitk::Application::registerViewer(), camitk::ViewerExtension::registerViewer(), camitk::MainWindow::setCentralViewer(), camitk::Application::unregisterAllViewers(), ImpMainWindow::updateViewMenu(), and camitk::viewerLessThan().

+ Here is the caller graph for this function:

◆ getPropertyObject()

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

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

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

Referenced by ImpMainWindow::editSettings(), and camitk::PersistenceManager::loadWorkspace().

+ 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 MedicalImageViewer, BitmapViewer, and camitk::InteractiveViewer.

◆ getToolBarVisibility()

bool camitk::Viewer::getToolBarVisibility ( )
virtual

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 PropertyExplorer, MedicalImageViewer, FrameExplorer, Explorer, BitmapViewer, ActionViewer, camitk::InteractiveViewer, 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.

Referenced by camitk::MainWindow::refresh(), camitk::Component::refresh(), and camitk::MainWindow::refreshViewers().

+ Here is the caller graph for this function:

◆ 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(), camitk::InteractiveViewer::picked(), camitk::InteractiveViewer::sliderChanged(), 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

References camitk::Component::setSelected().

+ Here is the call graph for this function:

◆ 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).

References camitk::Component::setSelected().

+ Here is the call graph for this function:

◆ setDescription()

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

set the viewer's description

References 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)
virtual

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

References CAMITK_ERROR.

Referenced by camitk::MainWindow::addDockViewer().

+ Here is the caller graph for this function:

◆ setEmbedder()

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

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

References CAMITK_ERROR.

Referenced by camitk::MainWindow::setCentralViewer().

+ Here is the caller graph for this function:

◆ setIcon()

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

set the default icon for the viewer extension

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

+ Here is the caller graph for this function:

◆ setToolBarVisibility()

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

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 addDockViewer(...) will remove it

Reimplemented in MedicalImageViewer.

Referenced by ActionStateMachine::initMainWindow().

+ 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)
virtual

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

Member Data Documentation

◆ Component

* get the list of Component class manages by this viewer* default is set to camitk::Viewer::Component

◆ type

ViewerType camitk::Viewer::type = EMBEDDED)

this viewer's layout

Referenced by camitk::InteractiveViewer::InteractiveViewer().


The documentation for this class was generated from the following files: