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