}
return spacing;
}
-//--------------------------------------------------------------------
-
//--------------------------------------------------------------------
std::vector<double> vvImage::GetOrigin() const
{
//--------------------------------------------------------------------
//--------------------------------------------------------------------
-vtkTransform * vvImage::GetTransform()
+vtkSmartPointer<vtkTransform> vvImage::GetTransform()
{
return mTransform;
}
//--------------------------------------------------------------------
-//-------------------------------------------------------------------
-void vvImage::SetRotateX(int xvalue)
-{
- mTransform->PostMultiply();
- mTransform->Translate(-origin[0],-origin[1],-origin[2]);
- mTransform->RotateX(xvalue);
- mTransform->Translate(origin[0],origin[1],origin[2]);
-}
-
-//--------------------------------------------------------------------
-
-//-------------------------------------------------------------------
-void vvImage::SetRotateY(int yvalue)
-{
- mTransform->PostMultiply();
- mTransform->Translate(-origin[0],-origin[1],-origin[2]);
- mTransform->RotateY(yvalue);
- mTransform->Translate(origin[0],origin[1],origin[2]);
-}
-//--------------------------------------------------------------------
-
-//-------------------------------------------------------------------
-void vvImage::SetRotateZ(int zvalue)
-{
- mTransform->PostMultiply();
- mTransform->Translate(-origin[0],-origin[1],-origin[2]);
- mTransform->RotateZ(zvalue);
- mTransform->Translate(origin[0],origin[1],origin[2]);
-}
-//--------------------------------------------------------------------
-
-//-------------------------------------------------------------------
-void vvImage::SetTranslationX(int xvalue)
-{
- mTransform->Translate(xvalue,0,0);
-}
//--------------------------------------------------------------------
-
-//-------------------------------------------------------------------
-
-void vvImage::SetTranslationY(int yvalue)
+void vvImage::SetTransform(vtkSmartPointer<vtkTransform> transform)
{
- mTransform->Translate(0,yvalue,0);
+ mTransform = transform;
+ this->UpdateReslice();
}
//--------------------------------------------------------------------
-//-------------------------------------------------------------------
-void vvImage::SetTranslationZ(int zvalue)
-{
- mTransform->Translate(0,0,zvalue);
-}
-//-------------------------------------------------------------------
-
-//-------------------------------------------------------------------
-void vvImage::SetOrigin(double value[3])
-{
- origin[0]=value[0];
- origin[1]=value[1];
- origin[2]=value[2];
-}
-
//--------------------------------------------------------------------
-void vvImage::SetTransform(vtkTransform *transform)
+void vvImage::UpdateReslice()
{
- mTransform = transform;
+ for (unsigned int i=0; i<mVtkImageReslice.size(); i++) {
+ mVtkImageReslice[i]->UpdateInformation();
+ mVtkImageReslice[i]->UpdateWholeExtent();
+ mVtkImageReslice[i]->Update();
+ mVtkImageReslice[i]->UpdateInformation();
+ mVtkImageReslice[i]->UpdateWholeExtent();
+ mVtkImageReslice[i]->Update();
+ }
}
//--------------------------------------------------------------------
/*=========================================================================
Program: vv http://www.creatis.insa-lyon.fr/rio/vv
- Authors belong to:
+ Authors belong to:
- University of LYON http://www.universite-lyon.fr/
- Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
#include <QApplication>
#include <vtkImageData.h>
#include <vtkSmartPointer.h>
+#include <vtkTransform.h>
#include "vvImage.h"
#include "vvSlicer.h"
#include <QString>
//------------------------------------------------------------------------------
vvToolRigidReg::vvToolRigidReg(vvMainWindowBase * parent, Qt::WindowFlags f):
- vvToolWidgetBase(parent, f),
- vvToolBase<vvToolRigidReg>(parent),
- Ui::vvToolRigidReg() {
+ vvToolWidgetBase(parent, f),
+ vvToolBase<vvToolRigidReg>(parent),
+ Ui::vvToolRigidReg()
+{
// GUI Initialization
Ui_vvToolRigidReg::setupUi(mToolWidget);
-
+
// Set how many inputs are needed for this tool
AddInputSelector("Select the Reference Image");
AddInputSelector("Select the Target Image");
- }
+}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-vvToolRigidReg::~vvToolRigidReg() {
+vvToolRigidReg::~vvToolRigidReg()
+{
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-bool vvToolRigidReg::close() {
- return vvToolWidgetBase::close();
+bool vvToolRigidReg::close()
+{
+ return vvToolWidgetBase::close();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::reject() {
- return vvToolWidgetBase::reject();
+void vvToolRigidReg::reject()
+{
+ return vvToolWidgetBase::reject();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::InputIsSelected(std::vector<vvSlicerManager *> & l) {
+void vvToolRigidReg::InputIsSelected(std::vector<vvSlicerManager *> & l)
+{
//inputs
mInput1 = l[0];
- mInput2 = l[1];
+ mInput2 = l[1];
mTwoInputs = true;
-
-
+
+
SetOverlay();
- for (int j = 1; j <= 4; j++)
- {
- mCurrentSlicerManager->GetSlicer(j-1)->SetActorVisibility("overlay",0,true);
- }
+ for (int j = 1; j <= 4; j++) {
+ mCurrentSlicerManager->GetSlicer(j-1)->SetActorVisibility("overlay",0,true);
+ }
mCurrentSlicerManager->Render();
- origin = new double[3];
std::vector<int> imagesize;
imagesize=mCurrentSlicerManager->GetImage()->GetSize();
+ std::vector<double> imageorigin;
+ imageorigin=mCurrentSlicerManager->GetImage()->GetOrigin();
QString xcord,ycord,zcord;
- //default image origin is its centroid
- xcord=xcord.setNum(imagesize[0]*mCurrentSlicerManager->GetImage()->GetSpacing()[0]/2);
- ycord=ycord.setNum(imagesize[1]*mCurrentSlicerManager->GetImage()->GetSpacing()[1]/2);
- zcord=zcord.setNum(imagesize[2]*mCurrentSlicerManager->GetImage()->GetSpacing()[2]/2);
-
- Xval->setText(xcord);Yval->setText(ycord);Zval->setText(zcord);
- origin[0]=xcord.toDouble();origin[1]=ycord.toDouble();origin[2]=zcord.toDouble();
- this->mCurrentSlicerManager->GetImage()->SetOrigin(origin);
-
+ //default image rotation center is the center of the image
+ xcord=xcord.setNum(imageorigin[0]+imagesize[0]*mCurrentSlicerManager->GetImage()->GetSpacing()[0]/2, 'g', 3);
+ ycord=ycord.setNum(imageorigin[1]+imagesize[1]*mCurrentSlicerManager->GetImage()->GetSpacing()[1]/2, 'g', 3);
+ zcord=zcord.setNum(imageorigin[2]+imagesize[2]*mCurrentSlicerManager->GetImage()->GetSpacing()[2]/2, 'g', 3);
+
+ Xval->setText(xcord);
+ Yval->setText(ycord);
+ Zval->setText(zcord);
+
xtrans_slider->setMaximum(2*mCurrentSlicerManager->GetImage()->GetSize()[0]);
xtrans_slider->setMinimum(-2*mCurrentSlicerManager->GetImage()->GetSize()[0]);
ytrans_slider->setMaximum(2*mCurrentSlicerManager->GetImage()->GetSize()[1]);
ztrans_slider->setMaximum(2*mCurrentSlicerManager->GetImage()->GetSize()[2]);
ztrans_slider->setMinimum(-2*mCurrentSlicerManager->GetImage()->GetSize()[2]);
-
+
xtrans_sb->setMaximum(2*mCurrentSlicerManager->GetImage()->GetSize()[0]);
xtrans_sb->setMinimum(-2*mCurrentSlicerManager->GetImage()->GetSize()[0]);
ytrans_sb->setMaximum(2*mCurrentSlicerManager->GetImage()->GetSize()[1]);
zrot_slider->setMaximum(360);
zrot_slider->setMinimum(-360);
-
+
xrot_sb->setMaximum(360);
xrot_sb->setMinimum(-360);
yrot_sb->setMaximum(360);
yrot_sb->setMinimum(-360);
zrot_sb->setMaximum(360);
zrot_sb->setMinimum(-360);
-
+
//connect all sigs to slots
connect(Xval, SIGNAL(editingFinished()), this, SLOT(SetXvalue()));
connect(Yval, SIGNAL(editingFinished()), this, SLOT(SetYvalue()));
connect(Zval, SIGNAL(editingFinished()), this, SLOT(SetZvalue()));
connect(xtrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateXtranslider()));
connect(ytrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateYtranslider()));
- connect(ztrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateZtranslider()));
+ connect(ztrans_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateZtranslider()));
connect(xrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateXrotslider()));
connect(yrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateYrotslider()));
- connect(zrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateZrotslider()));
+ connect(zrot_slider, SIGNAL(valueChanged(int)), this, SLOT(UpdateZrotslider()));
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::apply() {
-
+void vvToolRigidReg::apply()
+{
+
}
//------------------------------------------------------------------------------
-
+
//------------------------------------------------------------------------------
void vvToolRigidReg::SetOverlay()
{
- for(int i =0;i<mCurrentSlicerManager->NumberOfSlicers();i++)
- {
+ for (int i =0; i<mCurrentSlicerManager->NumberOfSlicers(); i++) {
mCurrentSlicerManager->GetSlicer(i)->SetOverlay(mInput2->GetImage());
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::SetXvalue() {
+void vvToolRigidReg::SetXvalue()
+{
QString xstr = Xval->text();
- origin[0]= xstr.toDouble();
- this->mCurrentSlicerManager->GetImage()->SetOrigin(origin);
-
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::SetYvalue() {
+void vvToolRigidReg::SetYvalue()
+{
QString ystr = Yval->text();
- origin[1]= ystr.toDouble();
- this->mCurrentSlicerManager->GetImage()->SetOrigin(origin);
-
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::SetZvalue() {
+void vvToolRigidReg::SetZvalue()
+{
QString zstr = Zval->text();
- origin[2]= zstr.toDouble();
- this->mCurrentSlicerManager->GetImage()->SetOrigin(origin);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvToolRigidReg::SetTransform(double tX, double tY, double tZ, double aX, double aY, double aZ)
+{
+
+ vtkSmartPointer<vtkTransform> transform = mCurrentSlicerManager->GetImage()->GetTransform();
+ transform->PostMultiply();
+
+ //Rotations
+ if (aX!=0 || aY!=0 || aZ!=0) {
+ double x, y ,z;
+ x= Xval->text().toDouble();
+ y= Yval->text().toDouble();
+ z= Zval->text().toDouble();
+ transform->Translate(-x,-y,-z);
+ if (aX!=0) transform->RotateX(aX);
+ if (aY!=0) transform->RotateY(aY);
+ if (aZ!=0) transform->RotateZ(aZ);
+ transform->Translate(x,y,z);
+ }
+
+ //Translations
+ if (tX!=0 || tY!=0 || tZ!=0)
+ transform->Translate(tX,tY,tZ);
+
+ transform->Update();
+ for (int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++) {
+ mCurrentSlicerManager->GetImage()->UpdateReslice();
+ mCurrentSlicerManager->GetSlicer(i)->Render();
+ }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-void vvToolRigidReg::UpdateXtranslider(){
-
- int diff=0;
- diff=xtrans_slider->value()-xtrans_sb->value();
- mCurrentSlicerManager->GetImage()->SetTranslationX(diff);//perform the translation difference
- for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++)
- {
- mCurrentSlicerManager->GetSlicer(i)->Render();
- }
- xtrans_sb->setValue(xtrans_slider->value());
+void vvToolRigidReg::UpdateXtranslider()
+{
+
+ int diff=0;
+ diff=xtrans_slider->value()-xtrans_sb->value();
+ this->SetTransform(diff, 0, 0, 0, 0, 0);
+ xtrans_sb->setValue(xtrans_slider->value());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvToolRigidReg::UpdateYtranslider()
-{
- int diff=0;
- diff=ytrans_slider->value()-ytrans_sb->value();
- mCurrentSlicerManager->GetImage()->SetTranslationY(diff);//perform the translation difference
- for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++)
- {
- mCurrentSlicerManager->GetSlicer(i)->Render();
- }
- ytrans_sb->setValue(ytrans_slider->value());
+{
+ int diff=0;
+ diff=ytrans_slider->value()-ytrans_sb->value();
+ this->SetTransform(0, diff, 0, 0, 0, 0);
+ ytrans_sb->setValue(ytrans_slider->value());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvToolRigidReg::UpdateZtranslider()
{
- int diff=0;
- diff=ztrans_slider->value()-ztrans_sb->value();
- mCurrentSlicerManager->GetImage()->SetTranslationZ(diff);
- for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++)
- {
- mCurrentSlicerManager->GetSlicer(i)->Render();
- }
- ztrans_sb->setValue(ztrans_slider->value());
+ int diff=0;
+ diff=ztrans_slider->value()-ztrans_sb->value();
+ this->SetTransform(0, 0, diff, 0, 0, 0);
+ ztrans_sb->setValue(ztrans_slider->value());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvToolRigidReg::UpdateXrotslider()
{
- int diff=0;
- diff=xrot_slider->value()-xrot_sb->value();
- mCurrentSlicerManager->GetImage()->SetRotateX(diff);
- for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++)
- {
- mCurrentSlicerManager->GetSlicer(i)->Render();
- }
- xrot_sb->setValue(xrot_slider->value());
+ int diff=0;
+ diff=xrot_slider->value()-xrot_sb->value();
+ this->SetTransform(0, 0, 0, diff, 0, 0);
+ xrot_sb->setValue(xrot_slider->value());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvToolRigidReg::UpdateYrotslider()
{
- int diff=0;
- diff=yrot_slider->value()-yrot_sb->value();
- mCurrentSlicerManager->GetImage()->SetRotateY(diff);
- for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++)
- {
- mCurrentSlicerManager->GetSlicer(i)->Render();
- }
- yrot_sb->setValue(yrot_slider->value());
+ int diff=0;
+ diff=yrot_slider->value()-yrot_sb->value();
+ this->SetTransform(0, 0, 0, 0, diff, 0);
+ yrot_sb->setValue(yrot_slider->value());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void vvToolRigidReg::UpdateZrotslider()
{
- int diff=0;
- diff=zrot_slider->value()-zrot_sb->value();
- mCurrentSlicerManager->GetImage()->SetRotateZ(diff);
- for(int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++)
- {
- mCurrentSlicerManager->GetSlicer(i)->Render();
- }
- zrot_sb->setValue(zrot_slider->value());
+ int diff=0;
+ diff=zrot_slider->value()-zrot_sb->value();
+ this->SetTransform(0, 0, 0, 0, 0, diff);
+ zrot_sb->setValue(zrot_slider->value());
}