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 7d700ad2 authored by cfouard's avatar cfouard
Browse files

NEW Handling of image image orientation step 1: ImageComponent must now be in...

NEW Handling of image image orientation step 1: ImageComponent must now be in RAI orientation, Axial, Coronal and Sagittal are now in real medical orientation (as long as the ImageComponent is loaded in RAI convention)
FIXED first step to fix bug 12

NEW Frame Service ! A new CamiTK Service handling position of Components in space.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1540 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 3f470387
#
# DO NOT EDIT THIS FILE (unless you REALLY know what you are doing)
#
# To add a component, just add a subdirectory (the component name is the
# directory name). Add all your code there and a text file called
# CMakeLists.txt
# In your CMakeLists.txt, use the camitk_extension(ACTION_EXTENSION ...) macro apropriately
# find components
get_subdirectories(FRAME_ACTIONS_LIST)
# Add subdirectories in CMake project
foreach(FRAME_NAME ${FRAME_ACTIONS_LIST})
add_subdirectory(${FRAME_NAME})
endforeach()
# Call CamiTK CMake Macro to define the action
camitk_extension(ACTION_EXTENSION
)
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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$
****************************************************************************/
// Local
#include "MoveFrame.h"
// CamiTK
#include <InteractiveViewer.h>
#include <Log.h>
#include <Application.h>
#include <Component.h>
using namespace camitk;
// Qt
#include <QFileDialog>
#include <QTextStream>
// QT DOM
#include <QDomDocument>
#include <QDomElement>
#include <QDomText>
// vtk
#include <vtkUnstructuredGrid.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkAlgorithmOutput.h>
// --------------- constructor -------------------
MoveFrame::MoveFrame(ActionExtension* extension) : Action(extension) {
setName("Move Frame");
setDescription("This action allow to move a frame from its parent frame (or the world frame if it has no parent) by setting translations and rotation parameters.");
setComponent("Component");
// Setting classification family and tags
setFamily("Frame");
addTag("Test");
addTag("Move");
addTag("Visualization");
dialog = NULL;
inputFrame = NULL;
}
// --------------- init -------------------
void MoveFrame::init() {
dialog = new QDialog();
transformation = vtkTransform::New();
//-- init user interface
ui.setupUi(dialog);
// initialize slider names
ui.tX->setName("X");
ui.tY->setName("Y");
ui.tZ->setName("Z");
ui.rX->setName("Around X");
ui.rY->setName("Around Y");
ui.rZ->setName("Around Z");
// connect everything
connect(ui.translatePushButton, SIGNAL(clicked()), SLOT(translate()));
connect(ui.setTranslationPushButton, SIGNAL(clicked()), SLOT(setTranslation()));
connect(ui.rotatePushButton, SIGNAL(clicked()), SLOT(rotate()));
connect(ui.setRotationPushButton, SIGNAL(clicked()), SLOT(setRotation()));
connect(ui.resetButton, SIGNAL(clicked()), SLOT(reset()));
connect(ui.setTransformButton, SIGNAL(clicked()), SLOT(apply()));
connect(ui.savePushButton, SIGNAL(clicked()), SLOT(save()));
}
// --------------- destructor -------------------
MoveFrame::~MoveFrame() {
if (dialog) {
delete dialog;
}
}
// --------------- getWidget -------------------
QWidget * MoveFrame::getWidget() {
if (!dialog)
init();
inputFrame = dynamic_cast<Component *> (getTargets().last());
vtkSmartPointer<vtkTransform> initialTransform = inputFrame->getTransformFromParent();
initialPosition.setX(initialTransform->GetPosition()[0]);
initialPosition.setY(initialTransform->GetPosition()[1]);
initialPosition.setZ(initialTransform->GetPosition()[2]);
initialOrientation.setX(initialTransform->GetOrientation()[0]);
initialOrientation.setY(initialTransform->GetOrientation()[1]);
initialOrientation.setZ(initialTransform->GetOrientation()[2]);
// disconnect and reset previous state
reset();
return dialog;
}
//--------------- reset -------------
void MoveFrame::reset() {
//-- initialize the transformation to Identity
transformation->Identity();
transformation->RotateX(initialOrientation.x());
transformation->RotateY(initialOrientation.y());
transformation->RotateZ(initialOrientation.z());
transformation->Translate(initialPosition.x(), initialPosition.y(), initialPosition.z());
//-- init values
double bounds[6];
InteractiveViewer::get3DViewer()->getBounds(bounds);
double xLength = bounds[1] - bounds[0];
double yLength = bounds[3] - bounds[2];
double zLength = bounds[5] - bounds[4];
ui.tX->init(-xLength, + xLength, initialPosition.x());
ui.tY->init(-yLength, + yLength, initialPosition.y());
ui.tZ->init(-zLength, + zLength, initialPosition.z());
ui.rX->init(-180.0, 180.0, initialOrientation.x());
ui.rY->init(-180.0, 180.0, initialOrientation.y());
ui.rZ->init(-180.0, 180.0, initialOrientation.z());
}
//--------------- apply ------------
Action::ApplyStatus MoveFrame::apply() {
inputFrame = dynamic_cast<Component *> (getTargets().last());
transformation->Identity();
//-- Set the Rotation
transformation->RotateX(double(ui.rX->getValue()));
transformation->RotateY(double(ui.rY->getValue()));
transformation->RotateZ(double(ui.rZ->getValue()));
//-- Set the Translation
transformation->Translate(double(ui.tX->getValue()), double(ui.tY->getValue()), double(ui.tZ->getValue()));
inputFrame->setTransformFromParent(transformation);
// Refresh all the used viewers
// InteractiveViewer::get3DViewer()->refresh();
Application::refresh();
return SUCCESS;
}
void MoveFrame::translate() {
QVector3D trans;
trans.setX(double (ui.tX->getValue()));
trans.setY(double (ui.tY->getValue()));
trans.setZ(double (ui.tZ->getValue()));
inputFrame->translate(trans.x(), trans.y(), trans.z());
}
void MoveFrame::setTranslation() {
QVector3D trans;
trans.setX(double (ui.tX->getValue()));
trans.setY(double (ui.tY->getValue()));
trans.setZ(double (ui.tZ->getValue()));
inputFrame->setTranslation(trans.x(), trans.y(), trans.z());
}
void MoveFrame::rotate() {
QVector3D rot;
rot.setX(double (ui.rX->getValue()));
rot.setY(double (ui.rY->getValue()));
rot.setZ(double (ui.rZ->getValue()));
inputFrame->rotate(rot.x(), rot.y(), rot.z());
}
void MoveFrame::setRotation() {
QVector3D rot;
rot.setX(double (ui.rX->getValue()));
rot.setY(double (ui.rY->getValue()));
rot.setZ(double (ui.rZ->getValue()));
inputFrame->setRotation(rot.x(), rot.y(), rot.z());
}
void MoveFrame::save() {
transformation->Identity();
//-- Set the Rotation
transformation->RotateX(double(ui.rX->getValue()));
transformation->RotateY(double(ui.rY->getValue()));
transformation->RotateZ(double(ui.rZ->getValue()));
//-- Set the Translation
transformation->Translate(double(ui.tX->getValue()), double(ui.tY->getValue()), double(ui.tZ->getValue()));
QString filename = QFileDialog::getSaveFileName(NULL, "Save file");
QFile file(filename);
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
QDomDocument doc("frame");
QDomElement root = doc.createElement("frame");
root.setAttribute("name", "created frame");
QDomElement transform = doc.createElement("transform");
transform.setAttribute("type", "matrix");
vtkSmartPointer<vtkMatrix4x4> matrix = transformation->GetMatrix();
for (int i = 0; i < 4; i++) {
QDomElement line = doc.createElement("line");
// x
QDomElement xElmt = doc.createElement("x");
double xVal = matrix->GetElement(i, 0);
QDomText x = doc.createTextNode(QString::number(xVal));
xElmt.appendChild(x);
line.appendChild(xElmt);
// y
QDomElement yElmt = doc.createElement("y");
double yVal = matrix->GetElement(i, 1);
QDomText y = doc.createTextNode(QString::number(yVal));
yElmt.appendChild(y);
line.appendChild(yElmt);
// z
QDomElement zElmt = doc.createElement("z");
double zVal = matrix->GetElement(i, 2);
QDomText z = doc.createTextNode(QString::number(zVal));
zElmt.appendChild(z);
line.appendChild(zElmt);
// t
QDomElement tElmt = doc.createElement("t");
double tVal = matrix->GetElement(i, 3);
QDomText t = doc.createTextNode(QString::number(tVal));
tElmt.appendChild(t);
line.appendChild(tElmt);
transform.appendChild(line);
}
root.appendChild(transform);
doc.appendChild(root);
doc.save(stream, 0);
file.close();
}
}
\ No newline at end of file
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 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 MOVEFRAME_H
#define MOVEFRAME_H
#include "Action.h"
#include "Component.h"
#include <QVector3D>
#include <vtkTransform.h>
#include <vtkTransformFilter.h>
#include <vtkSmartPointer.h>
#include "ui_MoveFrame.h"
/** This action allows you to apply a linear transformation
* (translation,rotation around axes) on the top level selected Frame
*/
class MoveFrame : public camitk::Action {
Q_OBJECT
public:
/// the constructor
MoveFrame(camitk::ActionExtension*);
/// Destructor
virtual ~MoveFrame();
/// this method creates and returns the widget containing the user interface for the action
virtual QWidget * getWidget();
public slots:
/// method called when the action is applied
virtual ApplyStatus apply();
virtual void translate();
virtual void setTranslation();
virtual void rotate();
virtual void setRotation();
virtual void save();
private slots:
/// slot called when reset is ckicked, reset the transformation to Identity
void reset();
private:
/// initialize the dialog
void init();
/// current transformation
vtkTransform * transformation;
/// initial transformation
QVector3D initialPosition;
QVector3D initialOrientation;
/// current transform filters (one per selected object)
// QList< vtkSmartPointer<vtkTransformFilter> > filterList;
/// the Qt Gui
Ui::MoveFrame ui;
/// the dialog
QDialog *dialog;
camitk::Component * inputFrame;
};
#endif // MOVEFRAME_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MoveFrame</class>
<widget class="QDialog" name="MoveFrame">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>477</width>
<height>230</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Rigid Transformation</string>
</property>
<property name="windowIconText">
<string>TransformDialog</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="textSliders">
<item>
<widget class="QGroupBox" name="translationBox">
<property name="title">
<string>Translation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="camitk::SliderTextWidget" name="tX" native="true"/>
</item>
<item>
<widget class="camitk::SliderTextWidget" name="tY" native="true"/>
</item>
<item>
<widget class="camitk::SliderTextWidget" name="tZ" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="translatePushButton">
<property name="text">
<string>Translate</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<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="QPushButton" name="setTranslationPushButton">
<property name="text">
<string>SetTranslation</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="rotationBox">
<property name="title">
<string>Rotation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="camitk::SliderTextWidget" name="rX" native="true"/>
</item>
<item>
<widget class="camitk::SliderTextWidget" name="rY" native="true"/>
</item>
<item>
<widget class="camitk::SliderTextWidget" name="rZ" native="true"/>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="rotatePushButton">
<property name="text">
<string>Rotate</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<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="QPushButton" name="setRotationPushButton">
<property name="text">
<string>Set Rotation</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="viewModifiers">
<item>
<layout class="QHBoxLayout" name="dialogButtons">
<item>
<widget class="QPushButton" name="resetButton">
<property name="text">
<string>Reset</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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="QPushButton" name="setTransformButton">
<property name="text">
<string>Set Transform</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>