Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

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

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;
};
}
......
......@@ -130,27 +130,30 @@ InteractiveViewer* InteractiveViewer::getViewer(QString name) {
QString letters[4] = {QString("R"), QString("L"), QString("A"), QString("P") };
singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters);
singletonInstance->toggleOrientationDecorations(true);
singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection(1);
singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
}
else if (name == defaultNames[2]) { // Coronal Viewer
singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK);
QString letters[4] = {QString("R"), QString("L"), QString("S"), QString("I") };
singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters);
singletonInstance->toggleOrientationDecorations(true);
singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection(1);
}
else if (name == defaultNames[3]) { // Sagittal Viewer
singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN);
QString letters[4] = {QString("A"), QString("P"), QString("S"), QString("I") };
singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters);
singletonInstance->toggleOrientationDecorations(true);
singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection(1);
}
else if (name == defaultNames[4]) { // Arbitrary Viewer
else
if (name == defaultNames[2]) { // Coronal Viewer
singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK);
QString letters[4] = {QString("R"), QString("L"), QString("S"), QString("I") };
singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters);
singletonInstance->toggleOrientationDecorations(true);
singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
}
else
if (name == defaultNames[3]) { // Sagittal Viewer
singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN);
QString letters[4] = {QString("A"), QString("P"), QString("S"), QString("I") };
singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters);
singletonInstance->toggleOrientationDecorations(true);
singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
}
else
if (name == defaultNames[4]) { // Arbitrary Viewer
// singletonInstance->getRendererWidget()->setCameraOrientation ( RendererWidget::RIGHT_DOWN );
singletonInstance->toggleOrientationDecorations(false);
// singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection ( 1 );
}
singletonInstance->toggleOrientationDecorations(false);
// singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn();
}
return singletonInstance;
......@@ -760,39 +763,42 @@ QMenu* InteractiveViewer::getMenu() {
// ---------------------- getToolBar ----------------------------
QToolBar* InteractiveViewer::getToolBar() {
if (frame && !viewerToolBar && myType == GEOMETRY_VIEWER) {
viewerToolBar = new QToolBar(objectName() + " ToolBar");
// ensure object name is set for saving the state
viewerToolBar->setObjectName(objectName() + " ToolBar");
if (frame && !viewerToolBar) {
if (myType == GEOMETRY_VIEWER) {
viewerToolBar = new QToolBar(objectName() + " ToolBar");
// ensure object name is set for saving the state
viewerToolBar->setObjectName(objectName() + " ToolBar");
viewerToolBar->addAction(pickPointAction);
viewerToolBar->addAction(pickCellAction);
viewerToolBar->addAction(pickPointRegionAction);
viewerToolBar->addAction(pickCellRegionAction);
viewerToolBar->addSeparator();
viewerToolBar->addAction(surfaceAction);
viewerToolBar->addAction(wireframeAction);
viewerToolBar->addAction(pointsAction);
if (colorAction) {
viewerToolBar->addAction(colorAction);
}
viewerToolBar->addAction(glyphAction);
viewerToolBar->addAction(toggleLabelAction);
viewerToolBar->addAction(pickPointAction);
viewerToolBar->addAction(pickCellAction);
viewerToolBar->addAction(pickPointRegionAction);
viewerToolBar->addAction(pickCellRegionAction);
viewerToolBar->addSeparator();
viewerToolBar->addSeparator();
viewerToolBar->addAction(toggleAxesAction);
viewerToolBar->addAction(surfaceAction);
viewerToolBar->addAction(wireframeAction);
viewerToolBar->addAction(pointsAction);
if (colorAction) {
viewerToolBar->addAction(colorAction);
}
viewerToolBar->addAction(glyphAction);
viewerToolBar->addAction(toggleLabelAction);
viewerToolBar->addAction(screenshotAction);
viewerToolBar->addSeparator();
viewerToolBar->addSeparator();
viewerToolBar->addAction(toggleAxesAction);
if (myType == SLICE_VIEWER) {
viewerToolBar->addAction(scalarDataColorAction);
}
/* if (myType == SLICE_VIEWER) {
viewerToolBar->addAction(toggleOrientationDecorationsAction);
}
viewerToolBar->addAction(screenshotAction);
viewerToolBar->addSeparator();
viewerToolBar->addAction(scalarDataColorAction);
*/
}
return viewerToolBar;
......@@ -1119,11 +1125,12 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) {
if (e->modifiers() == Qt::NoModifier && myType == GEOMETRY_VIEWER) {
toggleLabelAction->toggle();
}
else if (e->modifiers() == Qt::AltModifier) {
// addWhatsThisItem("Alt+L", "Toggle light follows camera");
rendererWidget->setLightFollowCamera(!rendererWidget->getLightFollowCamera());
rendererWidget->refresh();
}
else
if (e->modifiers() == Qt::AltModifier) {
// addWhatsThisItem("Alt+L", "Toggle light follows camera");
rendererWidget->setLightFollowCamera(!rendererWidget->getLightFollowCamera());
rendererWidget->refresh();
}
break;
......@@ -1164,10 +1171,11 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) {
refresh(this);
}
else if (e->modifiers() == Qt::NoModifier) {
// addWhatsThisItem("S", "Take a screenshot");
screenshot();
}
else
if (e->modifiers() == Qt::NoModifier) {
// addWhatsThisItem("S", "Take a screenshot");
screenshot();
}
break;
......@@ -1383,31 +1391,35 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) {
found = true;
debugStream << "\t- Surface Actor" << endl;
}
else if (c->getActor(InterfaceGeometry::Wireframe) == p) {
found = true;
debugStream << "\t- Wireframe Actor" << endl;
}
else if (c->getActor(InterfaceGeometry::Points) == p) {
found = true;
debugStream << "\t- Points Actor" << endl;
}
else
if (c->getActor(InterfaceGeometry::Wireframe) == p) {
found = true;
debugStream << "\t- Wireframe Actor" << endl;
}
else
if (c->getActor(InterfaceGeometry::Points) == p) {
found = true;
debugStream << "\t- Points Actor" << endl;
}
break;
case SLICE_VIEWER:
if (c->getPixelActor() == p) {
found = true;
debugStream << "\t- Pixel Actor" << endl;
}
else if (c->get2DImageActor() == p) {
found = true;
debugStream << "\t- 2D Image Actor" << endl;
}
else if (c->getPickPlaneActor() == p) {
found = true;
debugStream << "\t- Picked Plane Actor" << endl;
/* } else if (c->get2DAxesActor() == p) {
found = true;
debugStream << "\t- 2D Axes Actor" << endl; */
}
else
if (c->get2DImageActor() == p) {
found = true;
debugStream << "\t- 2D Image Actor" << endl;
}
else
if (c->getPickPlaneActor() == p) {
found = true;
debugStream << "\t- Picked Plane Actor" << endl;
/* } else if (c->get2DAxesActor() == p) {
found = true;
debugStream << "\t- 2D Axes Actor" << endl; */
}
break;
default:
......@@ -1957,20 +1969,21 @@ void InteractiveViewer::highlightModeChanged(QAction* selectedAction) {
if (selectedAction == highlightSelectionAction) {
propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::SELECTION);
}
else if (selectedAction == highlightSelectionOnlyAction) {
propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::SELECTION_ONLY);
}
else
/*
if (selectedAction == highlightModeXtraHotAction) {
highlightMode = InteractiveViewer::XTRA_HOT;
if (selectedAction == highlightSelectionOnlyAction) {
propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::SELECTION_ONLY);
}
else
*/
if (selectedAction == highlightOffAction) {
propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::OFF);
}
/*
if (selectedAction == highlightModeXtraHotAction) {
highlightMode = InteractiveViewer::XTRA_HOT;
}
else
*/
if (selectedAction == highlightOffAction) {
propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::OFF);
}
refresh(this);
}
......@@ -1982,16 +1995,18 @@ void InteractiveViewer::cameraOrientationChanged(QAction* selectedAction) {
resetCamera();
rendererWidget->refresh();
}
else if (selectedAction == cameraOrientationLeftUpAction) {
rendererWidget->setCameraOrientation(RendererWidget::LEFT_UP);
resetCamera();
rendererWidget->refresh();
}
else if (selectedAction == cameraOrientationRightUpAction) {
rendererWidget->setCameraOrientation(RendererWidget::RIGHT_UP);
resetCamera();
rendererWidget->refresh();
}
else
if (selectedAction == cameraOrientationLeftUpAction) {
rendererWidget->setCameraOrientation(RendererWidget::LEFT_UP);
resetCamera();
rendererWidget->refresh();
}
else
if (selectedAction == cameraOrientationRightUpAction) {
rendererWidget->setCameraOrientation(RendererWidget::RIGHT_UP);
resetCamera();
rendererWidget->refresh();
}
QSettings& settings = Application::getSettings();
settings.beginGroup(Application::getName() + ".InteractiveViewer." + objectName().simplified().replace(" ", ""));
......@@ -2088,15 +2103,18 @@ void InteractiveViewer::pickingModeChanged(QAction* selectedAction) {
if (selectedAction == pickCellAction) {
initPicking(CELL_PICKING);
}
else if (selectedAction == pickPointAction) {
initPicking(POINT_PICKING);
}
else if (selectedAction == pickCellRegionAction) {
initPicking(AREA_CELL_PICKING);
}
else if (selectedAction == pickPointRegionAction) {
initPicking(AREA_POINT_PICKING);
}
else
if (selectedAction == pickPointAction) {
initPicking(POINT_PICKING);
}
else
if (selectedAction == pickCellRegionAction) {
initPicking(AREA_CELL_PICKING);
}
else
if (selectedAction == pickPointRegionAction) {
initPicking(AREA_POINT_PICKING);
}
}
//-------------------- picked ---------------------
......
......@@ -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.