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