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