From: srit Date: Wed, 28 Apr 2010 12:49:22 +0000 (+0000) Subject: Adapted manual rigid registration: less functions in vvImage, more on vvToolRigidRed... X-Git-Tag: v1.2.0~676 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=916b360a5059598577cb44f87381ccb1f0514476;p=clitk.git Adapted manual rigid registration: less functions in vvImage, more on vvToolRigidRed (with bharath). Changed formatting to new coding style. --- diff --git a/common/vvImage.cxx b/common/vvImage.cxx index a394c76..be2690a 100644 --- a/common/vvImage.cxx +++ b/common/vvImage.cxx @@ -176,8 +176,6 @@ std::vector vvImage::GetSpacing() } return spacing; } -//-------------------------------------------------------------------- - //-------------------------------------------------------------------- std::vector vvImage::GetOrigin() const { @@ -274,77 +272,31 @@ bool vvImage::IsScalarTypeInteger(int t) //-------------------------------------------------------------------- //-------------------------------------------------------------------- -vtkTransform * vvImage::GetTransform() +vtkSmartPointer 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 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; iUpdateInformation(); + mVtkImageReslice[i]->UpdateWholeExtent(); + mVtkImageReslice[i]->Update(); + mVtkImageReslice[i]->UpdateInformation(); + mVtkImageReslice[i]->UpdateWholeExtent(); + mVtkImageReslice[i]->Update(); + } } //-------------------------------------------------------------------- diff --git a/common/vvImage.h b/common/vvImage.h index 49695bb..38348ee 100644 --- a/common/vvImage.h +++ b/common/vvImage.h @@ -58,32 +58,28 @@ public : bool IsTimeSequence(); bool IsScalarTypeInteger(); bool IsScalarTypeInteger(int t); - vtkTransform * GetTransform(); - void SetTransform(vtkTransform *transform); - vtkImageReslice* GetVTKImageReslice(); - void SetVTKImageReslice(vtkImageReslice *reslice); - void SetRotateX(int xvalue); - void SetRotateY(int yvalue); - void SetRotateZ(int zvalue); + vtkSmartPointer GetTransform(); + void SetTransform(vtkSmartPointer transform); - void SetTranslationX(int xvalue); - void SetTranslationY(int yvalue); - void SetTranslationZ(int zvalue); - void SetOrigin(double value[3]); + void SetTimeSpacing(double s) { + mTimeSpacing = s; + } + void SetTimeOrigin(double o) { + mTimeOrigin = o; + } - void SetTimeSpacing(double s) { mTimeSpacing = s; } - void SetTimeOrigin(double o) { mTimeOrigin = o; } + void UpdateReslice(); private: vvImage(); ~vvImage(); + std::vector mVtkImages; std::vector< vtkSmartPointer > mVtkImageReslice; vtkSmartPointer mTransform; double mTimeOrigin; double mTimeSpacing; - double * origin; }; #endif diff --git a/vv/vvToolRigidReg.cxx b/vv/vvToolRigidReg.cxx index dcea325..2473e65 100644 --- a/vv/vvToolRigidReg.cxx +++ b/vv/vvToolRigidReg.cxx @@ -1,7 +1,7 @@ /*========================================================================= 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 @@ -21,6 +21,7 @@ #include #include #include +#include #include "vvImage.h" #include "vvSlicer.h" #include @@ -35,68 +36,73 @@ ADD_TOOL(vvToolRigidReg); //------------------------------------------------------------------------------ vvToolRigidReg::vvToolRigidReg(vvMainWindowBase * parent, Qt::WindowFlags f): - vvToolWidgetBase(parent, f), - vvToolBase(parent), - Ui::vvToolRigidReg() { + vvToolWidgetBase(parent, f), + vvToolBase(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 & l) { +void vvToolRigidReg::InputIsSelected(std::vector & 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 imagesize; imagesize=mCurrentSlicerManager->GetImage()->GetSize(); + std::vector 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]); @@ -104,7 +110,7 @@ void vvToolRigidReg::InputIsSelected(std::vector & l) { 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]); @@ -119,149 +125,153 @@ void vvToolRigidReg::InputIsSelected(std::vector & l) { 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;iNumberOfSlicers();i++) - { + for (int i =0; iNumberOfSlicers(); 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 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; iNumberOfSlicers(); 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; iNumberOfSlicers(); 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; iNumberOfSlicers(); 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; iNumberOfSlicers(); 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; iNumberOfSlicers(); 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; iNumberOfSlicers(); 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; iNumberOfSlicers(); 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()); } diff --git a/vv/vvToolRigidReg.h b/vv/vvToolRigidReg.h index cce7aba..b6e0341 100644 --- a/vv/vvToolRigidReg.h +++ b/vv/vvToolRigidReg.h @@ -1,7 +1,7 @@ /*========================================================================= 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 @@ -28,15 +28,15 @@ //------------------------------------------------------------------------------ class vvToolRigidReg: - public vvToolWidgetBase, - public vvToolBase, - private Ui::vvToolRigidReg + public vvToolWidgetBase, + public vvToolBase, + private Ui::vvToolRigidReg { Q_OBJECT - public: +public: vvToolRigidReg(vvMainWindowBase * parent=0, Qt::WindowFlags f=0); ~vvToolRigidReg(); - virtual void InputIsSelected(std::vector & m); + virtual void InputIsSelected(std::vector & m); public slots: virtual void apply(); virtual bool close(); @@ -48,23 +48,23 @@ public slots: SetToolIconFilename(":/common/icons/register.png"); SetToolTip("Register Image."); } - void SetXvalue(); - void SetYvalue(); - void SetZvalue(); - void UpdateXtranslider(); - void UpdateYtranslider(); - void UpdateZtranslider(); - void UpdateXrotslider(); - void UpdateYrotslider(); - void UpdateZrotslider(); - void SetOverlay(); - protected: + void SetXvalue(); + void SetYvalue(); + void SetZvalue(); + void UpdateXtranslider(); + void UpdateYtranslider(); + void UpdateZtranslider(); + void UpdateXrotslider(); + void UpdateYrotslider(); + void UpdateZrotslider(); + void SetOverlay(); +protected: Ui::vvToolRigidReg ui; vvSlicerManager * mInput1; vvSlicerManager * mInput2; vvMainWindow * mWindow; bool mTwoInputs; - double * origin; + void SetTransform(double tX, double tY, double tZ, double aX, double aY, double aZ); }; // end class vvToolRigidReg //------------------------------------------------------------------------------