2 #include "ui_ImageMPR.h"
4 #include <vtkProperty.h>
5 #include <vtkRenderWindow.h>
11 # define PLUGIN_PREFIX ""
12 # define PLUGIN_EXT "dll"
13 # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
15 # define PLUGIN_PREFIX "lib"
16 # define PLUGIN_EXT "so"
17 # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
20 // -------------------------------------------------------------------------
21 ImageMPR::ImageMPR( QWidget* parent )
22 : QMainWindow( parent ),
23 m_UI( new Ui::ImageMPR ),
24 m_ImageReaderClass( "" ),
25 m_ImageWriterClass( "" ),
26 m_MeshReaderClass( "" ),
27 m_MeshWriterClass( "" ),
28 m_MeshCutterClass( "" ),
31 this->m_UI->setupUi( this );
33 // Create and associate renderers
34 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
35 this->m_MPRObjects->SetRenderWindows(
36 this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
37 this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
38 this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
39 this->m_UI->m_3DVTK->GetRenderWindow( )
44 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
45 this, SLOT( _triggered_actionOpenPlugins( ) )
48 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
49 this, SLOT( _triggered_actionOpenInputImage( ) )
52 this->m_UI->actionOpenSegmentation, SIGNAL( triggered( ) ),
53 this, SLOT( _triggered_actionOpenSegmentation( ) )
56 this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
57 this, SLOT( _triggered_actionOpenInputPolyData( ) )
60 // Start: load all disponible plugins
62 std::string( PLUGIN_PREFIX ) +
63 std::string( "cpPluginsIO." ) +
64 std::string( PLUGIN_EXT )
67 std::string( PLUGIN_PREFIX ) +
68 std::string( "cpPluginsBasicFilters." ) +
69 std::string( PLUGIN_EXT )
73 // -------------------------------------------------------------------------
77 // Close all connections
78 this->m_Plugins.UnloadAll( );
84 // -------------------------------------------------------------------------
86 _LoadPlugins( const std::string& filename )
88 QApplication::setOverrideCursor( Qt::WaitCursor );
89 this->setEnabled( false );
91 this->m_ImageReaderClass = "";
92 this->m_ImageWriterClass = "";
93 this->m_MeshReaderClass = "";
94 this->m_MeshWriterClass = "";
95 this->m_MeshCutterClass = "";
96 this->m_UI->MenuImageToImage->clear( );
97 this->m_UI->MenuImageToMesh->clear( );
99 if( !( this->m_Plugins.Load( filename ) ) )
102 typedef TPluginsInterface::TClasses _TClasses;
103 _TClasses::const_iterator cIt = this->m_Plugins.GetClasses( ).begin( );
104 for( ; cIt != this->m_Plugins.GetClasses( ).end( ); ++cIt )
106 TPluginFilter::Pointer o =
107 this->m_Plugins.CreateProcessObject( cIt->first );
108 std::string name = o->GetClassName( );
109 std::string category = o->GetClassCategory( );
110 if( category == "ImageReader" )
111 this->m_ImageReaderClass = name;
112 else if( category == "ImageWriter" )
113 this->m_ImageWriterClass = name;
114 else if( category == "MeshReader" )
115 this->m_MeshReaderClass = name;
116 else if( category == "MeshWriter" )
117 this->m_MeshWriterClass = name;
118 else if( category == "MeshToMeshFilter" )
120 if( name.find_last_of( "Cutter" ) != std::string::npos )
121 this->m_MeshCutterClass = name;
123 else if( category == "ImageToImageFilter" )
126 this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) );
128 action, SIGNAL( triggered( ) ),
129 this, SLOT( _triggered_actionImageToImage( ) )
132 else if( category == "ImageToMeshFilter" )
135 this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) );
137 action, SIGNAL( triggered( ) ),
138 this, SLOT( _triggered_actionImageToMesh( ) )
144 QApplication::restoreOverrideCursor( );
145 this->setEnabled( true );
150 // -------------------------------------------------------------------------
151 std::string ImageMPR::
152 _LoadImage( TPluginImage::Pointer& image )
154 std::string ret = "";
157 // Get a reader from loaded plugins
158 TPluginFilter::Pointer reader =
159 this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass );
160 if( reader.IsNotNull( ) )
162 if( reader->ExecConfigurationDialog( this ) )
165 QApplication::setOverrideCursor( Qt::WaitCursor );
166 this->setEnabled( false );
168 // Execute and get error message, if any
169 ret = reader->Update( );
171 // Assign fresh image, if any
174 image = reader->GetOutput< TPluginImage >( 0 );
175 reader->DisconnectOutputs( );
179 // Unblock application
180 QApplication::restoreOverrideCursor( );
181 this->setEnabled( true );
186 ret = "No suitable reader object found in loaded plugins.";
191 // -------------------------------------------------------------------------
192 std::string ImageMPR::
193 _ConfigureMeshActors( )
195 if( this->m_Mesh.IsNull( ) )
196 return( "Valid mesh not found." );
198 vtkActor* vtk_actor = this->m_Mesh->GetVTKActor( );
199 if( vtk_actor != NULL )
201 this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor );
202 this->m_MPRObjects->Render( 4 );
206 TMPRObjects::TMPRActors* mprActors = this->m_MPRObjects->GetMPRActors( );
208 std::string err = "";
209 for( unsigned int i = 0; i < 3; ++i )
211 this->m_Cutters[ i ] = this->m_Plugins.CreateProcessObject( this->m_MeshCutterClass );
212 this->m_Planes[ i ] = TPluginImplicitFunction::New( );
213 this->m_Planes[ i ]->SetFunction( mprActors->GetSliceActors( i )->GetPlaneFunction( ) );
214 this->m_Cutters[ i ]->SetInput( 0, this->m_Mesh );
215 this->m_Cutters[ i ]->SetInput( 1, this->m_Planes[ i ] );
216 std::string lerr = this->m_Cutters[ i ]->Update( );
219 vtkActor* actor = this->m_Cutters[ i ]->GetOutput< TPluginMesh >( 0 )->GetVTKActor( );
220 mprActors->GetSliceActors( i )->AddActor( this->m_Cutters[ i ]->GetVTKAlgorithm( ), actor );
222 this->m_MPRObjects->GetXRenderer( )->AddActor( actor );
224 this->m_MPRObjects->GetYRenderer( )->AddActor( actor );
226 this->m_MPRObjects->GetZRenderer( )->AddActor( actor );
232 this->m_MPRObjects->RenderAll( );
236 // -------------------------------------------------------------------------
238 _triggered_actionOpenPlugins( )
240 // Show dialog and check if it was accepted
241 QFileDialog dialog( this );
242 dialog.setFileMode( QFileDialog::ExistingFile );
243 dialog.setDirectory( "." );
244 dialog.setNameFilter( tr( PLUGIN_REGEX ) );
245 dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
246 if( !( dialog.exec( ) ) )
249 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
250 if( !( _LoadPlugins( fname ) ) )
251 QMessageBox::critical(
253 tr( "Ignoring plugin" ),
258 // -------------------------------------------------------------------------
260 _triggered_actionOpenInputImage( )
263 std::string err = this->_LoadImage( this->m_Image );
266 vtkImageData* vtk_id = this->m_Image->GetVTKImageData( );
269 this->m_MPRObjects->SetImage( vtk_id );
270 this->m_MPRObjects->ActivateInteractors( );
271 this->m_MPRObjects->ResetCameras( );
272 this->m_MPRObjects->RenderAll( );
275 QMessageBox::critical(
277 tr( "Error message" ),
278 tr( "Read image does not have a valid VTK converter." )
282 QMessageBox::critical(
284 tr( "Error reading single image" ),
289 // -------------------------------------------------------------------------
291 _triggered_actionOpenSegmentation( )
293 if( this->m_Image.IsNull( ) )
295 QMessageBox::critical(
297 tr( "Error message" ),
298 tr( "Before reading a segmentation, first load a raw image." )
305 std::string err = this->_LoadImage( this->m_Segmentation );
308 vtkImageData* vtk_id = this->m_Segmentation->GetVTKImageData( );
311 this->m_MPRObjects->AddAuxiliaryImage( vtk_id );
312 this->m_MPRObjects->RenderAll( );
315 QMessageBox::critical(
317 tr( "Error message" ),
318 tr( "Read image does not have a valid VTK converter." )
322 QMessageBox::critical(
324 tr( "Error reading single image" ),
329 // -------------------------------------------------------------------------
331 _triggered_actionOpenInputPolyData( )
335 // Get a reader from plugins
336 TPluginFilter::Pointer reader =
337 this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass );
339 if( reader.IsNotNull( ) )
342 if( reader->ExecConfigurationDialog( this ) )
344 // Execute and get error message, if any
345 QApplication::setOverrideCursor( Qt::WaitCursor );
346 this->setEnabled( false );
347 std::string err = reader->Update( );
348 QApplication::restoreOverrideCursor( );
349 this->setEnabled( true );
351 // Assign fresh mesh, if any
354 this->m_Mesh = reader->GetOutput< TPluginMesh >( 0 );
355 reader->DisconnectOutputs( );
356 err = this->_ConfigureMeshActors( );
358 QMessageBox::critical(
360 tr( "Error message" ),
365 QMessageBox::critical(
367 tr( "Error reading mesh" ),
374 QMessageBox::critical(
376 tr( "Error reading single mesh" ),
377 tr( "No suitable mesh reader found in loaded plugins." )
381 // -------------------------------------------------------------------------
383 _triggered_actionImageToImage( )
385 if( this->m_Image.IsNull( ) )
389 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
392 std::string name = action->text( ).toStdString( );
395 TPluginFilter::Pointer filter =
396 this->m_Plugins.CreateProcessObject( name );
397 bool dlg_ok = filter->ExecConfigurationDialog( NULL );
402 QApplication::setOverrideCursor( Qt::WaitCursor );
403 this->setEnabled( false );
404 filter->SetInput( 0, this->m_Image );
405 std::string err = filter->Update( );
406 QApplication::restoreOverrideCursor( );
407 this->setEnabled( true );
412 TPluginImage* result = filter->GetOutput< TPluginImage >( 0 );
413 result->DisconnectPipeline( );
414 this->m_Image = result;
415 if( this->m_Image.IsNotNull( ) )
416 this->m_MPRObjects->SetImage( this->m_Image->GetVTKImageData( ) );
419 QMessageBox::critical(
421 tr( "Error executing filter" ),
426 // -------------------------------------------------------------------------
428 _triggered_actionImageToMesh( )
430 if( this->m_Image.IsNull( ) )
434 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
437 std::string name = action->text( ).toStdString( );
440 TPluginFilter::Pointer filter =
441 this->m_Plugins.CreateProcessObject( name );
442 bool dlg_ok = filter->ExecConfigurationDialog( NULL );
447 QApplication::setOverrideCursor( Qt::WaitCursor );
448 this->setEnabled( false );
449 filter->SetInput( 0, this->m_Image );
450 std::string err = filter->Update( );
451 QApplication::restoreOverrideCursor( );
452 this->setEnabled( true );
457 TPluginMesh* result = filter->GetOutput< TPluginMesh >( 0 );
458 result->DisconnectPipeline( );
459 this->m_Mesh = result;
460 err = this->_ConfigureMeshActors( );
462 QMessageBox::critical(
464 tr( "Error message" ),
469 QMessageBox::critical(
471 tr( "Error executing filter" ),