Commit a684a1e7 authored by Emmanuel Promayon's avatar Emmanuel Promayon

NEW tutorial to show how to change MainWindow central viewer

This new action add a specific central viewer that display
2D images with the right orientation and no slider (BitmapViewer)
BitmapViewer derived from InteractiveViewer.
parent 095e3fa8
/*****************************************************************************
* $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