]> Creatis software - clitk.git/blobdiff - vv/vvToolRigidReg.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvToolRigidReg.cxx
index a3ee90233c8d30b5a047b444a5dcfd2c8dd9336c..5a11c7f8e367dad022cf08bc8b54cf06a92e92ed 100644 (file)
@@ -178,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;
@@ -378,7 +379,21 @@ void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix)
   itk::Euler3DTransform<double>::Pointer euler;
   euler = itk::Euler3DTransform<double>::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
@@ -398,7 +413,7 @@ void vvToolRigidReg::SetTransform(vtkMatrix4x4 *matrix)
     double rad = (checkBoxDegrees->checkState()==Qt::Checked)?180./itk::Math::pi:1.;
     double angleDiff = euler->GetParameters()[i]-rotSBs[i]->value()/rad+2*itk::Math::pi;
     angleDiff = angleDiff - 2*itk::Math::pi*itk::Math::Round<double,double>(angleDiff/(2*itk::Math::pi));
-    if(angleDiff>1.e-4) {
+    if(std::abs(angleDiff)>1.e-4) {
       rotSBs[i]->blockSignals(true);
       rotSBs[i]->setValue( euler->GetParameters()[i]*rad );
       rotSBs[i]->blockSignals(false);