]> Creatis software - clitk.git/commitdiff
Adapted manual rigid registration: less functions in vvImage, more on vvToolRigidRed...
authorsrit <srit>
Wed, 28 Apr 2010 12:49:22 +0000 (12:49 +0000)
committersrit <srit>
Wed, 28 Apr 2010 12:49:22 +0000 (12:49 +0000)
Changed formatting to new coding style.

common/vvImage.cxx
common/vvImage.h
vv/vvToolRigidReg.cxx
vv/vvToolRigidReg.h

index a394c7608456b9d0de2f06f88ceeb3a7bfbd993c..be2690a512a930b1d31e3b2905c1761feac637e7 100644 (file)
@@ -176,8 +176,6 @@ std::vector<double> vvImage::GetSpacing()
   }
   return spacing;
 }
-//--------------------------------------------------------------------
-
 //--------------------------------------------------------------------
 std::vector<double> vvImage::GetOrigin() const
 {
@@ -274,77 +272,31 @@ bool vvImage::IsScalarTypeInteger(int t)
 //--------------------------------------------------------------------
 
 //--------------------------------------------------------------------
-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();
+  }
 }
 //--------------------------------------------------------------------
 
index 49695bb106286a1f5ba4c557d26369319c3dd07f..38348eece3d2db2ecc67ea8bf28d1d5f41cec4d9 100644 (file)
@@ -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<vtkTransform> GetTransform();
+  void SetTransform(vtkSmartPointer<vtkTransform> 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<vtkImageData*> mVtkImages;
   std::vector< vtkSmartPointer<vtkImageReslice> > mVtkImageReslice;
   vtkSmartPointer<vtkTransform> mTransform;
   double mTimeOrigin;
   double mTimeSpacing;
-  double * origin;
 };
 
 #endif
index dcea325e310ab51468ba9eda1025a5e5679e4014..2473e655b0f84e078868120dbbf93c98087e5608 100644 (file)
@@ -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 <QApplication>
 #include <vtkImageData.h>
 #include <vtkSmartPointer.h>
+#include <vtkTransform.h>
 #include "vvImage.h"
 #include "vvSlicer.h"
 #include <QString>
@@ -35,68 +36,73 @@ ADD_TOOL(vvToolRigidReg);
 
 //------------------------------------------------------------------------------
 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]);
@@ -104,7 +110,7 @@ void vvToolRigidReg::InputIsSelected(std::vector<vvSlicerManager *> & 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<vvSlicerManager *> & 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;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());
 }
index cce7aba3329a462e99b027a2707147045d48b302..b6e0341c0bd437a1b5a4e132ff28a770a37dd8c2 100644 (file)
@@ -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
 
 //------------------------------------------------------------------------------
 class vvToolRigidReg:
-  public vvToolWidgetBase,
-  public vvToolBase<vvToolRigidReg>, 
-  private Ui::vvToolRigidReg 
+    public vvToolWidgetBase,
+    public vvToolBase<vvToolRigidReg>,
+    private Ui::vvToolRigidReg
 {
   Q_OBJECT
-    public:
+public:
   vvToolRigidReg(vvMainWindowBase * parent=0, Qt::WindowFlags f=0);
   ~vvToolRigidReg();
-   virtual void InputIsSelected(std::vector<vvSlicerManager *> & m);
+  virtual void InputIsSelected(std::vector<vvSlicerManager *> & 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
 //------------------------------------------------------------------------------