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