Commit 43a7b685 authored by Maxime Calka's avatar Maxime Calka

Merging

parents bc64b886 a684a1e7
......@@ -45,6 +45,7 @@
#include <QUrl>
#include <QCloseEvent>
#include <QMimeData>
#include <QStackedWidget>
namespace camitk {
// ------------- constructor -----------------
......@@ -203,20 +204,6 @@ bool MainWindow::addViewer(Viewer* theViewer) {
// ------------- removeViewer -----------------
bool MainWindow::removeViewer(Viewer* viewer) {
if (!viewers.contains(viewer)) {
return false;
}
// tell all component not to be visible anymore in this viewer
foreach (Component* comp, Application::getAllComponents()) {
comp->setVisibility(viewer, false);
}
// remove it properly
disconnect(viewer, SIGNAL(selectionChanged()), this, SLOT(refresh()));
viewers.removeAll(viewer);
delete viewer;
return true;
}
......@@ -260,14 +247,20 @@ void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer
// ------------- setCentralViewer -----------------
void MainWindow::setCentralViewer(Viewer* theViewer) {
if (theViewer->getWidget(this) && addViewer(theViewer)) {
// remove actual central viewer properly
if (centralViewer && (theViewer != centralViewer)) {
removeViewer(centralViewer);
// get the viewer widget (must have something to show as it is a viewer after all!)
QWidget *viewerWidget = theViewer->getWidget(this);
if (viewerWidget != nullptr) {
// add the viewer to the list (if not already in the list)
addViewer(theViewer);
// if needed, create the default (empty) central widget inside which the central viewers can be added
if (centralWidget()==0) {
setCentralWidget(new QStackedWidget(this));
}
// set the central widget
setCentralWidget(theViewer->getWidget(this));
// add the widget to the central widget
qobject_cast<QStackedWidget*>(centralWidget())->addWidget(viewerWidget);
qobject_cast<QStackedWidget*>(centralWidget())->setCurrentWidget(viewerWidget);
centralViewer = theViewer;
}
}
......
......@@ -50,14 +50,20 @@ class Viewer;
* @ingroup group_sdk_libraries_core_application
*
* @brief
* This Class is the base class for your application. It sets up the main
* window and providing a menubar, toolbar and statusbar (all hidden).
* This class is the base class for your application. It sets up the main
* window and creates a menubar, toolbar and statusbar (all hidden by default).
*
* It is the default main window for a application.
*
* Create a class that inherits from MainWindow to
* get all the goodies of Core and add your own customization/UI.
* See applications for examples.
* get all the goodies of CamiTK and add your own customization/UI.
*
* See tutorials applications for examples.
*
* The central widget is a QStackWidget: when new central viewers are added, the previous central
* viewer is hidden, not destroyed. See the "switchviewer" action tutorial for some example on
* how to embed an new central viewer to the imp main window (and switch back to medical image viewer
* whenever required).
*/
class CAMITK_API MainWindow : public QMainWindow {
Q_OBJECT
......@@ -184,13 +190,21 @@ protected:
/// just call open with the dragged uri
void dropEvent(QDropEvent* event) override;
///@cond
/**
* TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0
* @deprecated
* Removing viewers can be harmful. Central viewer is now simply hidden, therefore there is no need to remove it.
* It will keep itself refreshed and when shown again will be up to date.
* DEPRECATED (CamiTK 5.0) -> to be removed
*
* @brief Remove the given viewer from the list of viewer.
* @note This tell all Component not to be visible anymore in this viewer instance, remove it from the list of viewers and delete it.
* @param viewer The viewer to remove.
* @return True if removing succeeded, false otherwise.
*/
bool removeViewer(Viewer* viewer);
///@endcond
/**
* @brief The actual central Viewer.
......@@ -227,6 +241,7 @@ private:
/// the main part of the title
QString mainTitle;
};
}
......
......@@ -1399,16 +1399,16 @@ void RendererWidget::resetCameraSettings() {
switch (cameraOrientation) {
case LEFT_UP:
// default position
cam->SetPosition(0, 0, -1);
cam->SetFocalPoint(0, 0, 0);
cam->SetViewUp(0, 1, 0);
cam->SetPosition(0.0, 0.0, -1.0);
cam->SetFocalPoint(0.0, 0.0, 0.0);
cam->SetViewUp(0.0, 1.0, 0.0);
cam->OrthogonalizeViewUp();
break;
case RIGHT_DOWN:
// default position
cam->SetPosition(0, 0, -1);
cam->SetFocalPoint(0, 0, 0);
cam->SetViewUp(0, -1, 0);
cam->SetPosition(0.0, 0.0, -1.0);
cam->SetFocalPoint(0.0, 0.0, 0.0);
cam->SetViewUp(0.0, -1.0, 0.0);
cam->OrthogonalizeViewUp();
break;
// For Coronal view of Coronal Viewer
......@@ -1427,9 +1427,9 @@ void RendererWidget::resetCameraSettings() {
break;
case RIGHT_UP:
default:
cam->SetPosition(0, 0, 1);
cam->SetFocalPoint(0, 0, 0);
cam->SetViewUp(0, 1, 0);
cam->SetPosition(0.0, 0.0, 1.0);
cam->SetFocalPoint(0.0, 0.0, 0.0);
cam->SetViewUp(0.0, 1.0, 0.0);
cam->OrthogonalizeViewUp();
break;
}
......
/*****************************************************************************
* $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$
****************************************************************************/
#include "BitmapViewer.h"
#include <Application.h>
#include <MainWindow.h>
#include <MedicalImageViewer.h>
#include <Log.h>
#include <QToolBar>
#include <vtkCamera.h>
using namespace camitk;
// initialize static variables
QString BitmapViewer::BitmapViewerName = "2D Bitmap Viewer"; // required due to QString ref needed by InteractiveViewer cstr
BitmapViewer* BitmapViewer::singleton = nullptr;
BitmapViewer* BitmapViewer::getInstance() {
if (!singleton) {
singleton = new BitmapViewer();
}
return singleton;
}
// -------------------- Constructor --------------------
BitmapViewer::BitmapViewer() : InteractiveViewer(BitmapViewerName, InteractiveViewer::SLICE_VIEWER) {
// 2D images need x right, y up, z front
getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_UP);
// no decoration and grey background
getRendererWidget()->toggleOrientationDecorations(false);
getRendererWidget()->setGradientBackground(false);
getRendererWidget()->setBackgroundColor(0.8, 0.8, 0.8);
// parallel projection
getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
isVisible = false;
switchToolBar = nullptr;
}
// -------------------- Destructor --------------------
BitmapViewer::~BitmapViewer() {
}
// -------------------- switchCentralViewer --------------------
void BitmapViewer::switchCentralViewer() {
// if the central viewer is the medical image viewer switch to my2DBitmapViewer (if it is not switch back to the medical image viewer)
if (isVisible) {
// switch back to the default MedicalImageViewer
Application::getMainWindow()->setCentralViewer(MedicalImageViewer::getInstance());
}
else {
// switch to the custom viewer
Application::getMainWindow()->setCentralViewer(BitmapViewer::getInstance());
// force refresh
refresh(this);
}
isVisible = !isVisible;
}
// -------------------- refresh --------------------
void BitmapViewer::refresh(Viewer* whoIsAsking) {
updateVisibility();
InteractiveViewer::refresh();
}
// -------------------- getWidget --------------------
QWidget* BitmapViewer::getWidget(QWidget* parent) {
QWidget* myWidget = InteractiveViewer::getWidget(parent);
// hide slice slider
sideFrame->hide();
updateVisibility();
return myWidget;
}
// -------------------- getToolBar --------------------
QToolBar* BitmapViewer::getToolBar() {
if (switchToolBar == nullptr) {
// create the action to switch between the default and this viewer
QAction* switchViewerAction = new QAction(tr("Bitmap Viewer"), this);
switchViewerAction->setCheckable(true);
switchViewerAction->setChecked(true); // first time getToolBar is called -> BitmapViewer is being displayed
switchViewerAction->setStatusTip(tr("Switch The Central Viewer"));
switchViewerAction->setWhatsThis(tr("Switch The Central Viewer between the BitmapViewer and MedicalImageViewer"));
connect(switchViewerAction, SIGNAL(toggled(bool)), this, SLOT(switchCentralViewer()));
// create the toolbar and add the action to it
switchToolBar = new QToolBar(objectName() + " ToolBar");
// ensure object name is set for saving the state
switchToolBar->setObjectName(objectName() + " ToolBar");
switchToolBar->addAction(switchViewerAction);
}
return switchToolBar;
}
// -------------------- updateVisibility --------------------
void BitmapViewer::updateVisibility() {
// as the default component does not know anything about my2DBitmapViewer,
// tell all the components that are already visible in the axial slices to be also
// visible in my2DBitmapViewer
for (Component* comp : Application::getAllComponents()) {
if (comp->getVisibility(InteractiveViewer::getAxialViewer())) {
comp->setVisibility(this, true);
}
}
}
/*****************************************************************************
* $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 BITMAPVIEWER_H
#define BITMAPVIEWER_H
#include <InteractiveViewer.h>
class QToolBar;
/**
* @brief
* InteractiveViewer specialized in 2D bitmap (images in jpeg, png...)
*/
class BitmapViewer : public camitk::InteractiveViewer {
Q_OBJECT
public:
static BitmapViewer* getInstance();
virtual ~BitmapViewer() override;
void refresh(camitk::Viewer* whoIsAsking = nullptr) override;
QWidget* getWidget(QWidget* parent = nullptr) override;
QToolBar* getToolBar() override;
public slots:
void switchCentralViewer();
protected:
BitmapViewer();
private:
static BitmapViewer* singleton;
static QString BitmapViewerName;
bool isVisible;
QToolBar* switchToolBar;
// set visibility of all possible component (that is component that can be displayed in 2D)
void updateVisibility();
};
#endif // BITMAPVIEWER_H
camitk_extension(ACTION_EXTENSION
ENABLE_AUTO_TEST
#TEST_FILES bassin.msh brain.mha sinus.mhd
)
/*****************************************************************************
* $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$
****************************************************************************/
#include "SwitchViewer.h"
#include <BitmapViewer.h>
#include <Application.h>
#include <MainWindow.h>
#include <MedicalImageViewer.h>
#include <ImageComponent.h>
#include <QColor>
using namespace camitk;
// -------------------- SwitchViewer --------------------
SwitchViewer::SwitchViewer(ActionExtension* extension) : Action(extension) {
setName("Switch Central Viewer");
setEmbedded(false); // not embedded (and as the
setDescription("Tutorial action that switch the central viewer in/out. Trigger this action when no component is selected");
setComponent("");
setFamily("Tutorial");
addTag("Viewer");
addTag("MainWindow");
}
// --------------- getWidget -------------------
QWidget* SwitchViewer::getWidget() {
return nullptr;
}
// --------------- apply -------------------
Action::ApplyStatus SwitchViewer::apply() {
// just ask the BitMap viewer to switch the central viewer
BitmapViewer::getInstance()->switchCentralViewer();
return SUCCESS;
}
/*****************************************************************************
* $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 SWITCH_VIEWER_H
#define SWITCH_VIEWER_H
#include <Action.h>
namespace camitk {
class InteractiveViewer;
class Viewer;
}
/**
* Demonstrates how to switch the central image viewer.
*/
class SwitchViewer : public camitk::Action {
public:
/// the constructor
SwitchViewer(camitk::ActionExtension*);
/// the destructor
virtual ~SwitchViewer() = default;
/// method called when the action when the action is triggered (i.e. started)
virtual QWidget* getWidget();
public slots:
/// method called when the action is applied
virtual ApplyStatus apply();
};
#endif // SWITCH_VIEWER_H
/*****************************************************************************
* $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$
****************************************************************************/
#include "SwitchViewerExtension.h"
#include "SwitchViewer.h"
// -------------------- init --------------------
void SwitchViewerExtension::init() {
registerNewAction(SwitchViewer);
}
/*****************************************************************************
* $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 SWITCH_VIEWER_EXTENSION_H
#define SWITCH_VIEWER_EXTENSION_H
#include <QObject>
#include <Action.h>
#include <ActionExtension.h>
/// shows how to switch the central viewer in and out
class SwitchViewerExtension : public camitk::ActionExtension {
Q_OBJECT
Q_INTERFACES(camitk::ActionExtension)
Q_PLUGIN_METADATA(IID "fr.imag.camitk.tutorials.action.switchviewer")
public:
/// the constructor
SwitchViewerExtension() : ActionExtension() {};
/// the destructor
virtual ~SwitchViewerExtension() = default;
/// initialize all the actions
virtual void init();
/// Method that return the action extension name
virtual QString getName() {
return "Switch Viewer";
};
/// Method that return the action extension descrption
virtual QString getDescription() {
return "This extension contains a simple medical image viewer (axial slice) and a simple action to switch the central viewer (by default, the medical image viewer) to and from the simple medical image viewer.";
};
};
#endif // BASIC_PICKING_EXTENSION_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment