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