Commit 235a9e86 authored by Maxime Calka's avatar Maxime Calka

New Architecture Viewer

parent c38ec8dd
# Call CamiTK CMake Macro to define the action
camitk_extension(ACTION_EXTENSION
NEEDS_COMPONENT_EXTENSION vtkmesh
NEEDS_VIEWER_EXTENSION interactiveviewer
NEEDS_VIEWER_EXTENSION interactivegeometryviewer
CEP_NAME SDK
DESCRIPTION "Allows one to reorient a volumic image."
ENABLE_AUTO_TEST
......
......@@ -28,7 +28,7 @@
// CamiTK
#include <Core.h>
#include <InteractiveViewer.h>
#include <InteractiveGeometryViewer.h>
#include <Log.h>
#include <ImageComponent.h>
#include <ImageOrientationHelper.h>
......@@ -192,7 +192,7 @@ void ReorientImage::initInternalViewer() {
buildGeometries();
// Set up the 3D viewer to visualize actual origin/orientation locations
internalViewer = InteractiveViewer::getNewViewer("Image Orientation Viewer", InteractiveViewer::GEOMETRY_VIEWER);
internalViewer = dynamic_cast<InteractiveGeometryViewer*>(Application::getNewViewer("Image Orientation Viewer", "InteractiveGeometryViewer"));
internalViewer->setHighlightMode(InteractiveViewer::OFF);
internalViewer->toggleCopyright(false);
internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN);
......@@ -333,7 +333,7 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) {
updatedTransform->SetMatrix(updatedMatrix);
image->setTransform(updatedTransform);
image->setFrameVisibility(InteractiveViewer::get3DViewer(), true);
image->setFrameVisibility(Application::getViewer("3DViewer"), true);
}
else {
......@@ -357,9 +357,9 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) {
updatedTransform->SetMatrix(updatedMatrix);
result->setTransform(updatedTransform);
result->setFrameVisibility(InteractiveViewer::get3DViewer(), true);
result->setFrameVisibility(Application::getViewer("3DViewer"), true);
}
InteractiveViewer::get3DViewer()->refresh();
Application::getViewer("3DViewer")->refresh();
Application::refresh();
......
......@@ -31,12 +31,13 @@
// Include ui_ReorientImage.h to be able to declare an instance of Ui::ReorientImage
#include "ui_ReorientImage.h"
#include <InteractiveGeometryViewer.h>
class vtkTransform;
class vtkAnnotatedCubeActor;
namespace camitk {
class Geometry;
class ImageComponent;
class InteractiveViewer;
}
class ReorientImage : public camitk::Action {
......@@ -77,7 +78,7 @@ private:
void setAxesOrientation(const QString orientation);
camitk::InteractiveViewer* internalViewer;
InteractiveGeometryViewer* internalViewer;
/// Actually perform the image transformation
ApplyStatus process(camitk::ImageComponent* image);
......
......@@ -704,13 +704,6 @@ QMap<QString, Action*>& Application::getActionMap() {
return actionMap;
}
// -------------------- getViewerMap --------------------
QMap<QString, Viewer*>& Application::getViewerMap() {
static QMap<QString, Viewer*> viewerMap;
return viewerMap;
}
// -------------------- getActions --------------------
const ActionList Application::getActions() {
return getActionMap().values();
......@@ -740,26 +733,6 @@ int Application::registerAllActions(ActionExtension* ext) {
return registered;
}
// -------------------- registerAllViewers --------------------
int Application::registerAllViewers(ViewerExtension* ext) {
int registered = 0;
foreach (Viewer* viewer, ext->getViewers()) {
// check if an action with same name was not already registered
if (getViewerMap().contains(viewer->getName())) {
CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n"
"extension of same name already registered")
.arg(viewer->getName(), viewer->getDescription()))
}
else {
getViewerMap().insert(viewer->getName(), viewer);
registered++;
}
}
return registered;
}
// -------------------- unregisterAllActions --------------------
int Application::unregisterAllActions(ActionExtension* ext) {
int unregistered = 0;
......@@ -772,18 +745,6 @@ int Application::unregisterAllActions(ActionExtension* ext) {
return unregistered;
}
// -------------------- unregisterAllViewers --------------------
int Application::unregisterAllViewers(ViewerExtension* ext) {
int unregistered = 0;
foreach (Viewer* viewer, ext->getViewers()) {
getViewerMap().remove(viewer->getName());
unregistered++;
}
return unregistered;
}
// ---------------- actionLessThan ----------------
bool actionLessThan(const camitk::Action* a1, const camitk::Action* a2) {
// This method is needed by qsort in the sort method to sort action by name
......@@ -865,16 +826,74 @@ ActionList Application::getActions(ComponentList selComp, QString tag) {
}
Viewer* camitk::Application::getViewer(QString name)
// -------------------- getViewerMap --------------------
QMap<QString, Viewer*>& Application::getViewerMap() {
static QMap<QString, Viewer*> viewerMap;
return viewerMap;
}
// -------------------- registerAllViewers --------------------
int Application::registerAllViewers(ViewerExtension* ext) {
int registered = 0;
foreach(Viewer* viewer, ext->getViewers()) {
// check if an action with same name was not already registered
if (getViewerMap().contains(viewer->getName())) {
CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n"
"extension of same name already registered")
.arg(viewer->getName(), viewer->getDescription()))
}
else {
getViewerMap().insert(viewer->getName(), viewer);
registered++;
}
}
return registered;
}
Viewer* Application::getViewer(QString name)
{
return getViewerMap().value(name);
}
Viewer* Application::getNewViewer(QString name, QString className) {
int i = 0;
QList<ViewerExtension*> vl = ExtensionManager::getViewerExtensionsList();
while (i < vl.size() && vl.at(i)->getViewerClassName() != className) {
i++;
}
if (i < vl.size()) {
ViewerExtension* ve = vl.at(i);
return ve->getNewInstance(name);
}
else {
CAMITK_ERROR_ALT(tr("No extension manage viewer of type %1\n").arg(className))
return nullptr;
}
}
// -------------------- getViewers --------------------
const ViewerList Application::getViewers() {
return getViewerMap().values();
}
// -------------------- unregisterAllViewers --------------------
int Application::unregisterAllViewers(ViewerExtension* ext) {
int unregistered = 0;
foreach(Viewer* viewer, ext->getViewers()) {
getViewerMap().remove(viewer->getName());
unregistered++;
}
return unregistered;
}
// ---------- isAlive ----------
bool Application::isAlive(Component* comp) {
return getAllComponents().contains(comp);
......
......@@ -262,6 +262,8 @@ public:
/// get a registered viewer given its name
static Viewer* getViewer(QString name);
static Viewer * getNewViewer(QString name, QString className);
/// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate)
static const ViewerList getViewers();
......@@ -528,6 +530,7 @@ private:
* see http://www.parashift.com/c++-faq/ctors.html
*/
static QMap<QString, Viewer*>& getViewerMap();
///@}
/// @name Property management
......
......@@ -80,7 +80,7 @@
#include <array>
using namespace camitk;
namespace camitk {
std::array<QString, 5> InteractiveViewer::defaultNames = { QString("3DViewer"), QString("axialViewer"), QString("coronalViewer"), QString("sagittalViewer"), QString("arbitraryViewer") };
......@@ -2337,4 +2337,6 @@ void InteractiveViewerFrame::keyPressEvent(QKeyEvent* e) {
// CMake automoc generates a camitk namespace error on this moc
// for the RendererWidget member of the InteractiveViewer class.
// By including it, the file kept out library-camitkcore_automoc.cpp
#include "moc_InteractiveViewer.cpp"
\ No newline at end of file
#include "moc_InteractiveViewer.cpp"
}
\ No newline at end of file
......@@ -28,7 +28,7 @@
#define INTERACTIVE_VIEWER_H
// -- Core stuff
#include "InteractiveViewerAPI.h"
#include "CamiTKAPI.h"
#include "Component.h"
#include "ViewerExtension.h"
#include "Viewer.h"
......@@ -54,22 +54,20 @@ class vtkCamera;
class vtkEventQtSlotConnect;
namespace camitk {
// -- Core stuff classes
class SliderSpinBoxWidget;
class GeometricObject;
class InterfaceGeometry;
class InterfaceBitMap;
class MeshDataFilterModel;
class PropertyObject;
class Property;
}
// -- Core stuff classes
class SliderSpinBoxWidget;
class GeometricObject;
class InterfaceGeometry;
class InterfaceBitMap;
class InteractiveViewer;
class MeshDataFilterModel;
class PropertyObject;
class Property;
using vtkSmartPointerCamera = vtkSmartPointer<vtkCamera>;
/// InteractiveViewerFrame is just a QFrame that delegates all key events to its InteractiveViewer
class INTERACTIVEVIEWER_API InteractiveViewerFrame : public QFrame {
class CAMITK_API InteractiveViewerFrame : public QFrame {
public:
/// default constructor
InteractiveViewerFrame(QWidget* parent, InteractiveViewer* s3D) : QFrame(parent), myInteractiveViewer(s3D) {}
......@@ -140,7 +138,7 @@ protected:
*
*/
class INTERACTIVEVIEWER_API InteractiveViewer : public camitk::Viewer {
class CAMITK_API InteractiveViewer : public Viewer {
Q_OBJECT
Q_ENUMS(HighlightMode RendererWidget::ControlMode RendererWidget::CameraOrientation) // so that it can be used in property editor
......@@ -172,7 +170,7 @@ public:
SELECTION_ONLY ///< the selected Components are in default mode, the non-selected are hidden
};
InteractiveViewer(camitk::ViewerExtension * extension, QString & name, ViewerType type=SLICE_VIEWER);
InteractiveViewer(ViewerExtension * extension, QString & name, ViewerType type);
/** Destructor */
~InteractiveViewer() override;
......@@ -188,7 +186,7 @@ public:
unsigned int numberOfViewedComponent() override;
/// Refresh the display.
void refresh(camitk::Viewer* whoIsAsking = nullptr) override;
void refresh(Viewer* whoIsAsking = nullptr) override;
/// get the InteractiveViewer widget (QTreeWidget). @param parent the parent widget for the viewer widget
QWidget* getWidget(QWidget* parent) override;
......@@ -365,16 +363,16 @@ protected:
void toggleInterpolation();
/// Update the display of the given Component, according to its selection state and the current HighlightMode.
void updateSelectionDisplay(camitk::Component*);
void updateSelectionDisplay(Component*);
/// the map containing all the actors in the InteractiveViewer
QMultiMap<camitk::Component*, vtkSmartPointer<vtkProp> > actorMap;
QMultiMap<Component*, vtkSmartPointer<vtkProp> > actorMap;
/// add the given actor of the given Component to the renderer and insert it in the map
void addActor(camitk::Component*, vtkSmartPointer<vtkProp>);
void addActor(Component*, vtkSmartPointer<vtkProp>);
/// remove all the given Component actors from the renderer and delete comp from the map
void removeAllActors(camitk::Component*);
void removeAllActors(Component*);
/// number of top-level component that are currently displayed
unsigned int displayedTopLevelComponents;
......@@ -391,7 +389,7 @@ protected:
/** Slider used to control the slice index in a InteractiveViewer. This slider is visible only when
* the scene a 2D viewer (see constructor). */
camitk::SliderSpinBoxWidget* sliceSlider;
SliderSpinBoxWidget* sliceSlider;
/// the InteractiveViewer frame
InteractiveViewerFrame* frame;
......@@ -414,7 +412,7 @@ protected:
/// the ComboBox for mesh scalar data
QComboBox* scalarDataComboBox;
camitk::MeshDataFilterModel* scalarDataModel;
MeshDataFilterModel* scalarDataModel;
/// init all the actions (called only once in the getWidget() method)
void initActions();
......@@ -487,7 +485,7 @@ protected:
* but for speed optimization that are not yet selected in the explorer.
* They will all be selected in the explorer when the user release the mouse button.
*/
std::vector <camitk::Component*> pickedComponent;
std::vector <Component*> pickedComponent;
/** Current picking mode, NO_PICKING be default. */
PickingMode pickingMode;
......@@ -537,42 +535,42 @@ protected:
/**
* The property object that holds the properties of this viewer
*/
camitk::PropertyObject* propertyObject;
PropertyObject* propertyObject;
/**
* The property that stands for the type of highlight mode of the 3D viewer.
*/
camitk::Property* highlightModeProperty;
Property* highlightModeProperty;
/**
* The property that stands for the background color of the viewer.
*/
camitk::Property* backgroundColorProperty;
Property* backgroundColorProperty;
/**
* Property that tells whether the viewer use a gradient background color or not.
*/
camitk::Property* backgroundGradientColorProperty;
Property* backgroundGradientColorProperty;
/**
* Property that tells whether the viewer uses lines as tubes or not.
*/
camitk::Property* linesAsTubesProperty;
Property* linesAsTubesProperty;
/**
* Property that tells whether the viewer uses the backface culling option or not.
*/
camitk::Property* backfaceCullingProperty;
Property* backfaceCullingProperty;
/**
* Property that tells whether the screenshot action is visible or not.
*/
camitk::Property* screenshotActionProperty;
Property* screenshotActionProperty;
/**
* Property which defines the point size of each point in the 3D viewer.
*/
camitk::Property* pointSizeProperty;
Property* pointSizeProperty;
/**
* Create and handle the CamiTK properties of this viewer.
......@@ -626,7 +624,9 @@ protected slots:
};
Q_DECLARE_METATYPE(InteractiveViewer::HighlightMode)
}
Q_DECLARE_METATYPE(camitk::InteractiveViewer::HighlightMode)
#endif
......
......@@ -122,6 +122,8 @@ Q_COREAPP_STARTUP_FUNCTION(initialize)
#endif
namespace camitk {
// static instantiation (global variable, global only for this file)
QMap <RendererWidget::ScreenshotFormat, RendererWidget::ScreenshotFormatInfo*> screenshotMap;
......@@ -1473,4 +1475,7 @@ void RendererWidget::setPicker(vtkSmartPointer<vtkAbstractPropPicker> woodyWood)
// I know, it is really Woody Wood Pecker, but you know, with a french accent...
GetInteractor()->SetPicker(woodyWood);
}
}
}
\ No newline at end of file
......@@ -31,7 +31,7 @@
#endif
// -- Core stuff
#include "InteractiveViewerAPI.h"
#include "CamiTKAPI.h"
// -- VTK stuff
#include <vtkVersion.h>
......@@ -73,6 +73,8 @@ class vtkScalarBarWidget;
class vtkTextMapper;
class vtkAbstractPropPicker;
namespace camitk {
class vtkInteractorStylePick;
/**
......@@ -94,7 +96,7 @@ class vtkInteractorStylePick;
*
**/
#if VTK_MAJOR_VERSION == 6
class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget2 {
class CAMITK_API RendererWidget : public QVTKWidget2 {
#elif VTK_MAJOR_VERSION == 7
class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget {
......@@ -523,5 +525,7 @@ protected :
};
}
#endif //RENDERERWIDGET_H
......@@ -68,4 +68,9 @@ bool Viewer::getToolBarVisibility() {
return toolbarVisibility;
}
ViewerExtension * Viewer::getExtension()
{
return extension;
}
}
......@@ -110,6 +110,8 @@ public:
/// Is actually useful (and defined) in Explorer.
virtual void refreshInterfaceNode(Component* comp) {};
ViewerExtension* getExtension();
signals:
/// this signal is emitted when the current selection was changed by the viewer
......
......@@ -30,6 +30,7 @@
#include "Log.h"
#include <QDir>
#include <QMetaType>
namespace camitk {
......@@ -54,6 +55,11 @@ void ViewerExtension::initResources() {
}
}
QString ViewerExtension::getViewerClassName()
{
return viewerClassName;
}
// -------------------- destructor --------------------
ViewerExtension::~ViewerExtension() {
while (!viewers.empty()) {
......@@ -74,6 +80,14 @@ void ViewerExtension::registerViewer(Viewer* viewer) {
viewers.append(viewer);
}
Viewer* ViewerExtension::getNewInstance(QString name) {
int typeId = QMetaType::type(name.toStdString().c_str());
const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId);
QObject *o = metaObject->newInstance();
Viewer* viewer = qobject_cast<Viewer*>(o);
return viewer;
}
// -------------------- getActions --------------------
const ViewerList& ViewerExtension::getViewers() {
return viewers;
......
......@@ -65,6 +65,10 @@ public:
/// Load, for the selected langage (asked to the Application), the associated .qm file
void initResources();
QString getViewerClassName();
Viewer * getNewInstance(QString name);
protected:
/// register an viewer instance
void registerViewer(Viewer*);
......@@ -78,6 +82,8 @@ private:
/// Provide internationalization support for text output.
QTranslator* translator{ nullptr };
QString viewerClassName;
};
}
......
......@@ -35,6 +35,8 @@
#include <vtkPicker.h>
#include <vtkAreaPicker.h>
namespace camitk {
//----------------------- Picking Interactor -----------------------
#if VTK_MAJOR_VERSION < 8
vtkInstantiatorNewMacro(vtkInteractorStylePick);
......@@ -300,4 +302,7 @@ void vtkInteractorStylePick::Pick() {
// ------------------------------- PrintSelf -------------------------------
void vtkInteractorStylePick::PrintSelf(ostream& os, vtkIndent indent) {
this->Superclass::PrintSelf(os, indent);
}
}
\ No newline at end of file
......@@ -27,17 +27,19 @@
#ifndef VTKINTERACTORSTYLEPICK_H
#define VTKINTERACTORSTYLEPICK_H
#include "InteractiveViewerAPI.h"
#include "CamiTKAPI.h"
#include <vtkInteractorStyle.h>
#include <vtkSmartPointer.h>
class vtkUnsignedCharArray;
namespace camitk {
/// Specific backward compatible interactor for CamiTK RendererWidget
/// Interactor used when we are in picking mode
///
class INTERACTIVEVIEWER_API vtkInteractorStylePick : public vtkInteractorStyle {
class CAMITK_API vtkInteractorStylePick : public vtkInteractorStyle {
public:
......@@ -73,4 +75,6 @@ protected:
bool areaPicking;
};
}
#endif //VTKINTERACTORSTYLEPICK_H
# Call CamiTK CMake Macro to define the action
camitk_extension(VIEWER_EXTENSION
CEP_NAME SDK
DEFINES COMPILE_INTERACTIVEGEOMETRYVIEWER_API
DESCRIPTION "An extension for the viewer that display GUI action"
INSTALL_ALL_HEADERS
)
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
// -- Core stuff
#include "InteractiveGeometryViewer.h"
#include <InteractiveViewer.h>
using namespace camitk;
// -------------------- Constructor --------------------
InteractiveGeometryViewer::InteractiveGeometryViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::GEOMETRY_VIEWER) {
}
// -------------------- Destructor --------------------
InteractiveGeometryViewer::~InteractiveGeometryViewer() {
}
\ No newline at end of file
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef INTERACTIVEGEOMETRYVIEWER_H
#define INTERACTIVEGEOMETRYVIEWER_H
// -- Core stuff
#include "InteractiveGeometryViewerAPI.h"
#include "ViewerExtension.h"
#include "InteractiveViewer.h"
// -- QT stuff
#include <QFrame>
#include <QGridLayout>
#include <QAction>
#include <QBoxLayout>
/**
* @ingroup group_sdk_libraries_core_viewer
*
* @brief
* The views manager.
*
* MedicalImageViewer is a viewer that can display from 1 to 4 InteractiveViewer that represents
* the axial, coronal, sagittal and 3D view of the same medical image.
* The views used the default InteractiveViewers singletons.
*
* This class follow the "singleton" design pattern, see getInstance().
* Singleton is enforced/recommanded so that actions can directly use the show*Viewer() methods
*
* \image html libraries/medicalimageviewer.png "The medical image viewer"
*
*/
class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewer : public camitk::InteractiveViewer {
Q_OBJECT
public:
InteractiveGeometryViewer(camitk::ViewerExtension*, QString);
/** destructor */
~InteractiveGeometryViewer() override;
};
#endif
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3