]> Creatis software - cpPlugins.git/blob - appli/ImageMPR/ImageMPR.cxx
Generic MPR+Plugins application base updated.
[cpPlugins.git] / appli / ImageMPR / ImageMPR.cxx
1 #include "ImageMPR.h"
2 #include "ui_ImageMPR.h"
3
4 #include <QMessageBox>
5
6 // -------------------------------------------------------------------------
7 #define ImageMPR_ConnectAction( ACTION )                \
8   QObject::connect(                                     \
9     this->m_UI->a##ACTION, SIGNAL( triggered( ) ),      \
10     this, SLOT( _a##ACTION( ) )                         \
11     )
12
13 // -------------------------------------------------------------------------
14 ImageMPR::
15 ImageMPR( QWidget* parent )
16   : QMainWindow( parent ),
17     m_UI( new Ui::ImageMPR ),
18     m_Plugins( new TPlugins ),
19     m_MainImage( NULL )
20 {
21   this->m_UI->setupUi( this );
22   this->m_Plugins->SetWidget( this );
23
24   // Connect actions
25   ImageMPR_ConnectAction( OpenImage );
26   ImageMPR_ConnectAction( OpenDICOMSeries );
27   ImageMPR_ConnectAction( OpenSegmentation );
28   ImageMPR_ConnectAction( OpenPolyData );
29   ImageMPR_ConnectAction( SaveImage );
30   ImageMPR_ConnectAction( SaveSegmentation );
31   ImageMPR_ConnectAction( SavePolyData );
32   ImageMPR_ConnectAction( Undo );
33   ImageMPR_ConnectAction( Redo );
34   ImageMPR_ConnectAction( LoadPlugins );
35   ImageMPR_ConnectAction( ShowPlugins );
36
37   // Try to load default plugins
38   this->m_Plugins->LoadPluginsConfigurationFile( "Plugins.cfg" );
39   this->m_Plugins->AssociatePluginsToMenu(
40     this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) )
41     );
42 }
43
44 // -------------------------------------------------------------------------
45 ImageMPR::
46 ~ImageMPR( )
47 {
48   delete this->m_UI;
49   delete this->m_Plugins;
50 }
51
52 // -------------------------------------------------------------------------
53 void ImageMPR::
54 _aOpenImage( )
55 {
56   if( this->m_MainImage.IsNotNull( ) )
57     this->m_UI->MPR->ClearAll( );
58   if( this->m_Plugins->ReadImage( this->m_MainImage, true ) )
59   {
60     vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( );
61     if( vimage == NULL )
62       QMessageBox::critical(
63         this,
64         QMessageBox::tr( "Error showing image." ),
65         QMessageBox::tr(
66           "Image was read, but no valid VTK conversion was found."
67           )
68         );
69     else
70       this->m_UI->MPR->ShowImage( vimage );
71
72   } // fi
73 }
74
75 // -------------------------------------------------------------------------
76 void ImageMPR::
77 _aOpenDICOMSeries( )
78 {
79   if( this->m_MainImage.IsNotNull( ) )
80     this->m_UI->MPR->ClearAll( );
81   if( this->m_Plugins->ReadDicomSeries( this->m_MainImage ) )
82   {
83     vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( );
84     if( vimage == NULL )
85       QMessageBox::critical(
86         this,
87         QMessageBox::tr( "Error showing image." ),
88         QMessageBox::tr(
89           "Image was read, but no valid VTK conversion was found."
90           )
91         );
92     else
93       this->m_UI->MPR->ShowImage( vimage );
94
95   } // fi
96 }
97
98 // -------------------------------------------------------------------------
99 void ImageMPR::
100 _aOpenSegmentation( )
101 {
102   /*
103     if( this->m_ImageLoaded != "" )
104     this->m_ImageLoaded = this->m_UI->MPR->LoadImage( );
105   */
106 }
107
108 // -------------------------------------------------------------------------
109 void ImageMPR::
110 _aOpenPolyData( )
111 {
112 }
113
114 // -------------------------------------------------------------------------
115 void ImageMPR::
116 _aSaveImage( )
117 {
118   if( this->m_MainImage.IsNotNull( ) )
119     this->m_Plugins->WriteImage( this->m_MainImage, true );
120 }
121
122 // -------------------------------------------------------------------------
123 void ImageMPR::
124 _aSaveSegmentation( )
125 {
126 }
127
128 // -------------------------------------------------------------------------
129 void ImageMPR::
130 _aSavePolyData( )
131 {
132 }
133
134 // -------------------------------------------------------------------------
135 void ImageMPR::
136 _aUndo( )
137 {
138 }
139
140 // -------------------------------------------------------------------------
141 void ImageMPR::
142 _aRedo( )
143 {
144 }
145
146 // -------------------------------------------------------------------------
147 void ImageMPR::
148 _aLoadPlugins( )
149 {
150   this->m_Plugins->DialogLoadPlugins( );
151   this->m_Plugins->AssociatePluginsToMenu(
152     this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) )
153     );
154 }
155
156 // -------------------------------------------------------------------------
157 void ImageMPR::
158 _aShowPlugins( )
159 {
160 }
161
162 // -------------------------------------------------------------------------
163 void ImageMPR::
164 _execPlugin( )
165 {
166   // Get filter name
167   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
168   if( action == NULL )
169     return;
170   QMenu* menu = dynamic_cast< QMenu* >( action->parentWidget( ) );
171   if( menu == NULL )
172     return;
173   std::string cate = menu->title( ).toStdString( );
174   std::string name = action->text( ).toStdString( );
175   std::string err = "";
176
177   TPlugins::TProcessObject::Pointer filter;
178   if( this->m_Plugins->CreateFilter( filter, name ) )
179   {
180     if( cate == "ImageToMeshFilter" )
181     {
182       if( filter->ExecConfigurationDialog( this ) )
183       {
184         filter->SetInput( "Input", this->m_MainImage );
185         this->_Block( );
186         err = filter->Update( );
187         this->_Unblock( );
188         TPlugins::TMesh::Pointer mesh =
189           filter->GetOutput< TPlugins::TMesh >( "Input" );
190         mesh->Print( std::cout );
191
192       } // fi
193
194     } // fi
195   }
196   else
197     QMessageBox::critical(
198       this,
199       tr( "Error creating filter" ),
200       tr( "No valid filter defined." )
201       );
202
203   /*
204     if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" )
205     {
206     this->m_Flooding = true;
207     }
208     else
209     {
210     this->m_Flooding = false;
211     this->m_UI->MPR->ExecuteFilter(
212     name, this->m_ImageLoaded, "SegmentedImage"
213     );
214     
215     } // fi
216   */
217   
218   // Configure filter
219   /*
220     TPluginFilter::Pointer filter =
221     this->m_Plugins.CreateProcessObject( name );
222     bool dlg_ok = filter->ExecConfigurationDialog( NULL );
223     if( !dlg_ok )
224     return;
225
226     // Execute filter
227     QApplication::setOverrideCursor( Qt::WaitCursor );
228     this->setEnabled( false );
229     filter->SetInput( 0, this->m_Image );
230     std::string err = filter->Update( );
231     QApplication::restoreOverrideCursor( );
232     this->setEnabled( true );
233
234     // Update image
235     if( err == "" )
236     {
237     TPluginImage* result = filter->GetOutput< TPluginImage >( 0 );
238     result->DisconnectPipeline( );
239     this->m_Image = result;
240     if( this->m_Image.IsNotNull( ) )
241     this->m_MPRObjects->SetImage(
242     this->m_Image->GetVTK< vtkImageData >( )
243     );
244     MementoState(this->m_state, this->m_Image);
245     this->m_state++;
246     if (this->m_state > this->m_max_state)
247     {
248     this->m_max_state = this->m_state;
249     }
250     }
251     else
252     QMessageBox::critical(
253     this,
254     tr( "Error executing filter" ),
255     tr( err.c_str( ) )
256     );
257   */
258 }
259
260 // -------------------------------------------------------------------------
261 /* TODO
262    void ImageMPR::
263    _CursorCommand( double* pos, int axis, void* data )
264    {
265    Self* app = reinterpret_cast< Self* >( data );
266    if( app == NULL )
267    return;
268    if( !( app->m_Flooding ) )
269    return;
270
271    cpPlugins::Interface::ProcessObject::Pointer filter =
272    app->m_UI->MPR->CreateFilter(
273    "cpPlugins::BasicFilters::FloodFillImageFilter"
274    );
275    if( filter.IsNull( ) )
276    return;
277
278    cpPlugins::Interface::Parameters* params = filter->GetParameters( );
279    params->SetPoint( "Seed", 3, pos );
280    params->SetReal( "Window", app->m_UI->MPR->GetWindow( ) );
281    params->SetReal( "Level", app->m_UI->MPR->GetLevel( ) );
282    params->SetUint( "InsideValue", 1 );
283    params->SetUint( "OutsideValue", 0 );
284    filter->SetInput( "Input", app->m_UI->MPR->GetImage( app->m_ImageLoaded ) );
285    app->m_UI->MPR->Block( );
286    std::string err = filter->Update( );
287    cpPlugins::Interface::BaseMPRWindow::TImage::Pointer image = filter->GetOutput< cpPlugins::Interface::BaseMPRWindow::TImage >( "Output" );
288    filter->DisconnectOutputs( );
289    app->m_UI->MPR->AddImage( "Segmentation", image );
290    app->m_UI->MPR->Unblock( );
291
292    std::cout
293    << "CursorCommand ==> "
294    << pos[ 0 ] << " "
295    << pos[ 1 ] << " "
296    << pos[ 2 ] << " : "
297    << axis << " "
298    << data << std::endl;
299    }
300 */
301
302 /*
303 #include "MementoState.h"
304
305 #include <vtkProperty.h>
306 #include <vtkRenderWindow.h>
307 #include <vtkMetaImageReader.h>
308
309 #include <QFileDialog>
310 #include <QMessageBox>
311
312 #ifdef _WIN32
313 #  define PLUGIN_PREFIX ""
314 #  define PLUGIN_EXT "dll"
315 #  define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
316 #else
317 #  define PLUGIN_PREFIX "lib"
318 #  define PLUGIN_EXT "so"
319 #  define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
320 #endif // _WIN32
321
322 // -------------------------------------------------------------------------
323 ImageMPR::ImageMPR( QWidget* parent )
324   : QMainWindow( parent ),
325     m_UI( new Ui::ImageMPR ),
326     m_ImageReaderClass( "" ),
327     m_ImageWriterClass( "" ),
328     m_MeshReaderClass( "" ),
329     m_MeshWriterClass( "" ),
330     m_MeshCutterClass( "" ),
331     m_Image( NULL ),
332         m_state(0),
333         m_max_state(0)
334 {
335   this->m_UI->setupUi( this );
336
337   // Create and associate renderers
338   this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
339   this->m_MPRObjects->SetRenderWindows(
340     this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
341     this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
342     this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
343     this->m_UI->m_3DVTK->GetRenderWindow( )
344     );
345
346   // signals <-> slots
347   QObject::connect(
348     this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
349     this, SLOT( _triggered_actionOpenPlugins( ) )
350     );
351   QObject::connect(
352     this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
353     this, SLOT( _triggered_actionOpenInputImage( ) )
354     );
355   QObject::connect(
356     this->m_UI->actionOpenSegmentation, SIGNAL( triggered( ) ),
357     this, SLOT( _triggered_actionOpenSegmentation( ) )
358     );
359   QObject::connect(
360     this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
361     this, SLOT( _triggered_actionOpenInputPolyData( ) )
362     );
363   QObject::connect(
364         this->m_UI->actionUndo, SIGNAL(triggered()),
365         this, SLOT(_triggered_actionUndo())
366         );
367   QObject::connect(
368         this->m_UI->actionRedo, SIGNAL(triggered()),
369         this, SLOT(_triggered_actionRedo())
370         );
371
372   // Start: load all disponible plugins
373   this->_LoadPlugins(
374     std::string( PLUGIN_PREFIX ) +
375     std::string( "cpPluginsIO." ) +
376     std::string( PLUGIN_EXT )
377     );
378   this->_LoadPlugins(
379     std::string( PLUGIN_PREFIX ) +
380     std::string( "cpPluginsBasicFilters." ) +
381     std::string( PLUGIN_EXT )
382     );
383 }
384
385 // -------------------------------------------------------------------------
386 ImageMPR::
387 ~ImageMPR( )
388 {
389   // Close all connections
390   this->m_Plugins.UnloadAll( );
391
392   // Delete objects
393   delete this->m_UI;
394 }
395
396 // -------------------------------------------------------------------------
397 bool ImageMPR::
398 _LoadPlugins( const std::string& filename )
399 {
400   QApplication::setOverrideCursor( Qt::WaitCursor );
401   this->setEnabled( false );
402
403   this->m_ImageReaderClass = "";
404   this->m_ImageWriterClass = "";
405   this->m_MeshReaderClass = "";
406   this->m_MeshWriterClass = "";
407   this->m_MeshCutterClass = "";
408   this->m_UI->MenuImageToImage->clear( );
409   this->m_UI->MenuImageToMesh->clear( );
410
411   if( !( this->m_Plugins.Load( filename ) ) )
412     return( false );
413
414   typedef TPluginsInterface::TClasses _TClasses;
415   _TClasses::const_iterator cIt = this->m_Plugins.GetClasses( ).begin( );
416   for( ; cIt != this->m_Plugins.GetClasses( ).end( ); ++cIt )
417   {
418     TPluginFilter::Pointer o =
419       this->m_Plugins.CreateProcessObject( cIt->first );
420     std::string name = o->GetClassName( );
421     std::string category = o->GetClassCategory( );
422     if( category == "ImageReader" )
423       this->m_ImageReaderClass = name;
424     else if( category == "ImageWriter" )
425       this->m_ImageWriterClass = name;
426     else if( category == "MeshReader" )
427       this->m_MeshReaderClass = name;
428     else if( category == "MeshWriter" )
429       this->m_MeshWriterClass = name;
430     else if( category == "MeshToMeshFilter" )
431     {
432       if( name.find_last_of( "Cutter" ) != std::string::npos )
433         this->m_MeshCutterClass = name;
434     }
435     else if( category == "ImageToImageFilter" )
436     {
437       QAction* action =
438         this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) );
439       QObject::connect(
440         action, SIGNAL( triggered( ) ),
441         this, SLOT( _triggered_actionImageToImage( ) )
442         );
443     }
444     else if( category == "ImageToMeshFilter" )
445     {
446       QAction* action =
447         this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) );
448       QObject::connect(
449         action, SIGNAL( triggered( ) ),
450         this, SLOT( _triggered_actionImageToMesh( ) )
451         );
452
453     } // fi
454
455   } // rof
456   QApplication::restoreOverrideCursor( );
457   this->setEnabled( true );
458
459   return( true );
460 }
461
462 // -------------------------------------------------------------------------
463 std::string ImageMPR::
464 _LoadImage( TPluginImage::Pointer& image )
465 {
466   std::string ret = "";
467   image = NULL;
468
469   // Get a reader from loaded plugins
470   TPluginFilter::Pointer reader =
471     this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass );
472   if( reader.IsNotNull( ) )
473   {
474     if( reader->ExecConfigurationDialog( this ) )
475     {
476       // Block application
477       QApplication::setOverrideCursor( Qt::WaitCursor );
478       this->setEnabled( false );
479
480       // Execute and get error message, if any
481       ret = reader->Update( );
482
483       // Assign fresh image, if any
484       if( ret == "" )
485       {
486         image = reader->GetOutput< TPluginImage >( 0 );
487         reader->DisconnectOutputs( );
488
489       } // fi
490
491       // Unblock application
492       QApplication::restoreOverrideCursor( );
493       this->setEnabled( true );
494
495     } // fi
496   }
497   else
498     ret = "No suitable reader object found in loaded plugins.";
499   
500   return( ret );
501 }
502
503 // -------------------------------------------------------------------------
504 std::string ImageMPR::
505 _ConfigureMeshActors( )
506 {
507   if( this->m_Mesh.IsNull( ) )
508     return( "Valid mesh not found." );
509
510   this->m_Mesh->CreateVTKActor( );
511   vtkActor* vtk_actor = this->m_Mesh->GetVTKActor( );
512   if( vtk_actor != NULL )
513   {
514     this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor );
515     this->m_MPRObjects->Render( 4 );
516
517   } // fi
518
519   TMPRObjects::TMPRActors* mprActors = this->m_MPRObjects->GetMPRActors( );
520
521   std::string err = "";
522   for( unsigned int i = 0; i < 3; ++i )
523   {
524     this->m_Cutters[ i ] = this->m_Plugins.CreateProcessObject( this->m_MeshCutterClass );
525     this->m_Planes[ i ] = TPluginImplicitFunction::New( );
526     this->m_Planes[ i ]->SetFunction( mprActors->GetSliceActors( i )->GetPlaneFunction( ) );
527     this->m_Cutters[ i ]->SetInput( 0, this->m_Mesh );
528     this->m_Cutters[ i ]->SetInput( 1, this->m_Planes[ i ] );
529     std::string lerr = this->m_Cutters[ i ]->Update( );
530     if( lerr == "" )
531     {
532       this->m_Cutters[ i ]->GetOutput< TPluginMesh >( 0 )->CreateVTKActor( );
533       vtkActor* actor = this->m_Cutters[ i ]->GetOutput< TPluginMesh >( 0 )->GetVTKActor( );
534       mprActors->GetSliceActors( i )->AddActor( this->m_Cutters[ i ]->GetVTK< vtkAlgorithm >( ), actor );
535       if( i == 0 )
536         this->m_MPRObjects->GetXRenderer( )->AddActor( actor );
537       else if( i == 1 )
538         this->m_MPRObjects->GetYRenderer( )->AddActor( actor );
539       else if( i == 2 )
540         this->m_MPRObjects->GetZRenderer( )->AddActor( actor );
541
542     } // fi
543     err += lerr;
544
545   } // rof
546   this->m_MPRObjects->RenderAll( );
547   return( err );
548 }
549
550 // -------------------------------------------------------------------------
551 void ImageMPR::
552 _triggered_actionOpenPlugins( )
553 {
554   // Show dialog and check if it was accepted
555   QFileDialog dialog( this );
556   dialog.setFileMode( QFileDialog::ExistingFile );
557   dialog.setDirectory( "." );
558   dialog.setNameFilter( tr( PLUGIN_REGEX ) );
559   dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
560   if( !( dialog.exec( ) ) )
561     return;
562   
563   std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
564   if( !( _LoadPlugins( fname ) ) )
565     QMessageBox::critical(
566       this,
567       tr( "Ignoring plugin" ),
568       tr( fname.c_str( ) )
569       );
570 }
571
572 // -------------------------------------------------------------------------
573 void ImageMPR::
574 _triggered_actionOpenInputImage( )
575 {
576   // Read image
577   std::string err = this->_LoadImage( this->m_Image );
578   if( err == "" )
579   {
580     vtkImageData* vtk_id = this->m_Image->GetVTK< vtkImageData >( );
581     if( vtk_id != NULL )
582     {
583       this->m_MPRObjects->SetImage( vtk_id );
584       this->m_MPRObjects->ActivateInteractors( );
585       this->m_MPRObjects->ResetCameras( );
586       this->m_MPRObjects->RenderAll( );
587
588           MementoState(m_state, this->m_Image);  
589           this->m_state++;
590     }
591     else
592       QMessageBox::critical(
593         this,
594         tr( "Error message" ),
595         tr( "Read image does not have a valid VTK converter." )
596         );
597   }
598   else
599     QMessageBox::critical(
600       this,
601       tr( "Error reading single image" ),
602       tr( err.c_str( ) )
603       );
604 }
605
606 // -------------------------------------------------------------------------
607 void ImageMPR::
608 _triggered_actionOpenSegmentation( )
609 {
610   if( this->m_Image.IsNull( ) )
611   {
612     QMessageBox::critical(
613       this,
614       tr( "Error message" ),
615       tr( "Before reading a segmentation, first load a raw image." )
616       );
617     return;
618
619   } // fi
620
621   // Read image
622   std::string err = this->_LoadImage( this->m_Segmentation );
623   if( err == "" )
624   {
625     vtkImageData* vtk_id = this->m_Segmentation->GetVTK< vtkImageData >( );
626     if( vtk_id != NULL )
627     {
628       this->m_MPRObjects->AddAuxiliaryImage( vtk_id );
629       this->m_MPRObjects->RenderAll( );
630     }
631     else
632       QMessageBox::critical(
633         this,
634         tr( "Error message" ),
635         tr( "Read image does not have a valid VTK converter." )
636         );
637   }
638   else
639     QMessageBox::critical(
640       this,
641       tr( "Error reading single image" ),
642       tr( err.c_str( ) )
643       );
644 }
645
646 // -------------------------------------------------------------------------
647 void ImageMPR::
648 _triggered_actionOpenInputPolyData( )
649 {
650   this->m_Mesh = NULL;
651
652   // Get a reader from plugins
653   TPluginFilter::Pointer reader =
654     this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass );
655
656   if( reader.IsNotNull( ) )
657   {
658     // Configure reader
659     if( reader->ExecConfigurationDialog( this ) )
660     {
661       // Execute and get error message, if any
662       QApplication::setOverrideCursor( Qt::WaitCursor );
663       this->setEnabled( false );
664       std::string err = reader->Update( );
665       QApplication::restoreOverrideCursor( );
666       this->setEnabled( true );
667
668       // Assign fresh mesh, if any
669       if( err == "" )
670       {
671         this->m_Mesh = reader->GetOutput< TPluginMesh >( 0 );
672         reader->DisconnectOutputs( );
673         err = this->_ConfigureMeshActors( );
674         if( err != "" )
675           QMessageBox::critical(
676             this,
677             tr( "Error message" ),
678             tr( err.c_str( ) )
679             );
680       }
681       else
682         QMessageBox::critical(
683           this,
684           tr( "Error reading mesh" ),
685           tr( err.c_str( ) )
686           );
687
688     } // fi
689   }
690   else
691     QMessageBox::critical(
692       this,
693       tr( "Error reading single mesh" ),
694       tr( "No suitable mesh reader found in loaded plugins." )
695       );
696 }
697
698 // -------------------------------------------------------------------------
699 void ImageMPR::
700 _triggered_actionImageToImage( )
701 {
702   if( this->m_Image.IsNull( ) )
703     return;
704
705   // Get filter name
706   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
707   if( action == NULL )
708     return;
709   std::string name = action->text( ).toStdString( );
710
711   // Configure filter
712   TPluginFilter::Pointer filter =
713     this->m_Plugins.CreateProcessObject( name );
714   bool dlg_ok = filter->ExecConfigurationDialog( NULL );
715   if( !dlg_ok )
716     return;
717
718   // Execute filter
719   QApplication::setOverrideCursor( Qt::WaitCursor );
720   this->setEnabled( false );
721   filter->SetInput( 0, this->m_Image );
722   std::string err = filter->Update( );
723   QApplication::restoreOverrideCursor( );
724   this->setEnabled( true );
725
726   // Update image
727   if( err == "" )
728   {
729     TPluginImage* result = filter->GetOutput< TPluginImage >( 0 );
730     result->DisconnectPipeline( );
731     this->m_Image = result;
732     if( this->m_Image.IsNotNull( ) )
733       this->m_MPRObjects->SetImage(
734         this->m_Image->GetVTK< vtkImageData >( )
735
736                 );
737         
738         
739         MementoState(this->m_state, this->m_Image);
740         this->m_state++;
741         if (this->m_state > this->m_max_state)
742         {
743                 this->m_max_state = this->m_state;
744         }
745   }
746   else
747     QMessageBox::critical(
748       this,
749       tr( "Error executing filter" ),
750       tr( err.c_str( ) )
751       );
752 }
753
754 // -------------------------------------------------------------------------
755 void ImageMPR::
756 _triggered_actionImageToMesh( )
757 {
758   if( this->m_Image.IsNull( ) )
759     return;
760
761   // Get filter name
762   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
763   if( action == NULL )
764     return;
765   std::string name = action->text( ).toStdString( );
766
767   // Configure filter
768   TPluginFilter::Pointer filter =
769     this->m_Plugins.CreateProcessObject( name );
770   bool dlg_ok = filter->ExecConfigurationDialog( NULL );
771   if( !dlg_ok )
772     return;
773
774   // Execute filter
775   QApplication::setOverrideCursor( Qt::WaitCursor );
776   this->setEnabled( false );
777   filter->SetInput( 0, this->m_Image );
778   std::string err = filter->Update( );
779   QApplication::restoreOverrideCursor( );
780   this->setEnabled( true );
781
782   // Update image
783   if( err == "" )
784   {
785     TPluginMesh* result = filter->GetOutput< TPluginMesh >( 0 );
786     result->DisconnectPipeline( );
787     this->m_Mesh = result;
788     err = this->_ConfigureMeshActors( );
789     if( err != "" )
790       QMessageBox::critical(
791         this,
792         tr( "Error message" ),
793         tr( err.c_str( ) )
794         );
795   }
796   else
797     QMessageBox::critical(
798       this,
799       tr( "Error executing filter" ),
800       tr( err.c_str( ) )
801       );
802 }
803
804 // -------------------------------------------------------------------------
805 void ImageMPR::
806 _triggered_actionUndo()
807 {
808         MementoState memento = MementoState();
809     
810         if (this->m_state>1)
811         {
812                 this->m_state--;
813                 this->m_MPRObjects->SetImage(
814                         memento.getMemento(this->m_state)->GetOutput()
815                         );
816         } else
817         {
818                 QMessageBox::warning(
819                         this,
820                         tr("message"),
821                         tr("No history to undo")
822                         );
823         }
824
825 }
826
827 // -------------------------------------------------------------------------
828 void ImageMPR::
829 _triggered_actionRedo()
830 {
831         MementoState memento = MementoState();
832                 if (this->m_state + 1 <= m_max_state)
833                 {
834                         this->m_state++;
835                         this->m_MPRObjects->SetImage(
836                                 memento.getMemento(this->m_state)->GetOutput()
837                                 );
838                 } else
839                 {
840                         QMessageBox::warning(
841                                 this,
842                                 tr("message"),
843                                 tr("No history to redo")
844                                 );
845                 }
846         
847 }
848         
849 */
850
851 // eof - $RCSfile$