]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImagePlanes.cxx
Merge branch 'vtk8itk5wx3-mingw64' of ssh://git.creatis.insa-lyon.fr/bbtk into vtk8it...
[bbtk.git] / packages / vtk / src / bbvtkImagePlanes.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbvtkImagePlanes.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:58 $
33   Version:   $Revision: 1.38 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41 #ifdef _USE_VTK_
42 #include "bbvtkImagePlanes.h"
43 #include "bbvtkPackage.h"
44 #include "vtkCellPicker.h"
45 #include "vtkProperty.h"
46 #include "vtkPolyData.h"
47
48
49 #include "vtkMetaImageWriter.h"
50 #include "vtkPNGWriter.h"
51
52 #include "bbstdCast.h"
53 #include <vtkCommand.h>
54
55 #include "vtkImageData.h"
56 //#include "vtkOutlineFilter.h"
57 //#include "vtkPolyDataMapper.h"
58 //#include "vtkActor.h"
59 #include "vtkImagePlaneWidget.h"
60 #include "vtkCellPicker.h"
61 //#include "vtkProperty.h"
62
63 //#include "vtkRenderer.h"
64 //#include "vtkCamera.h"
65
66 #include "vtkPlaneWidget.h"
67
68 #include <vtkImplicitPlaneWidget.h>
69
70 #include "bbstdRelay.h"
71
72 #include "vtkObjectFactory.h"
73 #include "vtkImageFlip.h"
74
75 #include "vtkImageReslice.h"
76 #include "vtkImageChangeInformation.h"
77
78 namespace bbstd
79 {
80
81   //====================================================================
82   BBTK_BLACK_BOX_TEMPLATE2_IMPLEMENTATION(Cast,
83                                           bbtk::AtomicBlackBox);
84   //====================================================================
85   //====================================================================
86 //  BBTK_BLACK_BOX_TEMPLATE_IMPLEMENTATION(Relay,
87 //                                       bbtk::AtomicBlackBox);
88   //====================================================================
89
90 }
91 using namespace bbstd;
92 /*
93 namespace bbtk
94 {
95         typedef vtkImageData::Pointer vtkImageDataPointer;
96   BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(vtkImageDataPointer,
97                                        "vtkImageDataPointer");
98 }
99 */
100 namespace bbvtk
101 {
102
103   //====================================================================
104   // Add the specialized adaptors to the package
105   typedef vtkImagePlaneWidget* I;
106   typedef vtkInteractorObserver* O;
107
108   BBTK_ADD_TEMPLATE2_BLACK_BOX_TO_PACKAGE(vtk,Cast,I,O);
109
110   BBTK_DEFINE_RELAY_BLACK_BOX(vtkImageDataPointer,vtk,vtkImageDataPointerRelay);
111   BBTK_BLACK_BOX_IMPLEMENTATION(vtkImageDataPointerRelay,bbtk::AtomicBlackBox);
112
113   BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,vtkImageDataPointerRelay);
114  // BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(vtk,Relay,vtkImageDataPointer);
115   //Pointer);
116
117 }
118
119 namespace bbvtk
120 {
121
122   //================================================================
123  class ImagePlanes::VtkCallbackType : public vtkCommand
124  {
125  public:
126    static VtkCallbackType *New()
127    {
128      return new VtkCallbackType;
129    }
130    //vtkTypeRevisionMacro(VtkCallbackType,vtkCommand);
131
132    virtual void Execute(vtkObject *caller, unsigned long, void*)
133    {
134        mBlackBox->Process();
135        mBlackBox->bbSignalOutputModification();
136    } 
137    void SetBlackBox(ImagePlanes *BB) { mBlackBox = BB;};    
138    //   void SetVtkPlaneWidget( vtkImagePlaneWidget *planeWidget );
139    VtkCallbackType() {};
140
141  private:
142    //   vtkPlaneWidget *planeWidget;
143    ImagePlanes *mBlackBox;
144  };
145   //================================================================
146
147   //vtkCxxRevisionMacro(ImagePlanes::VtkCallbackType, "$Revision: 1.38 $");
148
149   //================================================================
150
151    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImagePlanes)
152    BBTK_BLACK_BOX_IMPLEMENTATION(ImagePlanes,bbtk::AtomicBlackBox);
153
154    void ImagePlanes::bbUserSetDefaultValues() 
155    { 
156      bbSetOutputPlaneX(NULL);
157      bbSetOutputPlaneY(NULL);
158      bbSetOutputPlaneZ(NULL);
159      bbSetOutputImageX(NULL);
160      bbSetOutputImageY(NULL);
161      bbSetOutputImageZ(NULL);
162      bbSetInputIn(NULL);
163      std::vector<double> vect;
164      vect.push_back(0);
165      vect.push_back(0);
166      bbSetInputWindowLevel (vect);  
167      mVtkCallback = 0;
168
169      std::vector<int> vectpoints;
170
171      bbSetOutputPlane3Pts(0);
172      bbSetOutputImage3Pts(0);
173      bbSetInputPointsX(vectpoints);
174      bbSetInputPointsY(vectpoints);
175      bbSetInputPointsZ(vectpoints);
176
177      _imageReslicer = NULL;
178      image          = NULL;
179      _transform     = NULL;
180      _matrix        = NULL;
181            
182            bbSetInputInterpolation(1);     
183    }
184
185         
186    void ImagePlanes::bbUserInitializeProcessing() 
187    {  
188      /// CREATION DES WIDGETS
189      if (bbGetOutputPlaneX() != 0) return;
190        
191      // The shared picker enables us to use 3 planes at one time
192      // and gets the picking order right
193      vtkCellPicker* picker = vtkCellPicker::New();
194      picker->SetTolerance(0.005);
195   
196      // The 3 image plane widgets 
197      vtkImagePlaneWidget* planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker);
198      vtkImagePlaneWidget* planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker);
199      planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
200
201      vtkImagePlaneWidget* planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker);     
202      planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
203
204      vtkImagePlaneWidget* planeWidget3Pts = GetPlaneWidget('3', 0, 1, 1, picker);        
205      planeWidget3Pts->SetLookupTable(planeWidgetX->GetLookupTable());
206
207            // EED MPR view orientation correction..
208      vtkImageFlip  *flipYFilter = vtkImageFlip::New();
209      flipYFilter->SetFilteredAxis(1); // flip y axis
210
211 //EED 2017-01-01 Migration VTK7
212 #if (VTK_MAJOR_VERSION <= 5) 
213      flipYFilter->SetInput( planeWidgetX->GetResliceOutput() );
214 #endif
215 #if (VTK_MAJOR_VERSION >= 6) 
216      flipYFilter->SetInputData( planeWidgetX->GetResliceOutput() );
217 #endif
218
219      flipYFilter->Update();
220
221            vtkImageChangeInformation *image = vtkImageChangeInformation::New();
222
223 //EED 2017-01-01 Migration VTK7
224 #if (VTK_MAJOR_VERSION <= 5) 
225            image->SetInput(  planeWidgetY->GetResliceOutput()  );
226 #endif
227 #if (VTK_MAJOR_VERSION >= 6) 
228            image->SetInputData(  planeWidgetY->GetResliceOutput()  );
229 #endif
230
231            image->SetOutputSpacing( 1,1,1 );       
232            image->CenterImageOn();
233            image->Update();
234            _imageTransform = vtkTransform::New();
235            vtkImageReslice *slicer =vtkImageReslice::New();
236
237 //EED 2017-01-01 Migration VTK7
238 #if (VTK_MAJOR_VERSION <= 5) 
239            slicer->SetInput( image->GetOutput() );
240 #endif
241 #if (VTK_MAJOR_VERSION >= 6) 
242            slicer->SetInputData( image->GetOutput() );
243 #endif
244
245            slicer->SetInformationInput( image->GetOutput() );
246            slicer->SetResliceTransform( _imageTransform );
247            slicer->SetOutputOrigin(0 , 0 , 0 );
248            slicer->SetInterpolationModeToNearestNeighbor();
249            slicer->Update();       
250            vtkImageChangeInformation *imageResult = vtkImageChangeInformation::New();
251
252 //EED 2017-01-01 Migration VTK7
253 #if (VTK_MAJOR_VERSION <= 5) 
254            imageResult->SetInput( slicer->GetOutput() );
255 #endif
256 #if (VTK_MAJOR_VERSION >= 6) 
257            imageResult->SetInputData( slicer->GetOutput() );
258 #endif
259
260            double spc[3];
261             planeWidgetY->GetResliceOutput()->GetSpacing(spc);
262            imageResult->SetOutputSpacing( spc[1], spc[0], spc[2] ); 
263            imageResult->SetOutputOrigin( 0,0,0 ); 
264                    
265            
266      bbSetOutputPlaneX(planeWidgetX);
267      bbSetOutputPlaneY(planeWidgetY);
268      bbSetOutputPlaneZ(planeWidgetZ);
269      bbSetOutputPlane3Pts(planeWidget3Pts);      
270      bbSetOutputImageX( flipYFilter->GetOutput() );             // EED MPR view orientation correction..
271      bbSetOutputImageY( imageResult->GetOutput() );                     // EED MPR view orientation correction..
272      bbSetOutputImageZ(planeWidgetZ->GetResliceOutput());
273      bbSetInputInteractor(0);
274      //bbSetOutputImage3Pts(planeWidget3Pts->GetResliceOutput());
275
276          if(picker != 0)
277      {
278                 picker->UnRegister(NULL);
279          }
280
281      mVtkCallback = VtkCallbackType::New();
282      mVtkCallback->SetBlackBox(this);
283      planeWidgetX->AddObserver(vtkCommand::InteractionEvent,mVtkCallback);
284      planeWidgetY->AddObserver(vtkCommand::InteractionEvent,mVtkCallback);
285      planeWidgetZ->AddObserver(vtkCommand::InteractionEvent,mVtkCallback);       
286
287    }
288
289 //---------------------------------------------------------------------
290   void ImagePlanes::bbUserFinalizeProcessing()
291   {
292
293     if (bbGetOutputPlaneX()) 
294       {
295
296         /*
297           bbGetOutputPlaneX()->RemoveObserver(mVtkCallback);
298           bbGetOutputPlaneY()->RemoveObserver(mVtkCallback);
299           bbGetOutputPlaneZ()->RemoveObserver(mVtkCallback);
300
301         bbGetOutputPlaneX()->Delete();
302         bbGetOutputPlaneY()->Delete();
303         bbGetOutputPlaneZ()->Delete();
304         mVtkCallback->Delete();
305         */
306         //bbGetOutputPlaneX()->SetInput(NULL);
307         //bbGetOutputPlaneY()->SetInput(NULL);
308         //bbGetOutputPlaneZ()->SetInput(NULL);
309
310       }
311   }
312   
313 //---------------------------------------------------------------------  
314   void ImagePlanes::Process()
315   {
316           
317         if (bbGetInputIn()!=0)
318         {
319                 int dim[3];
320                 int ext[6];
321 //EED 2017-01-01 Migration VTK7
322 #if (VTK_MAJOR_VERSION <= 5) 
323                 bbGetOutputPlaneX()->GetResliceOutput()->GetWholeExtent(ext);
324 #endif
325 #if (VTK_MAJOR_VERSION >= 6) 
326                 bbGetOutputPlaneX()->GetResliceOutput()->GetExtent(ext);
327 #endif
328
329                 dim[0] = ext[1]-ext[0]+1;
330                 dim[1] = ext[3]-ext[2]+1;
331                 dim[2] = ext[5]-ext[4]+1;
332                 _imageTransform->Identity();
333                 _imageTransform->PostMultiply();
334                 _imageTransform->Translate( (int)(-(dim[0]/2)) , (int)(-(dim[1]/2)) ,0);
335                 _imageTransform->RotateZ(90);
336                 
337                 
338                 if ( image != bbGetInputIn()){//bbGetInputStatus("In") != bbtk::UPTODATE ){
339                         // Input image has changed : reinitialize planes
340                         image = bbGetInputIn();                 
341
342                         // Initial values : center of the volume (in real world, not in pixels!)
343                         int xMin, xMax, yMin, yMax, zMin, zMax;
344                         bbGetInputIn()->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
345                         double xSpacing, ySpacing, zSpacing;
346                         bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
347
348 //EED 2017-01-01 Migration VTK7
349 #if (VTK_MAJOR_VERSION <= 5) 
350                         bbGetOutputPlaneX()->SetInput(bbGetInputIn());
351 #endif
352 #if (VTK_MAJOR_VERSION >= 6) 
353                         bbGetOutputPlaneX()->SetInputData(bbGetInputIn());
354 #endif
355
356                         bbGetOutputPlaneX()->SetPlaneOrientationToXAxes();       
357                         bbGetOutputPlaneX()->SetSlicePosition((xMax+xMin)/2.*xSpacing);
358
359                         //                 bbGetOutputPlaneX()->SetOrigin( 58*xSpacing , 80*ySpacing , 82*zSpacing );
360                         //                 bbGetOutputPlaneX()->SetPoint1( 0*xSpacing, 146*ySpacing, 186*zSpacing);
361                         //                 bbGetOutputPlaneX()->SetPoint2( 126*xSpacing, 146*ySpacing, 0*zSpacing);
362
363 //EED 2017-01-01 Migration VTK7
364 #if (VTK_MAJOR_VERSION <= 5) 
365                         bbGetOutputPlaneY()->SetInput(bbGetInputIn());
366 #endif
367 #if (VTK_MAJOR_VERSION >= 6) 
368                         bbGetOutputPlaneY()->SetInputData(bbGetInputIn());
369 #endif
370
371                         bbGetOutputPlaneY()->SetPlaneOrientationToYAxes();
372                         bbGetOutputPlaneY()->SetSlicePosition((yMax+yMin)/2.*ySpacing);
373
374 //EED 2017-01-01 Migration VTK7
375 #if (VTK_MAJOR_VERSION <= 5) 
376                         bbGetOutputPlaneZ()->SetInput(bbGetInputIn());
377 #endif
378 #if (VTK_MAJOR_VERSION >= 6) 
379                         bbGetOutputPlaneZ()->SetInputData(bbGetInputIn());
380 #endif
381
382                         bbGetOutputPlaneZ()->SetPlaneOrientationToZAxes();
383                         bbGetOutputPlaneZ()->SetSlicePosition((zMax+zMin)/2.*zSpacing);
384
385                         if (bbGetInputWindowLevel()[0]!=0)
386                         {
387                                 bbGetOutputPlaneZ()->SetWindowLevel(bbGetInputWindowLevel()[0],
388                                                                 bbGetInputWindowLevel()[1]);
389                         } else {
390                                 double *range = image->GetScalarRange();
391                                 bbGetOutputPlaneZ()->SetWindowLevel(range[1]-range[0],
392                                                                0.5*(range[1]+range[0]));
393                         } // windowlevel
394                         updateInteractor();
395                         
396                         dim[0] = xMax-xMin+1;
397                         dim[1] = yMax-yMin+1;
398                         dim[2] = zMax-zMin+1;
399                         _imageTransform->Identity();
400                         _imageTransform->PostMultiply();
401                         _imageTransform->Translate( (int)(-(dim[0]/2)*(1/xSpacing)) , (int)(-(dim[2]/2)*(1/zSpacing)) ,0);
402                         _imageTransform->RotateZ(90);
403                         
404            } // image
405                 
406                         // UPDATE DES SORTIES 
407                 bbGetOutputPlaneX()->SetResliceInterpolate( bbGetInputInterpolation() );
408                 bbGetOutputPlaneY()->SetResliceInterpolate( bbGetInputInterpolation() );
409                 bbGetOutputPlaneZ()->SetResliceInterpolate( bbGetInputInterpolation() );
410
411                 
412 //EED 2017-01-01 Migration VTK7
413 #if (VTK_MAJOR_VERSION <= 5) 
414                 bbGetOutputPlaneX()->GetResliceOutput()->Update();
415                 bbGetOutputPlaneY()->GetResliceOutput()->Update(); 
416                 bbGetOutputPlaneZ()->GetResliceOutput()->Update();               
417 #endif
418 #if (VTK_MAJOR_VERSION >= 6) 
419                 // ...
420 #endif
421                 
422                 std::vector<int> pointsx = bbGetInputPointsX();
423                 std::vector<int> pointsy = bbGetInputPointsY();
424                 std::vector<int> pointsz = bbGetInputPointsZ();
425
426                 //std::cout<<pointsx.size()<<pointsy.size()<<pointsz.size()<<std::endl;
427
428                 if (pointsx.size()==pointsy.size() && pointsx.size()==pointsz.size()&&pointsx.size()>=3)
429                 {
430
431                         //Get the corresponding three points out of the vectors
432                         double origin[3];
433                         origin[0]                       = pointsx[0];
434                         origin[1]                       = pointsy[0];
435                         origin[2]                       = pointsz[0];
436
437                         double point1[3];
438                         point1[0]                       = pointsx[1];
439                         point1[1]                       = pointsy[1];
440                         point1[2]                       = pointsz[1];
441                         double point2[3];
442                         point2[0]                       = pointsx[2];
443                         point2[1]                       = pointsy[2];
444                         point2[2]                       = pointsz[2];   
445
446                         //With the three points we create the corresponding X, Y and Z vectors all orthogonal to each other
447                         double* vect1           = getNormal(makeVector(origin, point1));
448                         double* vect2           = getNormal(makeVector(origin, point2));                                
449                         double* crossp          = getCrossProduct(vect1, vect2);
450
451                         double *newx            = getCrossProduct(vect2, crossp);
452
453                         int ext[6],factor       =       0;
454                         bbGetInputIn()->GetExtent(ext);
455
456                         factor = ext[0]<ext[3]? ext[3] : ext[0];
457                         factor = factor<ext[5]? ext[5] : factor;
458
459         //for the plane widgets
460                         vtkImagePlaneWidget* plane3pts = (vtkImagePlaneWidget*)bbGetOutputPlane3Pts();
461
462 //EED 2017-01-01 Migration VTK7
463 #if (VTK_MAJOR_VERSION <= 5) 
464                         plane3pts->SetInput(bbGetInputIn());                    
465 #endif
466 #if (VTK_MAJOR_VERSION >= 6) 
467                         plane3pts->SetInputData(bbGetInputIn());                        
468 #endif
469
470                         double xSpacing, ySpacing, zSpacing;
471                         bbGetInputIn()->GetSpacing(xSpacing, ySpacing, zSpacing);
472                         plane3pts->SetOrigin(pointsx[0]*xSpacing,pointsy[0]*ySpacing,pointsz[0]*zSpacing);      
473                         plane3pts->SetPoint1((origin[0]+newx[0]*factor)*xSpacing,
474                                                                         (origin[1]+newx[1]*factor)*ySpacing,
475                                                                         (origin[2]+newx[2]*factor)*zSpacing);
476                         plane3pts->SetPoint2((origin[0]+vect2[0]*factor)*xSpacing,
477                                                                         (origin[1]+vect2[1]*factor)*ySpacing,
478                                                                         (origin[2]+vect2[2]*factor)*zSpacing);
479
480 //EED 2017-01-01 Migration VTK7
481 #if (VTK_MAJOR_VERSION <= 5) 
482                         plane3pts->GetResliceOutput()->Update();
483 #endif
484 #if (VTK_MAJOR_VERSION >= 6) 
485                         // ..
486 #endif
487
488 //To get the slice of image out of the selected volume
489                         if (_imageReslicer==NULL)
490                         {
491                                 _imageReslicer = vtkImageReslice::New();                                        
492                                 _imageReslicer->SetOutputDimensionality(2);
493                                 _transform = vtkTransform::New();
494                                 _matrix = vtkMatrix4x4::New();  
495                         } // if
496                         _imageReslicer->SetInterpolationMode( bbGetInputInterpolation() );
497
498 //EED 2017-01-01 Migration VTK7
499 #if (VTK_MAJOR_VERSION <= 5) 
500                         _imageReslicer->SetInput( bbGetInputIn() );
501 #endif
502 #if (VTK_MAJOR_VERSION >= 6) 
503                         _imageReslicer->SetInputData( bbGetInputIn() );
504 #endif
505
506
507                         _imageReslicer->SetInformationInput(bbGetInputIn());    
508                         //fill out the information with the created vectors and using the spacing of the image
509                         _imageReslicer->SetResliceAxesDirectionCosines(newx[0]*xSpacing,newx[1]*xSpacing,newx[2]*xSpacing,
510                                                                         vect2[0]*ySpacing,vect2[1]*ySpacing,vect2[2]*ySpacing,
511                                                                         crossp[0]*zSpacing,crossp[1]*zSpacing,crossp[2]*zSpacing);                      
512                         _imageReslicer->SetResliceAxesOrigin(origin[0]*xSpacing,origin[1]*ySpacing,origin[2]*zSpacing);
513
514
515 //EED 2017-01-01 Migration VTK7
516 #if (VTK_MAJOR_VERSION <= 5) 
517                         _imageReslicer->GetOutput()->Update();
518                         _imageReslicer->GetOutput()->UpdateInformation();
519 #endif
520 #if (VTK_MAJOR_VERSION >= 6) 
521                         _imageReslicer->Update();
522 #endif
523
524
525
526                         bbSetOutputImage3Pts(_imageReslicer->GetOutput());
527
528                         _matrix->Identity();    
529
530                         _matrix->SetElement(0,0,newx[0]*xSpacing);
531                         _matrix->SetElement(1,0,newx[1]*xSpacing);
532                         _matrix->SetElement(2,0,newx[2]*xSpacing);
533                         _matrix->SetElement(0,1,vect2[0]*ySpacing);
534                         _matrix->SetElement(1,1,vect2[1]*ySpacing);
535                         _matrix->SetElement(2,1,vect2[2]*ySpacing);
536                         _matrix->SetElement(0,2,crossp[0]*zSpacing);
537                         _matrix->SetElement(1,2,crossp[1]*zSpacing);
538                         _matrix->SetElement(2,2,crossp[2]*zSpacing);
539                         _matrix->SetElement(0,3,origin[0]*xSpacing);
540                         _matrix->SetElement(1,3,origin[1]*ySpacing);
541                         _matrix->SetElement(2,3,origin[2]*zSpacing);
542
543                         _transform->SetMatrix(_matrix);
544
545                         //set the transformation out to be used by other bbBoxes
546                         bbSetOutputTransform3Pts((vtkLinearTransform*)_transform);                      
547                 }       // pointsx pointsy  pointsz
548         } // bbGetInputIn
549   }
550         
551         void ImagePlanes::updateInteractor()
552         {
553                 vtkRenderWindowInteractor* interactor = bbGetInputInteractor(); 
554                 if(interactor)
555                 {
556                         bbGetOutputPlaneX()->SetInteractor(interactor);
557                         bbGetOutputPlaneX()->EnabledOn();
558                         bbGetOutputPlaneY()->SetInteractor(interactor);
559                         bbGetOutputPlaneY()->EnabledOn();
560                         bbGetOutputPlaneZ()->SetInteractor(interactor);
561                         bbGetOutputPlaneZ()->EnabledOn();
562                         bbGetOutputPlane3Pts()->SetInteractor(interactor);
563                         bbGetOutputPlane3Pts()->EnabledOn();
564                 } // if
565         }
566
567         //-----------------------------------------------------------------     
568         void vtkImageDataPointerRelay::bbUserSetDefaultValues()
569         {
570                 
571         }
572         
573         //-----------------------------------------------------------------     
574   void vtkImageDataPointerRelay::bbUserInitializeProcessing()
575         {
576         }
577         
578         //-----------------------------------------------------------------     
579   void vtkImageDataPointerRelay::bbUserFinalizeProcessing()
580         {
581         }
582         
583   vtkImagePlaneWidget* ImagePlanes::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
584   {
585                 vtkProperty* prop1 = 0;         
586                 vtkImagePlaneWidget* planeWidget = 0;
587
588                 planeWidget = vtkImagePlaneWidget::New();
589                 planeWidget->DisplayTextOn();
590                 planeWidget->SetPicker(picker);
591                 planeWidget->SetKeyPressActivationValue(activationkey);
592                 prop1 = planeWidget->GetPlaneProperty();
593                 prop1->SetColor(r, g, b);
594
595                 return planeWidget;
596   }
597
598   double* ImagePlanes::getCrossProduct(double* vect0,double* vect1){
599         double* vectCross;
600         vectCross = new double[3];
601         vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
602         vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
603         vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
604
605         return vectCross;
606   }
607 /**
608 **      Returns the magnitud of the given vector
609 **/
610   double ImagePlanes::getMagnitud(double* vect){
611
612         double mag;
613         mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
614         //std::cout<<"mag "<<mag <<std::endl;
615         return mag;
616   }
617 /**
618 **      returns the unitary vector of the given vector
619 **      u = 1/|vect| . vect
620 **/
621   double* ImagePlanes::getNormal(double* vect){
622
623         double* vectnorm;
624         double mag = getMagnitud(vect);
625
626         vectnorm = new double[3];
627
628         if(mag!=0){
629                 vectnorm[0] = vect[0]/mag;
630                 vectnorm[1] = vect[1]/mag;
631                 vectnorm[2] = vect[2]/mag;
632         }else{
633                 vectnorm[0] = 0;
634                 vectnorm[1] = 0;
635                 vectnorm[2] = 0;
636         }
637
638         return vectnorm;
639   }
640
641   double* ImagePlanes::makeVector(double podouble0[3], double podouble1[3]){
642         double *vect;
643         vect = new double[3];
644
645         vect[0]= podouble1[0]-podouble0[0];
646         vect[1]= podouble1[1]-podouble0[1];
647         vect[2]= podouble1[2]-podouble0[2];
648
649         return vect;
650   }
651         
652 }//namespace bbtk
653
654 #endif // _USE_VTK_