]> Creatis software - bbtk.git/commitdiff
vtkPlanes with different way of calculating the plane of the image
authorJuan Prieto <Juan.Prieto@creatis.insa-lyon.fr>
Tue, 23 Jun 2009 15:58:56 +0000 (15:58 +0000)
committerJuan Prieto <Juan.Prieto@creatis.insa-lyon.fr>
Tue, 23 Jun 2009 15:58:56 +0000 (15:58 +0000)
packages/vtk/src/bbvtkImagePlanes.cxx
packages/vtk/src/bbvtkImagePlanes.h

index e838e03ed8b47f61a8c6e23ef033793a78fff904..fca5f6a3c9f8531ad744d8a583f658c69a871f73 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbvtkImagePlanes.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/06/09 08:41:53 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2009/06/23 15:58:56 $
+  Version:   $Revision: 1.27 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -58,6 +58,8 @@
 
 #include "vtkPlaneWidget.h"
 
+#include <vtkImplicitPlaneWidget.h>
+
 #include "bbstdRelay.h"
 
 #include "vtkObjectFactory.h"
@@ -133,7 +135,7 @@ namespace bbvtk
  };
   //================================================================
 
-  //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.26 $");
+  //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.27 $");
 
   //================================================================
 
@@ -156,6 +158,18 @@ namespace bbvtk
      vect.push_back(0);
      bbSetInputWindowLevel (vect);  
      mVtkCallback = 0;
+
+
+        std::vector<int> vectpoints;
+
+     bbSetOutputPlane3Pts(0);
+        bbSetOutputImage3Pts(0);
+        bbSetInputPointsX(vectpoints);
+        bbSetInputPointsY(vectpoints);
+        bbSetInputPointsZ(vectpoints);
+
+        _imageReslicer = NULL;
+        image=NULL;
    }
    
 
@@ -195,12 +209,23 @@ namespace bbvtk
      prop3->SetColor(0, 0, 1);
      planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
 
+        vtkImagePlaneWidget* planeWidget3Pts = vtkImagePlaneWidget::New();
+        //vtkPlaneWidget* planeWidget3Pts = vtkPlaneWidget::New();
+     planeWidget3Pts->DisplayTextOn();
+     planeWidget3Pts->SetPicker(picker);
+     planeWidget3Pts->SetKeyPressActivationValue('3');
+     vtkProperty* prop3Pts = planeWidget3Pts->GetPlaneProperty();
+     prop3Pts->SetColor(0, 1, 1);
+     planeWidget3Pts->SetLookupTable(planeWidgetX->GetLookupTable());
+
      bbSetOutputPlaneX(planeWidgetX);
      bbSetOutputPlaneY(planeWidgetY);
      bbSetOutputPlaneZ(planeWidgetZ);
+        bbSetOutputPlane3Pts(planeWidget3Pts);  
      bbSetOutputImageX(planeWidgetX->GetResliceOutput());
      bbSetOutputImageY(planeWidgetY->GetResliceOutput());
      bbSetOutputImageZ(planeWidgetZ->GetResliceOutput());
+        //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput());
 
      picker->UnRegister(NULL);
      
@@ -239,60 +264,134 @@ namespace bbvtk
   }
   
 //---------------------------------------------------------------------  
-   void ImagePlanes::Process()
-   {
-     if (bbGetInputIn()!=0)
-       {
-
-        if ( bbGetInputStatus("In") != bbtk::UPTODATE )
-          {
-            // Input image has changed : reinitialize planes
-            image = bbGetInputIn();
-
-            int xMin, xMax, yMin, yMax, zMin, zMax;
-            bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
-            
-            // Initial values : center of the volume (in real world, not in pixels!)
-            double xSpacing, ySpacing, zSpacing;
-            bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
-         
-            bbGetOutputPlaneX()->SetInput(bbGetInputIn());
-            bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();  
-            bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
-
-                  
-//                bbGetOutputPlaneX()->SetOrigin( 58*xSpacing , 80*ySpacing , 82*zSpacing );
-//                bbGetOutputPlaneX()->SetPoint1( 0*xSpacing, 146*ySpacing, 186*zSpacing);
-//                bbGetOutputPlaneX()->SetPoint2( 126*xSpacing, 146*ySpacing, 0*zSpacing);
-                  
-                  
-            bbGetOutputPlaneY()->SetInput(bbGetInputIn());
-            bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
-            bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
-            
-            bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
-            bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
-            bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
-            
-            if (bbGetInputWindowLevel()[0]!=0)
-              {
-                bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
-                                                    bbGetInputWindowLevel()[1]);
-              }
-            else 
-              {
-                double *range = image->GetScalarRange();
-                bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
-                                                    0.5*(range[1]+range[0]));
-              }
-          }     
-        
-        // UPDATE DES SORTIES 
-        bbGetOutputPlaneX()->GetResliceOutput()->Update();
-        bbGetOutputPlaneY()->GetResliceOutput()->Update(); 
-        bbGetOutputPlaneZ()->GetResliceOutput()->Update();              
-       }
-   }
+void ImagePlanes::Process()
+{
+       if (bbGetInputIn()!=0)
+       {
+
+               if ( image != bbGetInputIn()){//bbGetInputStatus("In") != bbtk::UPTODATE ){
+                       // Input image has changed : reinitialize planes
+                       image = bbGetInputIn();
+
+                       int xMin, xMax, yMin, yMax, zMin, zMax;
+                       bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
+
+                       // Initial values : center of the volume (in real world, not in pixels!)
+                       double xSpacing, ySpacing, zSpacing;
+                       bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
+
+                       bbGetOutputPlaneX()->SetInput(bbGetInputIn());
+                       bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();       
+                       bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
+
+
+                       //                 bbGetOutputPlaneX()->SetOrigin( 58*xSpacing , 80*ySpacing , 82*zSpacing );
+                       //                 bbGetOutputPlaneX()->SetPoint1( 0*xSpacing, 146*ySpacing, 186*zSpacing);
+                       //                 bbGetOutputPlaneX()->SetPoint2( 126*xSpacing, 146*ySpacing, 0*zSpacing);
+
+
+                       bbGetOutputPlaneY()->SetInput(bbGetInputIn());
+                       bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
+                       bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
+
+                       bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
+                       bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
+                       bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
+
+                       if (bbGetInputWindowLevel()[0]!=0)
+                       {
+                               bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
+                                                               bbGetInputWindowLevel()[1]);
+                       }
+                       else 
+                       {
+                               double *range = image->GetScalarRange();
+                               bbGetOutputPlaneZ()->SetWindowLevel(range[1] - range[0],
+                                                               0.5*(range[1]+range[0]));
+                       }               
+
+          }
+                       // UPDATE DES SORTIES 
+               bbGetOutputPlaneX()->GetResliceOutput()->Update();
+               bbGetOutputPlaneY()->GetResliceOutput()->Update(); 
+               bbGetOutputPlaneZ()->GetResliceOutput()->Update();               
+
+               std::vector<int> pointsx = bbGetInputPointsX();
+               std::vector<int> pointsy = bbGetInputPointsY();
+               std::vector<int> pointsz = bbGetInputPointsZ();
+
+               std::cout<<pointsx.size()<<pointsy.size()<<pointsz.size()<<std::endl;
+
+               if(pointsx.size()==pointsy.size() && pointsx.size()==pointsz.size()&&pointsx.size()>=3){
+                       vtkImagePlaneWidget* plane3pts = (vtkImagePlaneWidget*)bbGetOutputPlane3Pts();
+                       //vtkPlaneWidget* plane3pts = (vtkPlaneWidget*)bbGetOutputPlane3Pts();
+
+                       plane3pts->SetInput(bbGetInputIn());
+
+                       //xSpacing = ySpacing = zSpacing = 1;
+                       double xSpacing, ySpacing, zSpacing;
+                       bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
+
+                       plane3pts->SetOrigin(pointsx[0]*xSpacing,pointsy[0]*ySpacing,pointsz[0]*zSpacing);                              
+                       plane3pts->SetPoint1(pointsx[1]*xSpacing,pointsy[1]*ySpacing,pointsz[1]*zSpacing);
+                       //plane3pts->SetPoint1((pointsx[1]-pointsx[0])*xSpacing,(pointsy[1]-pointsy[0])*ySpacing,(pointsz[1]-pointsz[0])*zSpacing);
+                       plane3pts->SetPoint2(pointsx[2]*xSpacing,pointsy[2]*ySpacing,pointsz[2]*zSpacing);
+                       //plane3pts->SetPoint2((pointsx[2]-pointsx[0])*xSpacing,(pointsy[2]-pointsy[0])*ySpacing,(pointsz[2]-pointsz[0])*zSpacing);
+                       plane3pts->GetResliceOutput()->Update();
+
+
+
+                       if (_imageReslicer==NULL){
+                               _imageReslicer = vtkImageReslice::New();                                        
+                               _imageReslicer->SetOutputDimensionality(2);
+                               _imageReslicer->SetInterpolationModeToLinear();
+                       }
+
+                       _imageReslicer->SetInput( bbGetInputIn() );
+                       _imageReslicer->SetInformationInput(bbGetInputIn());
+
+                       double origin[3];
+                       origin[0] = pointsx[0];
+                       origin[1] = pointsy[0];
+                       origin[2] = pointsz[0];
+
+                       double point1[3];
+                       point1[0] = pointsx[1];
+                       point1[1] = pointsy[1];
+                       point1[2] = pointsz[1];
+                       double point2[3];
+                       point2[0]= pointsx[2];
+                       point2[1]= pointsy[2];
+                       point2[2]= pointsz[2];                          
+
+                       double* vect1= getNormal(makeVector(origin, point1));
+                       double* vect2= getNormal(makeVector(origin, point2));                           
+                       double* crossp = getCrossProduct(vect1, vect2);
+
+                       /*std::cout<<"origin "<<origin[0]<<" "<<origin[1]<<" "<<origin[2]<<" "<<std::endl;
+                       std::cout<<"point1 "<<point1[0]<<" "<<point1[1]<<" "<<point1[2]<<" "<<std::endl;
+                       std::cout<<"point2 "<<point2[0]<<" "<<point2[1]<<" "<<point2[2]<<" "<<std::endl;
+                       std::cout<<"vect1 "<<vect1[0]<<" "<<vect1[1]<<" "<<vect1[2]<<" "<<std::endl;                            
+                       std::cout<<"vect2 "<<vect2[0]<<" "<<vect2[1]<<" "<<vect2[2]<<" "<<std::endl;
+                       std::cout<<"crossp "<<crossp[0]<<" "<<crossp[1]<<" "<<crossp[2]<<" "<<std::endl;*/
+
+
+                       _imageReslicer->SetResliceAxesDirectionCosines(vect1[0],vect1[1],vect1[2],
+                                                                                                                       vect2[0],vect2[1],vect2[2],
+                                                                                                                       crossp[0],crossp[1],crossp[2]);
+                       //_imageReslicer->SetResliceAxesOrigin(0,0,0);
+                       _imageReslicer->SetResliceAxesOrigin(origin[0],origin[1],origin[2]);
+
+                       _imageReslicer->GetOutput()->Update;
+                       _imageReslicer->GetOutput()->UpdateInformation();
+
+                       bbSetOutputImage3Pts(_imageReslicer->GetOutput());
+
+                       
+               }
+               
+       }
+}
        
        
        //-----------------------------------------------------------------     
@@ -311,8 +410,71 @@ namespace bbvtk
        }
        
        
+
+double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){
+       double* vectCross;
+       vectCross = new double[3];
+       vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
+       vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
+       vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
+
+       return vectCross;
+}
+/**
+**     Returns the magnitud of the given vector
+**/
+double ImagePlanes::getMagnitud(double* vect){
+
+       double mag;
+
+       mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
+
+       std::cout<<"mag "<<mag <<std::endl;
+
+       return mag;
+
+}
+/**
+**     returns the unitary vector of the given vector
+**     u = 1/|vect| . vect
+**/
+double* ImagePlanes::getNormal(double* vect){
+
+       double* vectnorm;
+       double mag = getMagnitud(vect);
+
+       vectnorm = new double[3];
+       
+
+       if(mag!=0){
+               vectnorm[0] = vect[0]/mag;
+               vectnorm[1] = vect[1]/mag;
+               vectnorm[2] = vect[2]/mag;
+       }else{
+               vectnorm[0] = 0;
+               vectnorm[1] = 0;
+               vectnorm[2] = 0;
+       }
+
+       return vectnorm;
+
+
+}
+
+double* ImagePlanes::makeVector(double podouble0[3], double podouble1[3]){
+       double *vect;
+       vect = new double[3];
+
+       vect[0]= podouble0[0]-podouble1[0];
+       vect[1]= podouble0[1]-podouble1[1];
+       vect[2]= podouble0[2]-podouble1[2];
+
+       return vect;
+
+}
        
 }//namespace bbtk
 
 #endif // _USE_VTK_
 
+
index b0d1a0e1c559d92f2ef5e7c8814ae69f19108be2..ddf3590031ea9288cb50472300870e5cf6b0071b 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbvtkImagePlanes.h,v $
   Language:  C++
-  Date:      $Date: 2009/06/09 08:41:53 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2009/06/23 15:58:56 $
+  Version:   $Revision: 1.17 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -54,6 +54,9 @@
 class vtkImageData;
 class vtkImagePlaneWidget;
 
+#include "vtkPlaneWidget.h"
+#include "vtkImageReslice.h"
+
 namespace bbvtk
 {
   typedef std::vector<double> winLevel;
@@ -65,11 +68,14 @@ namespace bbvtk
     //    BBTK_DECLARE_INPUT(Contour,int);
     BBTK_DECLARE_INPUT(In,          vtkImageData *);
     BBTK_DECLARE_INPUT(WindowLevel, winLevel);
+       BBTK_DECLARE_INPUT(PointsX, std::vector<int>);
+       BBTK_DECLARE_INPUT(PointsY, std::vector<int>);
+       BBTK_DECLARE_INPUT(PointsZ, std::vector<int>);
 
     BBTK_DECLARE_OUTPUT(PlaneX,vtkImagePlaneWidget*);
     BBTK_DECLARE_OUTPUT(PlaneY,vtkImagePlaneWidget*);
     BBTK_DECLARE_OUTPUT(PlaneZ,vtkImagePlaneWidget*);
-       BBTK_DECLARE_OUTPUT(Plane3Pts,vtkImagePlaneWidget*);
+       BBTK_DECLARE_OUTPUT(Plane3Pts,vtkInteractorObserver *);
     BBTK_DECLARE_OUTPUT(ImageX,vtkImageData*);
     BBTK_DECLARE_OUTPUT(ImageY,vtkImageData*);        
     BBTK_DECLARE_OUTPUT(ImageZ,vtkImageData*);  
@@ -83,6 +89,14 @@ namespace bbvtk
     class VtkCallbackType;
     VtkCallbackType* mVtkCallback;
     vtkImageData* image;
+       vtkImageReslice* _imageReslicer;
+
+
+       double* getCrossProduct(double* vect0,double* vect1);
+       double getPodoubleProduct(double* vect0,double* vect1);
+       double* getNormal(double* vect);
+       double getMagnitud(double* vect);
+       double* makeVector(double podouble0[3], double podouble1[3]);
   };
    
   //=================================================================
@@ -94,11 +108,14 @@ namespace bbvtk
   BBTK_CATEGORY("3D object creator");
   BBTK_INPUT(ImagePlanes, In                   , "Input Image"         , vtkImageData *        , "");
   BBTK_INPUT(ImagePlanes, WindowLevel  , "Widdow Level"        , winLevel                      ,  "");
+  BBTK_INPUT(ImagePlanes, PointsX, "Points in X" , std::vector<int>,  "");
+  BBTK_INPUT(ImagePlanes, PointsY, "Points in Y" , std::vector<int>,  "");
+  BBTK_INPUT(ImagePlanes, PointsZ, "Points in Z" , std::vector<int>,  "");
 
   BBTK_OUTPUT(ImagePlanes,PlaneX,"The image plane in X direction",vtkImagePlaneWidget*,"");
   BBTK_OUTPUT(ImagePlanes,PlaneY,"The image plane in Y direction",vtkImagePlaneWidget*,"");
   BBTK_OUTPUT(ImagePlanes,PlaneZ,"The image plane in Z direction",vtkImagePlaneWidget*,"");
-  BBTK_OUTPUT(ImagePlanes,Plane3Pts,"The image plane (3 points definition) ",vtkImagePlaneWidget*,"");
+  BBTK_OUTPUT(ImagePlanes,Plane3Pts,"The image plane (3 points definition) ",vtkInteractorObserver *,"");
   BBTK_OUTPUT(ImagePlanes,ImageX,"The image in X direction",      vtkImageData*,       "");
   BBTK_OUTPUT(ImagePlanes,ImageY,"The image in Y direction",      vtkImageData*,       "");
   BBTK_OUTPUT(ImagePlanes,ImageZ,"The image in Z direction",      vtkImageData*,       "");