]> Creatis software - clitk.git/commitdiff
Added AutoRegister..........
authorbharath <bharath>
Sun, 1 Aug 2010 20:28:58 +0000 (20:28 +0000)
committerbharath <bharath>
Sun, 1 Aug 2010 20:28:58 +0000 (20:28 +0000)
vv/vvToolRigidReg.cxx

index f83136c11949ce5c804646ebf270b688c5cb0de7..64fbf4198326ae65367dc27cc285df6cab5765a3 100644 (file)
@@ -28,7 +28,7 @@
 
 // clitk
 #include "clitkTransformUtilities.h"
-
+#include "clitkAffineRegistrationGenericFilter.h"      
 // qt
 #include <QMessageBox>
 #include <QFileDialog>
@@ -58,10 +58,11 @@ vvToolRigidReg::vvToolRigidReg(vvMainWindowBase * parent, Qt::WindowFlags f):
 
   // Set how many inputs are needed for this tool
  // mFilter = new clitk::AffineTransformGenericFilter<args_info_clitkAffineTransform>;
+  mFilter = new clitk::AffineRegistrationGenericFilter<args_info_clitkAffineRegistration>;
 
   // Set how many inputs are needed for this tool
- AddInputSelector("Select moving image");
- AddInputSelector("Select fixed image");
+ AddInputSelector("Select moving image",mFilter);
+ AddInputSelector("Select fixed image",mFilter);
 }
 //------------------------------------------------------------------------------
 
@@ -83,14 +84,90 @@ bool vvToolRigidReg::close()
 //------------------------------------------------------------------------------
 void vvToolRigidReg::reject()
 {
-   return vvToolWidgetBase::reject();
+
+  return vvToolWidgetBase::reject();
 }
 //------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
 void vvToolRigidReg::GetArgsInfoFromGUI()
 {
-  DD("works");
+  QString str;
+  str.append("Configs Loaded for AutoRegister...Apply Filter...");
+    tab2textedit->setText(str);
+ /* cmdline_parser_clitkAffineRegistration_configfile("/home/bharath/bin/AffineReg.txt",&mArgsInfo,1,1,0);
+    mArgsInfo.reference_arg=new char;
+  mArgsInfo.target_arg=new char;
+  mArgsInfo.output_arg=new char;
+  mArgsInfo.referenceMask_arg=new char;
+  mArgsInfo.targetMask_arg=new char;
+  mArgsInfo.initMatrix_arg=new char;
+  mArgsInfo.matrix_arg=new char;*/
+  mArgsInfo.referenceMask_given=0;
+  mArgsInfo.reference_given=0;
+  mArgsInfo.reference_arg=new char;
+  mArgsInfo.target_given=0;
+  mArgsInfo.target_arg=new char;
+  mArgsInfo.output_given=0;
+  mArgsInfo.output_arg=new char;
+  mArgsInfo.checker_after_given=0;
+  mArgsInfo.checker_before_given=0;
+  mArgsInfo.after_given=0;
+  mArgsInfo.before_given=0;
+ // std::string strouput= "/home/bharath/bin/Lung3Doutput.mhd";
+  //mArgsInfo.output_arg=const_cast<char*>(strouput.c_str());
+  mArgsInfo.threads_given=1;
+  mArgsInfo.threads_arg=3;
+  mArgsInfo.normalize_flag=0;
+  DD("GetArgsInfoFromGUI_2");
+  mArgsInfo.blur_arg=0.0;
+  mArgsInfo.referenceMask_arg=new char;
+  mArgsInfo.targetMask_arg=new char;
+  mArgsInfo.targetMask_given=0;
+  mArgsInfo.levels_given=1;
+  mArgsInfo.levels_arg=2;
+  mArgsInfo.moment_flag=1;
+  mArgsInfo.intThreshold_given=0;
+  mArgsInfo.intThreshold_arg=0.0;
+  mArgsInfo.transX_arg=0.0;
+  mArgsInfo.transY_arg=0.0;
+  mArgsInfo.transZ_arg=0.0;
+  mArgsInfo.transform_arg=2;
+  mArgsInfo.gradient_flag=1;
+  mArgsInfo.interp_given=1;
+  mArgsInfo.interp_arg=1;
+  mArgsInfo.interpOrder_given=1;
+  mArgsInfo.interpOrder_arg=3;
+  mArgsInfo.interpSF_given=1;
+  mArgsInfo.interpSF_arg=20;//default
+  mArgsInfo.metric_given=1;
+  mArgsInfo.metric_arg=0;
+  mArgsInfo.samples_arg=1;//default
+  mArgsInfo.stdDev_arg=0.4;
+  mArgsInfo.step_arg=2.0;
+  mArgsInfo.relax_arg=0.7;
+  mArgsInfo.valueTol_arg=0.01;
+  mArgsInfo.stepTol_arg=0.1;
+  mArgsInfo.gradTol_arg=1e-5;
+  mArgsInfo.lineAcc_arg=0.9;
+  mArgsInfo.convFactor_arg=1e+12;
+  mArgsInfo.maxIt_arg=500;
+  mArgsInfo.maxLineIt_arg=50;
+  mArgsInfo.maxEval_arg=500;
+  mArgsInfo.maxCorr_arg=5;
+  mArgsInfo.selectBound_arg=0;
+  mArgsInfo.inc_arg=1.2;
+  mArgsInfo.dec_arg=4;
+  mArgsInfo.optimizer_arg=1;
+  mArgsInfo.initMatrix_given=0;
+  mArgsInfo.initMatrix_arg=new char;
+   mArgsInfo.tWeight_given=1;
+    mArgsInfo.tWeight_arg=1.0;
+  mArgsInfo.rWeight_given=1.0;
+  mArgsInfo.rWeight_arg=50.0;
+  //  std::string str="/home/bharath/bin/matrix.txt";
+ // mArgsInfo.initMatrix_arg=const_cast<char*>(str.c_str());
+  mArgsInfo.matrix_given=0;
 }
 //------------------------------------------------------------------------------
 
@@ -119,7 +196,9 @@ void vvToolRigidReg::InputIsSelected(std::vector<vvSlicerManager *> & l)
 
     //connect all sigs to slots
    connect(resetbutton, SIGNAL(pressed()), this, SLOT(ResetTransform()));
-   connect(tab2loadbutton, SIGNAL(pressed()), this, SLOT(AutoRegister()));
+   connect(tab2loadbutton, SIGNAL(pressed()), this, SLOT(GetArgsInfoFromGUI()));
+   connect(tab2applybutton, SIGNAL(pressed()), this, SLOT(AutoRegister()));
+
 
    connect(Xval, SIGNAL(editingFinished()), this, SLOT(SetXvalue()));
    connect(Yval, SIGNAL(editingFinished()), this, SLOT(SetYvalue()));
@@ -140,7 +219,7 @@ void vvToolRigidReg::InputIsSelected(std::vector<vvSlicerManager *> & l)
    connect(xrot_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
    connect(yrot_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
    connect(zrot_sb, SIGNAL(valueChanged(double)), this, SLOT(UpdateTransform_sb()));
-
+   
    connect(loadbutton, SIGNAL(pressed()), this, SLOT(ReadFile()));
    connect(savebutton, SIGNAL(pressed()), this, SLOT(SaveFile()));
 
@@ -226,21 +305,20 @@ void vvToolRigidReg::SetTransform(double tX, double tY, double tZ, double aX, do
 //------------------------------------------------------------------------------
 void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix)
 {
-    vtkSmartPointer<vtkTransform> transform =mCurrentSlicerManager->GetImage()->GetTransform();
+    vtkSmartPointer<vtkTransform> transform=vtkSmartPointer<vtkTransform>::New();
     for(int i=0; i<4;i++)
       for(int j=0;j<4;j++)
-       mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->SetElement(i,j,matrix->GetElement(i,j));
-
+    mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->SetElement(i,j,matrix->GetElement(i,j));
     
     Render();
 }
 //------------------------------------------------------------------------------
-
+  
 //------------------------------------------------------------------------------
 void vvToolRigidReg::Render()
 {
     for (int i=0; i<mCurrentSlicerManager->NumberOfSlicers(); i++) {
-      mCurrentSlicerManager->GetSlicer(i)->ForceUpdateDisplayExtent();
+       mCurrentSlicerManager->GetSlicer(i)->ForceUpdateDisplayExtent();
       mCurrentSlicerManager->GetSlicer(i)->Render();
       }
 }
@@ -324,8 +402,8 @@ void vvToolRigidReg::UpdateTransform_sliders()
                         ytrans_slider->value()*mInput1->GetImage()->GetSpacing()[1],
                         ztrans_slider->value()*mInput1->GetImage()->GetSpacing()[2],
                        xrot_slider->value(),yrot_slider->value(),zrot_slider->value(),false);
-      UpdateTransform(true);
-      Render();
+        UpdateTransform(true);
+       // Render();
 }
 //------------------------------------------------------------------------------
 
@@ -336,20 +414,41 @@ void vvToolRigidReg::UpdateTransform_sb()
       ytrans_sb->value(),
       ztrans_sb->value(),
                        xrot_sb->value(),yrot_sb->value(),zrot_sb->value(),false);
+                       DD(xtrans_sb->value());
       UpdateTransform(false);
-      Render();
+   //   Render();
 }
 //------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
 void vvToolRigidReg::AutoRegister()
-{
- GetArgsInfoFromGUI();
-    //clitk::AffineRegistrationGenericFilter::Pointer filter =
-   // clitk::AffineRegistrationGenericFilter::New();
-    //filter->SetArgsInfo(mArgsInfo);
-   // filter->Update();
-
+{ 
+    if (!mCurrentSlicerManager) close();
+    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+  
+    std::vector<vvImage::Pointer> inputs;
+    // Input
+    inputs.push_back(mInput1->GetImage());
+    inputs.push_back(mInput2->GetImage());
+    // Check input type
+    // Main filter
+    clitk::AffineRegistrationGenericFilter<args_info_clitkAffineRegistration>::Pointer filter =
+    clitk::AffineRegistrationGenericFilter<args_info_clitkAffineRegistration>::New();
+    filter->SetInputVVImages(inputs);
+    filter->SetArgsInfo(mArgsInfo);
+    DD("ArgsInfo given in");
+    filter->EnableReadOnDisk(false);
+    filter->Update();
+    DD("I am done...! Updated");
+    vvImage::Pointer output = filter->GetOutputVVImage();
+    DD("filter getoutput done...");
+    std::ostringstream osstream;
+    osstream << "Registered" << "_ "
+           << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
+    AddImage(output,osstream.str());
+   
+    QApplication::restoreOverrideCursor();
+    close();
 }
 //------------------------------------------------------------------------------
 
@@ -435,33 +534,13 @@ void vvToolRigidReg::ReadFile()
    vtkSmartPointer<vtkTransform> transform = mCurrentSlicerManager->GetImage()->GetTransform();
 
    //Open File to read the transformation parameters
-   QString file1 = QFileDialog::getOpenFileName(
-                    this,
-                   "Choose the Transformation Parameters file",
-                    mMainWindow->GetInputPathName(),
-                    "Text (*.mat *.txt *.rtf *.doc)");
-    if (file1.isEmpty())
-    return;
-   QFile Qfile1(file1);
-  // ifstream readfile;
-   std::string transfile= file1.toStdString();
-   std::string filename1(transfile);
-   std::ifstream f1(filename1.c_str());
-   if(f1.is_open())
-   {
-   f1.close();
-   itk::Matrix<double, 4, 4> itkMat = clitk::ReadMatrix3D(transfile);
-   for(int j=0; j<4; j++)
-      for(int i=0; i<4; i++)
-    matrix->SetElement(i,j,itkMat[i][j]);
-   }
-    UpdateTextEditor(matrix,textEdit);
+  
     transform->SetMatrix(matrix);
     transform->GetOrientation(orientations);
     transform->PostMultiply();
 
      //Obtain the Rotation Center , set it to origin
-    Xval->setText(center.setNum(0));
+    Xval->setText(center.setNum(0));           
     Yval->setText(center.setNum(0));
     Zval->setText(center.setNum(0));
 
@@ -508,7 +587,7 @@ void vvToolRigidReg::SetRotationCenter()
     QString xcord,ycord,zcord;
     std::vector<double> imageorigin;
     imageorigin=mInput1->GetImage()->GetOrigin();
-
+    DD("before bug");
     xcord=xcord.setNum(imageorigin[0]+mImageSize[0]*mInput1->GetImage()->GetSpacing()[0]/2, 'g', 3);
     ycord=ycord.setNum(imageorigin[1]+mImageSize[1]*mInput1->GetImage()->GetSpacing()[1]/2, 'g', 3);
     zcord=zcord.setNum(imageorigin[2]+mImageSize[2]*mInput1->GetImage()->GetSpacing()[2]/2, 'g', 3);
@@ -539,7 +618,6 @@ void vvToolRigidReg::InitializeSliders(double xtrans,double ytrans, double ztran
 
     if(sliders){
     xtrans_slider->blockSignals(true);
-    DD(xtrans_slider->value());
     xtrans_slider->setValue(rint(xtrans));
     xtrans_slider->blockSignals(false);
     ytrans_slider->blockSignals(true);
@@ -550,7 +628,7 @@ void vvToolRigidReg::InitializeSliders(double xtrans,double ytrans, double ztran
     ztrans_slider->blockSignals(false);
     }
     xrot_sb->blockSignals(true);
-    xrot_sb->setValue(xrot);
+    xrot_sb->setValue(xrot);                                                                   
     xrot_sb->blockSignals(false);
     yrot_sb->blockSignals(true);
     yrot_sb->setValue(yrot);
@@ -612,7 +690,6 @@ void vvToolRigidReg::SetSliderRanges()
   zrot_slider->setRange(-360,360);
   zrot_slider->blockSignals(false);
 
-
   xrot_sb->blockSignals(true);
   xrot_sb->setRange(-360,360);
   xrot_sb->blockSignals(false);