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