]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkMPR3DView.cxx
index 52fe1b7aebfbea5dbab9ac95d5602370654df7bc..67ecb3fe665ddf113d04ce5dda2cd3023a08ae94 100644 (file)
 #include "vtkCutter.h"
 #include "vtkTransform.h"
 #include "vtkmyPWCallback_3DPointWidget.h"
+#include "vtkProperty.h"
+#include "vtkCellPicker.h"
 
 wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
 {
        _wxvtk3Dbaseview                        =       wxvtk3Dbaseview;
        _vtkmpr3Ddataviewer                     =       NULL;
        _wxvtkmpr3DviewCntrlPanel       =       NULL;   
-       //_myCallback=NULL;
-       _pointWidget=NULL;
-       _planeWidget=NULL;
-       _vtkplane=NULL;
-       _probe=NULL;
-       _contourMapper=NULL;
+       //_myCallback                           =       NULL;
+       _pointWidget                            =       NULL;
+       _planeWidget                            =       NULL;
+       _vtkplane                                       =       NULL;
+       _probe                                          =       NULL;
+       _contourMapper                          =       NULL;
+       
+       _planeWidgetX = 0;
+       _planeWidgetY = 0;
+       _planeWidgetZ = 0;
+       //EED Fev 3 2010
+       //Free Planes 
 }
-void wxVtkMPR3DView::RemoveActor(vtkActor* actor){     
 
-       _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);    
 
+//-------------------------------------------------------------------
+wxVtkMPR3DView::~wxVtkMPR3DView()
+{
+       VisiblePointWidget( false );
+       VisiblePlaneWidget( false );
+       
+       if(_pointWidget!=NULL){
+               _pointWidget->Delete();
+       }
+       if(_planeWidget!=NULL){
+               _planeWidget->Delete();
+       }
+       
+       if(_vtkplane!=NULL){
+               _vtkplane->Delete();            
+               _probe->Delete();
+               _contourMapper->Delete();                       
+               _contourPlaneActor->Delete();           
+       }
+       
+}
 
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::RemoveActor(vtkActor* actor)
+{      
+       _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);    
 }
-void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc){
-       if(ext == NULL){
 
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc)
+{
+       if(ext == NULL){
                _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();        
                _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
        }else{
@@ -59,12 +92,18 @@ void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc){
                _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
        }
 }
-void wxVtkMPR3DView::Configure(){
 
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::Configure(){
+       
+       
+       vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
 
        _wxvtk3Dbaseview->Configure();
        _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
-       _wxvtk3Dbaseview->GetRenderer()->Clear();               
+       
+//EED 27 Mai 2009 
+//     _wxvtk3Dbaseview->GetRenderer()->Clear();    
        
        // Actors are added to the renderer. 
        vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
@@ -101,86 +140,198 @@ void wxVtkMPR3DView::Configure(){
        //}
        vtkmyPWCallback_3DPointWidget *_myCallback = vtkmyPWCallback_3DPointWidget::New();
        _myCallback->SetWxVtkMPR3DView(this);
-       if(_pointWidget!=NULL){
-               _pointWidget->Delete();
-       }
-       _pointWidget = vtkPointWidget::New();
-       _myCallback->SetVtkPointWidget(_pointWidget);
-       _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() ); 
-       _pointWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
        
-       _pointWidget->AllOff();
        
-       _pointWidget->PlaceWidget();
+       if(imageData){
+               if(_pointWidget==NULL){
+                       _pointWidget = vtkPointWidget::New();
+               }
+               _pointWidget->SetInput( imageData );
+               _myCallback->SetVtkPointWidget(_pointWidget);
+               _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() ); 
+               _pointWidget->AllOff();
+               _pointWidget->PlaceWidget();
+               
+               _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
+               
+               
+               if(_planeWidget==NULL)
+               {
+                       _planeWidget = vtkPlaneWidget::New();
+               }
+               _planeWidget->SetInput( imageData );
+               
+               _myCallback->SetVtkPlaneWidget(_planeWidget);
+
+               _planeWidget->NormalToXAxisOn();
+               _planeWidget->SetResolution(50);
+               _planeWidget->SetRepresentationToOutline();
+               
+               int dim[3];
+       
+               imageData->GetDimensions(dim);
+               int px=(dim[0]/2);
+               int py=(dim[1]/2);
+               int pz=(dim[2]/2);
+               int dd=20;
+               _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
+               
+               if(_vtkplane==NULL){
+                       _vtkplane = vtkPolyData::New();
+                       
+                       _probe = vtkProbeFilter::New();
+                       _probe->SetInput(_vtkplane);
+
+                       _contourMapper = vtkPolyDataMapper::New();
+                       
+                       _contourMapper->SetInput( _probe->GetPolyDataOutput() );
+
+                       _contourPlaneActor = vtkActor::New();
+                       _contourPlaneActor->SetMapper(_contourMapper);
+
+                       _contourPlaneActor->VisibilityOff();
+
+                       _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
+                       _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
+
+                       _planeWidget->Off();
+                       _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );        
+
+               }
+
+               _planeWidget->GetPolyData(_vtkplane);
+               _probe->SetSource( imageData );
+               _contourMapper->SetScalarRange( imageData->GetScalarRange() );
+               
+               
+               ConfigureFreePlanes();
+       }
+       
 //     _pointWidget->SetPosition( x,y,z ); 
        
 //EED01 29Mars2009
 // MACOS probleme vtk-window out of wx-window  
 //     _pointWidget->On();
        
-       _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
+       
 
 
 // PlaneWidget
-       if(_planeWidget!=NULL){
-               _planeWidget->Delete();
-       }
-       _planeWidget = vtkPlaneWidget::New();
-       _myCallback->SetVtkPlaneWidget(_planeWidget);
-       _planeWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
-       _planeWidget->NormalToXAxisOn();
-       _planeWidget->SetResolution(50);
-       _planeWidget->SetRepresentationToOutline();
-       int dim[3];
-       GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetDimensions(dim);
-       int px=(dim[0]/2);
-       int py=(dim[1]/2);
-       int pz=(dim[2]/2);
-       int dd=20;
-       _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
-
-
-       if(_vtkplane==NULL){
-               _vtkplane = vtkPolyData::New();
-               
-               _probe = vtkProbeFilter::New();
-               _probe->SetInput(_vtkplane);
+       
+       
+       
+       
+       
+       
 
-               _contourMapper = vtkPolyDataMapper::New();
-               
-               _contourMapper->SetInput( _probe->GetPolyDataOutput() );
 
-               _contourPlaneActor = vtkActor::New();
-               _contourPlaneActor->SetMapper(_contourMapper);
+       
+}
 
-               _contourPlaneActor->VisibilityOff();
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::ConfigureFreePlanes()
+{
 
-               _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
-               _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
+       // The shared picker enables us to use 3 planes at one time
+       // and gets the picking order right
+       vtkCellPicker* picker = vtkCellPicker::New();
+       picker->SetTolerance(0.005);
 
-               _planeWidget->Off();
-               _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );        
+       // The 3 image plane widgets 
+       _planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker);
+       _planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker);
+       _planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker);     
+       
+       _planeWidgetY->SetLookupTable(_planeWidgetX->GetLookupTable());
+       _planeWidgetZ->SetLookupTable(_planeWidgetX->GetLookupTable());
+       
+       picker->UnRegister(NULL);
+       
+}
 
-       }else{
-               
+//-------------------------------------------------------------------
+vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
+{
+       vtkProperty* prop1 = 0;         
+       vtkImagePlaneWidget* planeWidget = 0;
+       planeWidget = vtkImagePlaneWidget::New();
+       planeWidget->EnabledOff();
+       planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
+       vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
+       int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
+       double xSpacing = 0, ySpacing = 0, zSpacing = 0;
+       if(image){
+               planeWidget->SetInput( image );
+               image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);   
+               image->GetSpacing(xSpacing, ySpacing, zSpacing);
        }
-       _planeWidget->GetPolyData(_vtkplane);
 
        
-       vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData(); 
-       _probe->SetSource( imageData );
-
        
-       _contourMapper->SetScalarRange( imageData->GetScalarRange() );
-    
        
+               
+       
+       if (activationkey=='x')
+       {
+               planeWidget->SetPlaneOrientationToXAxes();       
+               planeWidget->SetSlicePosition((xMax+xMin)/2.*xSpacing);
+       }
+       
+       if (activationkey=='y')
+       {
+               planeWidget->SetPlaneOrientationToYAxes();
+               planeWidget->SetSlicePosition((yMax+yMin)/2.*ySpacing);
+       }
+               
+       if (activationkey=='z')
+       {
+               planeWidget->SetPlaneOrientationToZAxes();
+               planeWidget->SetSlicePosition((zMax+zMin)/2.*zSpacing);
+       }
+       
+       planeWidget->DisplayTextOn();
+       planeWidget->SetPicker(picker);
+       planeWidget->SetKeyPressActivationValue(activationkey);
+       prop1 = planeWidget->GetPlaneProperty();
+       prop1->SetColor(r, g, b);
+       return planeWidget;
+}
 
-                       
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::FreePlaneVisible(int plane, bool ok)
+{
+       if(_planeWidgetX){
+               if ((plane==1) && (ok==true)) _planeWidgetX->EnabledOn();
+               if ((plane==2) && (ok==true)) _planeWidgetY->EnabledOn();
+               if ((plane==3) && (ok==true)) _planeWidgetZ->EnabledOn();
+               if ((plane==1) && (ok==false)) _planeWidgetX->EnabledOff();
+               if ((plane==2) && (ok==false)) _planeWidgetY->EnabledOff();
+               if ((plane==3) && (ok==false)) _planeWidgetZ->EnabledOff();
+       }
 }
+
 //-------------------------------------------------------------------
-wxVtkMPR3DView::~wxVtkMPR3DView()
+void wxVtkMPR3DView::FreePlaneInteraction(bool ok)
+{
+       if(_planeWidgetX){
+               if (ok==true)
+               {
+                       _planeWidgetX->InteractionOn();
+                       _planeWidgetY->InteractionOn();
+                       _planeWidgetZ->InteractionOn();
+               } else {
+                       _planeWidgetX->InteractionOff();
+                       _planeWidgetY->InteractionOff();
+                       _planeWidgetZ->InteractionOff();
+               }
+       }
+}
+
+
+//-------------------------------------------------------------------
+void wxVtkMPR3DView::setColorTransferFunction(vtkColorTransferFunction* colortable)
 {
+       GetVtkMPR3DDataViewer ()->setColorTransferFunction(colortable); 
 }
 
 //-------------------------------------------------------------------
@@ -193,11 +344,21 @@ void wxVtkMPR3DView::Refresh()   // virtual
        }
 
 }
+
 //-------------------------------------------------------------------
 void wxVtkMPR3DView::RefreshView()   // virtual
 {
        double spc[3];
-       this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
+       vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
+       
+       if(image){
+               image->GetSpacing(spc);
+       }else{
+               spc[0] = 0;
+               spc[1] = 0;
+               spc[2] = 0;
+       }
+       //this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
 
        //double nx=1,ny=0,nz=0; // JPRx
        Refresh();
@@ -209,25 +370,27 @@ void wxVtkMPR3DView::RefreshView()   // virtual
        y=y*spc[1];
        z=z*spc[2];
 
-       _pointWidget->SetPosition( x,y,z ); 
+       if(_pointWidget){
+               _pointWidget->SetPosition( x,y,z ); 
 
 
-       double in[3]; 
-       double normal[3];
-       vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
-       in[0]=1;                in[1]=0;                        in[2]=0;
-       transform->TransformPoint(in,normal);
-       _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
+               double in[3]; 
+               double normal[3];
+               vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
+               in[0]=1;                in[1]=0;                        in[2]=0;
+               transform->TransformPoint(in,normal);
+               _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
 
 
-       _planeWidget->SetCenter( x,y,z );
-       _planeWidget->UpdatePlacement();
-       _planeWidget->GetPolyData(_vtkplane);
+               _planeWidget->SetCenter( x,y,z );
+               _planeWidget->UpdatePlacement();
+               _planeWidget->GetPolyData(_vtkplane);
+       }
 }
 //-------------------------------------------------------------------
-wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent)
+wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent, bool align)
 {
-       _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this);
+       _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this, align);
        return _wxvtkmpr3DviewCntrlPanel;
 }
 //-------------------------------------------------------------------
@@ -247,6 +410,14 @@ wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
 
 //-------------------------------------------------------------------
 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
+       /*if(visible == false)
+               printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == false \n");
+       else
+       {
+               printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == true\n");
+               printf("CPR: wxVtkMPR3DView::VisibleImageActor-> idPosition == %d\n", idPosition);
+       }
+       */
        if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
                if (visible==false){
                        _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );        
@@ -261,25 +432,43 @@ void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
 //-------------------------------------------------------------------
 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
 {
-       if (visible==true)
-       {
-               _pointWidget->On();
-       } else {
-               _pointWidget->Off();
+       if(_pointWidget){
+               if (visible==true)
+               {
+                       _pointWidget->On();
+               } else {
+                       _pointWidget->Off();
+               }
        }
 }
 
 //-------------------------------------------------------------------
 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
 {
-       if (visible==true)
-       {
-               _planeWidget->On();
-               _contourPlaneActor->VisibilityOn();
+       if(_planeWidget){
+               if (visible==true)
+               {
+                       _planeWidget->On();
+                       _contourPlaneActor->VisibilityOn();
+
+               } else {
+                       _planeWidget->Off();
+                       _contourPlaneActor->VisibilityOff();
+               }
+       }
+}
 
-       } else {
-               _planeWidget->Off();
-               _contourPlaneActor->VisibilityOff();
+//CPR: Method added 30 Nov 2009
+void wxVtkMPR3DView::showOutlineActor(bool value)
+{
+       vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
+       if(value == true)
+       {
+               _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );     
+       }
+       else
+       {
+               _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _outlineActor );  
        }
 }
 
@@ -487,4 +676,5 @@ void wxVtkMPR3DView::TestLoic2()
   iren->Start();
 
 
-}
\ No newline at end of file
+}
+