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