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