]> Creatis software - cpPlugins.git/blobdiff - appli/ImageMPR/ImageMPR.cxx
update: undo/redo for image to image filters
[cpPlugins.git] / appli / ImageMPR / ImageMPR.cxx
index 7fffc2732df90c2864acef0691e53db90bc2e463..402baff2c1b1c4a074f6da2af00f34b50fe3692b 100644 (file)
@@ -1,8 +1,10 @@
 #include "ImageMPR.h"
+#include "MementoState.h"
 #include "ui_ImageMPR.h"
 
 #include <vtkProperty.h>
 #include <vtkRenderWindow.h>
+#include <vtkMetaImageReader.h>
 
 #include <QFileDialog>
 #include <QMessageBox>
@@ -26,7 +28,9 @@ ImageMPR::ImageMPR( QWidget* parent )
     m_MeshReaderClass( "" ),
     m_MeshWriterClass( "" ),
     m_MeshCutterClass( "" ),
-    m_Image( NULL )
+    m_Image( NULL ),
+       m_state(0),
+       m_max_state(0)
 {
   this->m_UI->setupUi( this );
 
@@ -56,6 +60,14 @@ ImageMPR::ImageMPR( QWidget* parent )
     this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
     this, SLOT( _triggered_actionOpenInputPolyData( ) )
     );
+  QObject::connect(
+       this->m_UI->actionUndo, SIGNAL(triggered()),
+       this, SLOT(_triggered_actionUndo())
+       );
+  QObject::connect(
+       this->m_UI->actionRedo, SIGNAL(triggered()),
+       this, SLOT(_triggered_actionRedo())
+       );
 
   // Start: load all disponible plugins
   this->_LoadPlugins(
@@ -194,7 +206,8 @@ _ConfigureMeshActors( )
 {
   if( this->m_Mesh.IsNull( ) )
     return( "Valid mesh not found." );
-  
+
+  this->m_Mesh->CreateVTKActor( );
   vtkActor* vtk_actor = this->m_Mesh->GetVTKActor( );
   if( vtk_actor != NULL )
   {
@@ -216,8 +229,9 @@ _ConfigureMeshActors( )
     std::string lerr = this->m_Cutters[ i ]->Update( );
     if( lerr == "" )
     {
+      this->m_Cutters[ i ]->GetOutput< TPluginMesh >( 0 )->CreateVTKActor( );
       vtkActor* actor = this->m_Cutters[ i ]->GetOutput< TPluginMesh >( 0 )->GetVTKActor( );
-      mprActors->GetSliceActors( i )->AddActor( this->m_Cutters[ i ]->GetVTKAlgorithm( ), actor );
+      mprActors->GetSliceActors( i )->AddActor( this->m_Cutters[ i ]->GetVTK< vtkAlgorithm >( ), actor );
       if( i == 0 )
         this->m_MPRObjects->GetXRenderer( )->AddActor( actor );
       else if( i == 1 )
@@ -263,13 +277,16 @@ _triggered_actionOpenInputImage( )
   std::string err = this->_LoadImage( this->m_Image );
   if( err == "" )
   {
-    vtkImageData* vtk_id = this->m_Image->GetVTKImageData( );
+    vtkImageData* vtk_id = this->m_Image->GetVTK< vtkImageData >( );
     if( vtk_id != NULL )
     {
       this->m_MPRObjects->SetImage( vtk_id );
       this->m_MPRObjects->ActivateInteractors( );
       this->m_MPRObjects->ResetCameras( );
       this->m_MPRObjects->RenderAll( );
+
+         MementoState(m_state, this->m_Image);  
+         this->m_state++;
     }
     else
       QMessageBox::critical(
@@ -305,7 +322,7 @@ _triggered_actionOpenSegmentation( )
   std::string err = this->_LoadImage( this->m_Segmentation );
   if( err == "" )
   {
-    vtkImageData* vtk_id = this->m_Segmentation->GetVTKImageData( );
+    vtkImageData* vtk_id = this->m_Segmentation->GetVTK< vtkImageData >( );
     if( vtk_id != NULL )
     {
       this->m_MPRObjects->AddAuxiliaryImage( vtk_id );
@@ -413,7 +430,18 @@ _triggered_actionImageToImage( )
     result->DisconnectPipeline( );
     this->m_Image = result;
     if( this->m_Image.IsNotNull( ) )
-      this->m_MPRObjects->SetImage( this->m_Image->GetVTKImageData( ) );
+      this->m_MPRObjects->SetImage(
+        this->m_Image->GetVTK< vtkImageData >( )
+
+               );
+       
+       
+       MementoState(this->m_state, this->m_Image);
+       this->m_state++;
+       if (this->m_state > this->m_max_state)
+       {
+               this->m_max_state = this->m_state;
+       }
   }
   else
     QMessageBox::critical(
@@ -473,4 +501,50 @@ _triggered_actionImageToMesh( )
       );
 }
 
+// -------------------------------------------------------------------------
+void ImageMPR::
+_triggered_actionUndo()
+{
+       MementoState memento = MementoState();
+    
+       if (this->m_state>1)
+       {
+               this->m_state--;
+               this->m_MPRObjects->SetImage(
+                       memento.getMemento(this->m_state)->GetOutput()
+                       );
+       } else
+       {
+               QMessageBox::warning(
+                       this,
+                       tr("message"),
+                       tr("No history to undo")
+                       );
+       }
+
+}
+
+// -------------------------------------------------------------------------
+void ImageMPR::
+_triggered_actionRedo()
+{
+       MementoState memento = MementoState();
+               if (this->m_state + 1 <= m_max_state)
+               {
+                       this->m_state++;
+                       this->m_MPRObjects->SetImage(
+                               memento.getMemento(this->m_state)->GetOutput()
+                               );
+               } else
+               {
+                       QMessageBox::warning(
+                               this,
+                               tr("message"),
+                               tr("No history to redo")
+                               );
+               }
+       
+}
+       
+
 // eof - $RCSfile$