X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvToolRigidReg.cxx;h=5a11c7f8e367dad022cf08bc8b54cf06a92e92ed;hb=7d4e77191e55f668f316ba3ddf0fddb63e59bd25;hp=1a2d1c7679a71c3bee66a7ad249b692cd59e4717;hpb=f08c6ee2ae829766aa8871f76feab9bca7d8afd1;p=clitk.git diff --git a/vv/vvToolRigidReg.cxx b/vv/vvToolRigidReg.cxx index 1a2d1c7..5a11c7f 100644 --- a/vv/vvToolRigidReg.cxx +++ b/vv/vvToolRigidReg.cxx @@ -19,17 +19,23 @@ // vv #include "vvToolRigidReg.h" #include "vvSlicer.h" +#include // vtk #include #include +#include #include +#include +#include +#include // itk #include // clitk #include "clitkTransformUtilities.h" +#include "clitkMatrix.h" // qt #include @@ -108,9 +114,9 @@ void vvToolRigidReg::InputIsSelected(vvSlicerManager *input) imageorigin=mInput->GetImage()->GetOrigin(); std::vector imageSize = mInput->GetImage()->GetSize(); std::vector imageSpacing = mInput->GetImage()->GetSpacing(); - xcord=xcord.setNum(imageorigin[0]+imageSize[0]*imageSpacing[0]/2, 'g', 3); - ycord=ycord.setNum(imageorigin[1]+imageSize[1]*imageSpacing[1]/2, 'g', 3); - zcord=zcord.setNum(imageorigin[2]+imageSize[2]*imageSpacing[2]/2, 'g', 3); + xcord=xcord.setNum(imageorigin[0]+(imageSize[0]-1)*imageSpacing[0]*0.5, 'g', 3); + ycord=ycord.setNum(imageorigin[1]+(imageSize[1]-1)*imageSpacing[1]*0.5, 'g', 3); + zcord=zcord.setNum(imageorigin[2]+(imageSize[2]-1)*imageSpacing[2]*0.5, 'g', 3); Xval->setText(xcord); Yval->setText(ycord); Zval->setText(zcord); @@ -118,8 +124,9 @@ void vvToolRigidReg::InputIsSelected(vvSlicerManager *input) //backup original matrix for(int j=0; j<4; j++) for(int i=0; i<4; i++) - mInitialMatrix->SetElement(i,j, mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()->GetElement(i,j)); - QString origTransformString = dynamic_cast(mMainWindow)->Get4x4MatrixDoubleAsString(mInitialMatrix); + // TODO SR and BP: check on the list of transforms and not the first only + mInitialMatrix->SetElement(i,j, mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix()->GetElement(i,j)); + QString origTransformString(clitk::Get4x4MatrixDoubleAsString(mInitialMatrix).c_str()); transformationLabel->setText(origTransformString); SetTransform(mInitialMatrix); @@ -171,7 +178,8 @@ bool vvToolRigidReg::close() msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole); msgBox.addButton(tr("No"), QMessageBox::RejectRole); if (msgBox.exec() == QMessageBox::AcceptRole) { - SetTransform(mInitialMatrix); + if (mCurrentSlicerManager) + SetTransform(mInitialMatrix); return vvToolWidgetBase::close(); } return false; @@ -230,19 +238,20 @@ void vvToolRigidReg::SpinBoxChange(double newVal) for(int i=0; i<3; i++) { if(transSBs[i] == QObject::sender()) { transSliders[i]->blockSignals(true); - transSliders[i]->setValue(itk::Math::Round(newVal)); + transSliders[i]->setValue(itk::Math::Round(newVal)); transSliders[i]->blockSignals(false); } if(rotSBs[i] == QObject::sender()) { double rad = (checkBoxDegrees->checkState()==Qt::Unchecked)?180./itk::Math::pi:1.; rotSliders[i]->blockSignals(true); - rotSliders[i]->setValue(itk::Math::Round(newVal*rad)); + rotSliders[i]->setValue(itk::Math::Round(newVal*rad)); rotSliders[i]->blockSignals(false); } } // Compute transform and set - vtkSmartPointer transform_final=mInput->GetImage()->GetTransform(); + // TODO SR and BP: check on the list of transforms and not the first only + vtkSmartPointer transform_final=mInput->GetImage()->GetTransform()[0]; transform_final->Identity(); transform_final->PostMultiply(); @@ -294,8 +303,9 @@ void vvToolRigidReg::SaveFile() QFile file(filename); if (file.open(QFile::WriteOnly | QFile::Truncate)) { - vtkMatrix4x4* matrix = mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix(); - QString matrixStr = dynamic_cast(mMainWindow)->Get4x4MatrixDoubleAsString(matrix,16); + // TODO SR and BP: check on the list of transforms and not the first only + vtkMatrix4x4* matrix = mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix(); + QString matrixStr = clitk::Get4x4MatrixDoubleAsString(matrix,16).c_str(); QTextStream out(&file); out << matrixStr; } @@ -332,7 +342,8 @@ void vvToolRigidReg::LoadFile() //------------------------------------------------------------------------------ void vvToolRigidReg::ChangeOfRotationCenter() { - SetTransform(mCurrentSlicerManager->GetImage()->GetTransform()->GetMatrix()); + // TODO SR and BP: check on the list of transforms and not the first only + SetTransform(mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix()); } //------------------------------------------------------------------------------ @@ -347,7 +358,8 @@ void vvToolRigidReg::ResetTransform() void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix) { vtkSmartPointer transform=vtkSmartPointer::New(); - mCurrentSlicerManager->GetImage()->GetTransform()->SetMatrix(matrix); + // TODO SR and BP: check on the list of transforms and not the first only + mCurrentSlicerManager->GetImage()->GetTransform()[0]->SetMatrix(matrix); transform->Update(); Render(); dynamic_cast(mMainWindow)->ImageInfoChanged(); @@ -367,28 +379,51 @@ void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix) itk::Euler3DTransform::Pointer euler; euler = itk::Euler3DTransform::New(); euler->SetCenter(center); - euler->SetMatrix(rotMat); + try { +#if ITK_VERSION_MAJOR > 4 || (ITK_VERSION_MAJOR == 4 && ITK_VERSION_MINOR > 6) + euler->SetMatrix(rotMat,0.00001); +#else + euler->SetMatrix(rotMat); +#endif + } catch (itk::ExceptionObject) { + QString warning = "The matrice is a non-orthogonal rotation matrix.\nThe manual registration doesn't work."; + QMessageBox msgBox(QMessageBox::Warning, tr("Reset transform"),warning, 0, this); + msgBox.addButton(tr("OK"), QMessageBox::AcceptRole); + if (msgBox.exec() == QMessageBox::AcceptRole) { + //SetTransform(mInitialMatrix); + vvToolWidgetBase::close(); + } + } euler->SetOffset(transVec); - // Modify GUI according to the new parameters std::vector transSliders, rotSliders; std::vector transSBs, rotSBs; GetSlidersAndSpinBoxes(transSliders, rotSliders, transSBs, rotSBs); for(int i=0; i<3; i++) { + // Translations transSBs[i]->blockSignals(true); transSBs[i]->setValue( euler->GetParameters()[i+3] ); transSBs[i]->blockSignals(false); transSliders[i]->blockSignals(true); - transSliders[i]->setValue( itk::Math::Round(euler->GetParameters()[i+3]) ); + transSliders[i]->setValue( itk::Math::Round(euler->GetParameters()[i+3]) ); transSliders[i]->blockSignals(false); + + // Rotations double rad = (checkBoxDegrees->checkState()==Qt::Checked)?180./itk::Math::pi:1.; - rotSBs[i]->blockSignals(true); - rotSBs[i]->setValue( euler->GetParameters()[i]*rad ); - rotSBs[i]->blockSignals(false); - rotSliders[i]->blockSignals(true); - rotSliders[i]->setValue( itk::Math::Round(euler->GetParameters()[i]*180./itk::Math::pi) ); - rotSliders[i]->blockSignals(false); + double angleDiff = euler->GetParameters()[i]-rotSBs[i]->value()/rad+2*itk::Math::pi; + angleDiff = angleDiff - 2*itk::Math::pi*itk::Math::Round(angleDiff/(2*itk::Math::pi)); + if(std::abs(angleDiff)>1.e-4) { + rotSBs[i]->blockSignals(true); + rotSBs[i]->setValue( euler->GetParameters()[i]*rad ); + rotSBs[i]->blockSignals(false); + } + int iAngle = itk::Math::Round(euler->GetParameters()[i]*180./itk::Math::pi); + if((iAngle-rotSliders[i]->value()+360)%360!=0) { + rotSliders[i]->blockSignals(true); + rotSliders[i]->setValue(iAngle); + rotSliders[i]->blockSignals(false); + } } } //------------------------------------------------------------------------------ @@ -416,14 +451,34 @@ void vvToolRigidReg::GetSlidersAndSpinBoxes(std::vector&transSliders, } //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvToolRigidReg::ExtentMax(const double pointExtent[8][4], double maxExtent[2][3]) +{ + double max, min; + for (int i=0; i<3; ++i) { + max = pointExtent[0][i]; + min = pointExtent[0][i]; + for (int j=1; j<8; ++j) { + if (pointExtent[j][i] > max) { + max = pointExtent[j][i]; + } + if (pointExtent[j][i] < min) { + min = pointExtent[j][i]; + } + } + maxExtent[0][i] = min; + maxExtent[1][i] = max; + } +} +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ void vvToolRigidReg::Render() { - for (int i=0; iGetNumberOfSlicers(); i++) - { +for (int i=0; iGetNumberOfSlicers(); i++) { mCurrentSlicerManager->GetSlicer(i)->ForceUpdateDisplayExtent(); mCurrentSlicerManager->GetSlicer(i)->Render(); - } +} } //------------------------------------------------------------------------------