// clitk
#include "clitkTransformUtilities.h"
-
+#include "clitkAffineRegistrationGenericFilter.h"
// qt
#include <QMessageBox>
#include <QFileDialog>
// 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);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
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;
}
//------------------------------------------------------------------------------
//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()));
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()));
//------------------------------------------------------------------------------
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();
}
}
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();
}
//------------------------------------------------------------------------------
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();
}
//------------------------------------------------------------------------------
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));
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);
if(sliders){
xtrans_slider->blockSignals(true);
- DD(xtrans_slider->value());
xtrans_slider->setValue(rint(xtrans));
xtrans_slider->blockSignals(false);
ytrans_slider->blockSignals(true);
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);
zrot_slider->setRange(-360,360);
zrot_slider->blockSignals(false);
-
xrot_sb->blockSignals(true);
xrot_sb->setRange(-360,360);
xrot_sb->blockSignals(false);