]> Creatis software - clitk.git/commitdiff
Rigid Registration & Overlay Debug try
authortbaudier <thomas.baudier@etu.unistra.fr>
Thu, 19 Nov 2015 14:29:58 +0000 (15:29 +0100)
committertbaudier <thomas.baudier@etu.unistra.fr>
Thu, 19 Nov 2015 14:29:58 +0000 (15:29 +0100)
vv/vvSlicer.cxx
vv/vvToolRigidReg.cxx

index 317dc0670f411f54cea1c6f9cb57139aa1c045a8..0a54a6a7db2c55fdf1e8236d76920c7b93ae726f 100644 (file)
@@ -1072,7 +1072,7 @@ int vvSlicer::GetOrientation()
 
 //----------------------------------------------------------------------------
 void vvSlicer::UpdateDisplayExtent()
-{ //out << __func__ << endl;
+{ cout << __func__ << endl;
   vtkImageData *input = this->GetInput();
   
   if (!input || !this->ImageActor) {
@@ -1101,11 +1101,11 @@ void vvSlicer::UpdateDisplayExtent()
 #else
   vtkSmartPointer<vtkOpenGLImageSliceMapper> mapperOpenGL= vtkSmartPointer<vtkOpenGLImageSliceMapper>::New();
   try {
-        mapperOpenGL = dynamic_cast<vtkOpenGLImageSliceMapper*>(GetImageActor()->GetMapper());
+    mapperOpenGL = dynamic_cast<vtkOpenGLImageSliceMapper*>(GetImageActor()->GetMapper());
   } catch (const std::bad_cast& e) {
-               std::cerr << e.what() << std::endl;
-               std::cerr << "Conversion error" << std::endl;
-               return;
+    std::cerr << e.what() << std::endl;
+       std::cerr << "Conversion error" << std::endl;
+       return;
   }
   if (mFirstSetSliceOrientation) {
     copyExtent(ext, mRegisterExtent);
@@ -1118,7 +1118,7 @@ void vvSlicer::UpdateDisplayExtent()
     w_croppingRegion[ this->SliceOrientation*2+1 ] = this->Slice;
     mapperOpenGL->SetCroppingRegion(w_croppingRegion);
   }
-#endif 
+#endif
   
 #if VTK_MAJOR_VERSION >= 6 || (VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 10)
   // Fix for bug #1882
@@ -1127,6 +1127,7 @@ void vvSlicer::UpdateDisplayExtent()
 
   // Overlay image actor
   if (mOverlay && mOverlayVisibility) {
+    //mOverlayMapper->GetOutput()->Print(cout);
     AdjustResliceToSliceOrientation(mOverlayReslice);
     int overExtent[6];
     this->ConvertImageToImageDisplayExtent(input, w_ext, mOverlayReslice->GetOutput(), overExtent);
@@ -1592,7 +1593,7 @@ double vvSlicer::GetScalarComponentAsDouble(vtkImageData *image, double X, doubl
 
 //----------------------------------------------------------------------------
 void vvSlicer::Render()
-{ //out << __func__ << endl;
+{ cout << __func__ << endl;
   if (this->mFusion && mFusionActor->GetVisibility() && showFusionLegend) {
     legend->SetLookupTable(this->GetFusionMapper()->GetLookupTable());
     legend->UseOpacityOn();
@@ -1605,6 +1606,7 @@ void vvSlicer::Render()
   } else legend->SetVisibility(0);
 
   if (ca->GetVisibility()) {
+
     std::stringstream worldPos(" ");
     double pt[3];
     mConcatenatedTransform->TransformPoint(mCurrent, pt);
@@ -1644,7 +1646,7 @@ void vvSlicer::Render()
         Y <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[3]+0.5 &&
         Z >= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[4]-0.5 &&
         Z <= mImage->GetVTKImages()[mCurrentTSlice]->GetInformation()->Get(vtkDataObject::DATA_EXTENT())[5]+0.5) {
-      
+
       int ix, iy, iz;
       double value = this->GetScalarComponentAsDouble(mImage->GetVTKImages()[mCurrentTSlice], X, Y, Z, ix, iy, iz);
 
@@ -1706,6 +1708,7 @@ void vvSlicer::Render()
                std::cerr << "Conversion error" << std::endl;
                return;
        }
+
     if (xCursor >= mapperOpenGL->GetCroppingRegion()[0]-0.5 &&
         xCursor < mapperOpenGL->GetCroppingRegion()[1]+0.5 &&
         yCursor >= mapperOpenGL->GetCroppingRegion()[2]-0.5 &&
@@ -1736,6 +1739,7 @@ void vvSlicer::Render()
 #else
     mOverlayMapper->SetUpdateExtent(mOverlayActor->GetDisplayExtent());
 #endif
+       mOverlayActor->Print(cout);
     mOverlayMapper->Update();
   }
   if (mFusion && mFusionActor->GetVisibility()) {
index 5cc862d5aaf2b34fefac0a35b4a24cef2839f148..c02d7e6017fefca88875c19cde908fcc17e47389 100644 (file)
@@ -19,6 +19,7 @@
 // vv
 #include "vvToolRigidReg.h"
 #include "vvSlicer.h"
+#include <vvBlendImageActor.h>
 
 // vtk
 #include <vtkImageData.h>
@@ -460,6 +461,8 @@ void vvToolRigidReg::ExtentMax(const double pointExtent[8][4], double maxExtent[
 void vvToolRigidReg::Render()
 { //out << __func__ << endl;
 #if VTK_MAJOR_VERSION > 5
+double translationValues[4], translationValuesUpdate[4];
+mCurrentSlicerManager->GetImage()->GetTransform()[0]->Print(cout);
 vtkMatrix4x4* matrix = mCurrentSlicerManager->GetImage()->GetTransform()[0]->GetMatrix();
 vtkMatrix4x4* matrixTranspose = matrix->NewInstance();
 for (int i=0; i<3; ++i) {
@@ -468,15 +471,21 @@ for (int i=0; i<3; ++i) {
         matrixTranspose->SetElement(i,j,matrix->GetElement(j,i));
     }
 }
-for (int i=0; i<4; ++i) {
-   matrixTranspose->SetElement(3,i,matrix->GetElement(3,i));
+for (int j=0; j<3; ++j)
+{
+    translationValues[j] = matrix->GetElement(j,3);
+}
+translationValues[3] = 0.0;
+matrix->MultiplyPoint(translationValues, translationValuesUpdate);
+for (int i=0; i<3; ++i) {
+   matrixTranspose->SetElement(i,3,translationValuesUpdate[i]);
 }
 for (int i=0; i<4; ++i) {
-   matrixTranspose->SetElement(i,3,matrix->GetElement(i,3));
+   matrixTranspose->SetElement(3,i,matrix->GetElement(3,i));
 }
+
 #endif
-  for (int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++)
-    {
+for (int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
 #if VTK_MAJOR_VERSION > 5 
     double pointExtent[8][4], pointExtentUpdate[8][4];
     std::vector<int> w_ext;
@@ -517,21 +526,23 @@ for (int i=0; i<4; ++i) {
        for (int k=0; k<8; ++k) {
            for (int j=0; j<3; ++j)
            {
-               pointExtent[k][j] = mCurrentSlicerManager->GetImage()->GetOrigin()[j] + mCurrentSlicerManager->GetImage()->GetSpacing()[j] * pointExtent[k][j];
+               pointExtent[k][j] = mCurrentSlicerManager->GetImage()->GetSpacing()[j] * pointExtent[k][j];
            }
            matrixTranspose->MultiplyPoint(pointExtent[k], pointExtentUpdate[k]);
                for (int j=0; j<3; ++j)
            {
-               pointExtentUpdate[k][j] = (pointExtentUpdate[k][j] - mCurrentSlicerManager->GetImage()->GetOrigin()[j])/mCurrentSlicerManager->GetImage()->GetSpacing()[j];
+               pointExtentUpdate[k][j] = (pointExtentUpdate[k][j])/mCurrentSlicerManager->GetImage()->GetSpacing()[j];
+               cout << pointExtentUpdate[k][j] << " ";
            }
+           cout << endl;
+    }
+    double extUpdateTemp[2][3];
+    int extUpdate[6];
+    ExtentMax(pointExtentUpdate, extUpdateTemp);
+    for (int j=0; j<3; ++j) {
+        extUpdate[2*j] = 0;
+        extUpdate[2*j+1] = itk::Math::Round<double>(extUpdateTemp[1][j] - extUpdateTemp[0][j]);
     }
-double extUpdateTemp[2][3];
-int extUpdate[6];
-ExtentMax(pointExtentUpdate, extUpdateTemp);
-for (int j=0; j<3; ++j) {
-    extUpdate[2*j] = 0;
-    extUpdate[2*j+1] = itk::Math::Round<double>(extUpdateTemp[1][j] - extUpdateTemp[0][j]);
-}
     mCurrentSlicerManager->GetSlicer(i)->SetRegisterExtent(extUpdate);
     extUpdate[2*mCurrentSlicerManager->GetSlicer(i)->GetOrientation()] = mCurrentSlicerManager->GetSlicer(i)->GetSlice();
     extUpdate[2*mCurrentSlicerManager->GetSlicer(i)->GetOrientation()+1] = mCurrentSlicerManager->GetSlicer(i)->GetSlice();
@@ -544,11 +555,39 @@ for (int j=0; j<3; ++j) {
                std::cerr << "Conversion error" << std::endl;
                return;
        }
+       cout << extUpdate[0] << " " << extUpdate[1] << " " << extUpdate[2] << " " << extUpdate[3] << " " << extUpdate[4] << " " << extUpdate[5] << endl;
        mapperOpenGL->SetCroppingRegion(extUpdate);
+       
+       if (mCurrentSlicerManager->GetSlicer(i)->GetOverlay() && mCurrentSlicerManager->GetSlicer(i)->GetOverlayActor()->GetVisibility()) {
+           int extOverlayUpdate[6];
+           for (int j=0; j<3; ++j) {
+               if (0 < extUpdateTemp[0][j]) {
+                   extOverlayUpdate[2*j] = itk::Math::Round<double>(extUpdateTemp[0][j]);
+               } else {
+                   extOverlayUpdate[2*j] = 0;
+               }
+               if (extUpdateTemp[1][j] < w_ext[j]-1) {
+                   extOverlayUpdate[2*j+1] = itk::Math::Round<double>(extUpdateTemp[1][j]);
+               } else {
+                   extOverlayUpdate[2*j+1] = w_ext[j]-1;
+               }
+           }
+           extOverlayUpdate[2*mCurrentSlicerManager->GetSlicer(i)->GetOrientation()] += mCurrentSlicerManager->GetSlicer(i)->GetSlice();
+        extOverlayUpdate[2*mCurrentSlicerManager->GetSlicer(i)->GetOrientation()+1] = extOverlayUpdate[2*mCurrentSlicerManager->GetSlicer(i)->GetOrientation()];
+           vtkSmartPointer<vtkOpenGLImageSliceMapper> mapperOpenGL= vtkSmartPointer<vtkOpenGLImageSliceMapper>::New();
+           try {
+            mapperOpenGL = dynamic_cast<vtkOpenGLImageSliceMapper*>(mCurrentSlicerManager->GetSlicer(i)->GetOverlayActor()->GetMapper());
+        } catch (const std::bad_cast& e) {
+                   std::cerr << e.what() << std::endl;
+                   std::cerr << "Conversion error" << std::endl;
+                   return;
+           }
+           mapperOpenGL->SetCroppingRegion(extOverlayUpdate);
+       }
 #endif
     mCurrentSlicerManager->GetSlicer(i)->ForceUpdateDisplayExtent();
     mCurrentSlicerManager->GetSlicer(i)->Render();
-    }
+}
 }
 //------------------------------------------------------------------------------