Commit 28bd7585 authored by saubatn's avatar saubatn
Browse files

DONE : task 265 "Arbitrary Slice Viewer toolbar"

	NEW : arbitrary slice action to customize it (angle, slice number).
	NEW : widget to set up slice number and angles.

NEW : arbitrary slice number is initialized to the max of the 3 others axes slices number (axial, coronal, sagital).
FIXED : action families which contain only one action are displayed like others : a submenu of the family name, and an entry of the name of the action (previously the family sub-menu was not displayed, shorten the menu to the action directly). I think the family menu shows important nformation. To be debated.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@229 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 56831c0e
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2012 UJF-Grenoble 1, 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 "AnglesSetterWidget.h"
// CamiTK stuff
#include <InteractiveViewer.h>
#include <Application.h>
#include <MainWindow.h>
#include <ImageComponent.h>
// Qt stuff
#include <QSpinBox>
using namespace camitk;
// -------------------- constructor --------------------
AnglesSetterWidget::AnglesSetterWidget(QWidget* parent): QWidget(parent)
{
ui.setupUi(this);
// Ui slice number change slot connection
connect ( ui.sliceSpinBox, SIGNAL ( valueChanged(int)), this, SLOT ( updateSlice(int) ) );
connect ( ui.sliceSlider, SIGNAL ( valueChanged(int)), this, SLOT ( updateSlice(int) ) ) ;
// Ui angles slot connection
connect ( ui.xAngleDial, SIGNAL ( valueChanged(int)), this, SLOT ( xAngleDialValueChanged (int) ) );
connect ( ui.yAngleDial, SIGNAL ( valueChanged(int)), this, SLOT ( yAngleDialValueChanged (int) ) );
connect ( ui.zAngleDial, SIGNAL ( valueChanged(int)), this, SLOT ( zAngleDialValueChanged (int) ) );
// Initialize the slider
// The action calling this widget must be applyied on only one IMAGE component.
// Therefore, selectedComponents are counted to 5, the top image level component and its slices (axial, coronal, sagital and arbitrary).
// selectedComponent[1] => arbitrary slice of the top level component
ComponentList selectedComponents = Application::getSelectedComponents();
if (selectedComponents.size()>0)
{
ui.sliceSlider->setMaximum(selectedComponents[1]->getNumberOfSlices() - 1);
ui.sliceSlider->setValue(selectedComponents[1]->getSlice());
ui.sliceSpinBox->setMaximum(selectedComponents[1]->getNumberOfSlices() - 1);
ui.sliceSpinBox->setValue(selectedComponents[1]->getSlice());
}
else
{
// TODO display error message, log ...
}
}
// -------------------- destructor --------------------
AnglesSetterWidget::~AnglesSetterWidget(){;}
// -------------------- updateSlice --------------------
void AnglesSetterWidget::updateSlice(int sliceNumber)
{
// Ui slider and spin box are mapped and thus automatically updated when a change occurs.
InteractiveViewer::getArbitraryViewer()->sliderChanged(sliceNumber);
InteractiveViewer::getArbitraryViewer()->refresh();
InteractiveViewer::get3DViewer()->refresh();
}
// -------------------- xAngleDialValueChanged --------------------
void AnglesSetterWidget::xAngleDialValueChanged (int value) {
InteractiveViewer::getArbitraryViewer()->xAngleChanged(value);
updateAngleSlider(ui.xAngleDial, ui.xAngleValue);
InteractiveViewer::getArbitraryViewer()->refresh();
InteractiveViewer::get3DViewer()->refresh();
}
// -------------------- yAngleDialValueChanged --------------------
void AnglesSetterWidget::yAngleDialValueChanged (int value) {
InteractiveViewer::getArbitraryViewer()->yAngleChanged(value);
updateAngleSlider(ui.yAngleDial, ui.yAngleValue);
InteractiveViewer::getArbitraryViewer()->refresh();
InteractiveViewer::get3DViewer()->refresh();
}
// -------------------- zAngleDialValueChanged --------------------
void AnglesSetterWidget::zAngleDialValueChanged (int value) {
InteractiveViewer::getArbitraryViewer()->zAngleChanged(value);
updateAngleSlider(ui.zAngleDial, ui.zAngleValue);
InteractiveViewer::getArbitraryViewer()->refresh();
InteractiveViewer::get3DViewer()->refresh();
}
// -------------------- updateAngleSlider --------------------
void AnglesSetterWidget::updateAngleSlider(QDial * dial, QLabel * label) {
dial->blockSignals(true);
dial->setMinimum(0);
dial->setMaximum(360);
dial->blockSignals(false);
if (label == ui.xAngleValue)
label->setText("Angle X : <tt>" + QString("%1").arg(dial->value(), 3) + "</tt>" + 0x00B0);
else
if (label == ui.yAngleValue)
label->setText("Angle Y : <tt>" + QString("%1").arg(dial->value(), 3) + "</tt>" + 0x00B0);
else
if (label == ui.zAngleValue)
label->setText("Angle Z : <tt>" + QString("%1").arg(dial->value(), 3) + "</tt>" + 0x00B0);
label->update();
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2012 UJF-Grenoble 1, 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 AnglesSetterWidget_h
#define AnglesSetterWidget_h
#include "ui_AnglesSetterWidget.h"
#include <QWidget>
/**
* This class describes the QWidget that allows user to change the X,Y ans Z angle of the arbitrary slice
* of a 2D image. Moreover it also allows to change the slice number using a slider.
* @Note :
* For initialization purpose, widget must be used for only one component (arbitrary).
* If several component are selected, do not build / display it.
*
* Use corresponding .ui file created with Qt Designer.
*/
class AnglesSetterWidget : public QWidget
{
Q_OBJECT
public:
/// Default construtor
AnglesSetterWidget(QWidget* parent = 0);
/// Destructor
virtual ~AnglesSetterWidget();
private:
Ui::AnglesSetterWidget ui;
private:
/// update the angle dialog slider (text + value)
void updateAngleSlider(QDial * dial, QLabel * label);
private slots:
/// Update slice number to be displayed
void updateSlice(int sliceNumber);
/// Method that update the angle dialog slider (text + value)
void xAngleDialValueChanged (int value);
void yAngleDialValueChanged (int value);
void zAngleDialValueChanged (int value);
};
#endif // AnglesSetterWidget_h
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AnglesSetterWidget</class>
<widget class="QWidget" name="AnglesSetterWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>289</width>
<height>500</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>500</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>289</width>
<height>538</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="leftLayout">
<item>
<layout class="QHBoxLayout" name="labelLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Slice</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSpinBox" name="sliceSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="sliderLayout">
<item>
<widget class="QSlider" name="sliceSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="rightLayout">
<item>
<layout class="QHBoxLayout" name="xAngleLayout">
<item>
<widget class="QLabel" name="xAngleValue">
<property name="text">
<string>Angle X : 0°</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDial" name="xAngleDial">
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="yAngleLayout">
<item>
<widget class="QLabel" name="yAngleValue">
<property name="text">
<string>Angle Y : 0°</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDial" name="yAngleDial">
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="zAngleLayout">
<item>
<widget class="QLabel" name="zAngleValue">
<property name="text">
<string>Angle Z : 0°</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDial" name="zAngleDial">
<property name="minimumSize">
<size>
<width>5</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>sliceSlider</sender>
<signal>valueChanged(int)</signal>
<receiver>sliceSpinBox</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>34</x>
<y>445</y>
</hint>
<hint type="destinationlabel">
<x>38</x>
<y>39</y>
</hint>
</hints>
</connection>
<connection>
<sender>sliceSpinBox</sender>
<signal>valueChanged(int)</signal>
<receiver>sliceSlider</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>34</y>
</hint>
<hint type="destinationlabel">
<x>30</x>
<y>158</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2012 UJF-Grenoble 1, 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 "ArbitrarySliceExtension.h"
// include generated actions headers
#include "SetAnglesAction.h"
// --------------- declare the extension -------------------
Q_EXPORT_PLUGIN2(arbitraryslice, ArbitrarySliceExtension);
// --------------- getActions -------------------
void ArbitrarySliceExtension::init() {
// Creating and registering the instance of AdjustArbiratrySliceAnglesAction
registerNewAction(SetAnglesAction);
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2012 UJF-Grenoble 1, 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 ACTIONEXTENSIONEXAMPLE_H
#define ACTIONEXTENSIONEXAMPLE_H
#include <ActionExtension.h>
using namespace camitk;
class ArbitrarySliceExtension : public ActionExtension {
Q_OBJECT
Q_INTERFACES(camitk::ActionExtension);
public:
/// Constructor
ArbitrarySliceExtension() : ActionExtension() {};
/// Destructor
virtual ~ArbitrarySliceExtension() {};
/// Method returning the action extension name
virtual QString getName() {return "ArbitrarySliceExtension";};
/// Method returning the action extension descrption
virtual QString getDescription() {return "This extension gathers actions for 2D images arbitrary slice.";};
/// initialize all the actions
virtual void init();
};
#endif // ACTIONEXTENSIONEXAMPLE_H
# Call CamiTK CMake Macro to define the action
camitk_extension(ACTION_EXTENSION
DEFAULT
)
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2012 UJF-Grenoble 1, 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 "SetAnglesAction.h"
#include <QString>
#include <QMessageBox>
#include <QTextStream>
#include <Application.h>
#include <InteractiveViewer.h>
#include <ActionViewer.h>
using namespace camitk;
// --------------- Constructor -------------------
SetAnglesAction::SetAnglesAction(ActionExtension * extension) : Action(extension) {
// Setting name, description and input component
setName("Adjust angles");
setDescription("This Action allows user to adjust the angle of the slice of the arbitrary viewer.");
setComponent("ImageComponent");
// Setting classification family and tags
setFamily("Arbitrary Slice");
addTag("arbitrary slice");
addTag("arbitrary");
addTag("angle");
actionWidget = 0;
setEmbedded(true);
}
// --------------- destructor -------------------
SetAnglesAction::~SetAnglesAction() { ; }
// --------------- getWidget -------------------
QWidget* SetAnglesAction::getWidget() {
if (!actionWidget)
actionWidget = new AnglesSetterWidget();
return actionWidget;
}
\ No newline at end of file
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2012 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*