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