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( "" ),
28 this->m_UI->setupUi( this );
30 // Create and associate renderers
31 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
32 this->m_MPRObjects->SetRenderWindows(
33 this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
34 this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
35 this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
36 this->m_UI->m_3DVTK->GetRenderWindow( )
41 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
42 this, SLOT( _triggered_actionOpenPlugins( ) )
45 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
46 this, SLOT( _triggered_actionOpenInputImage( ) )
49 this->m_UI->actionOpenSegmentation, SIGNAL( triggered( ) ),
50 this, SLOT( _triggered_actionOpenSegmentation( ) )
53 this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
54 this, SLOT( _triggered_actionOpenInputPolyData( ) )
57 // Start: load all disponible plugins
59 std::string( PLUGIN_PREFIX ) +
60 std::string( "cpPluginsIO." ) +
61 std::string( PLUGIN_EXT )
65 // -------------------------------------------------------------------------
69 // Close all connections
70 this->m_Plugins.UnloadAll( );
76 // -------------------------------------------------------------------------
78 _LoadPlugins( const std::string& filename )
80 QApplication::setOverrideCursor( Qt::WaitCursor );
81 this->setEnabled( false );
83 this->m_ImageReaderClass = "";
84 this->m_ImageWriterClass = "";
85 this->m_MeshReaderClass = "";
86 this->m_MeshWriterClass = "";
87 this->m_UI->MenuImageToImage->clear( );
88 this->m_UI->MenuImageToMesh->clear( );
90 if( !( this->m_Plugins.Load( filename ) ) )
93 typedef TPluginsInterface::TClasses _TClasses;
94 _TClasses::const_iterator cIt = this->m_Plugins.GetClasses( ).begin( );
95 for( ; cIt != this->m_Plugins.GetClasses( ).end( ); ++cIt )
97 TPluginFilter::Pointer o =
98 this->m_Plugins.CreateProcessObject( cIt->first );
99 std::string name = o->GetClassName( );
100 std::string category = o->GetClassCategory( );
101 if( category == "ImageReader" )
102 this->m_ImageReaderClass = name;
103 else if( category == "ImageWriter" )
104 this->m_ImageWriterClass = name;
105 else if( category == "MeshReader" )
106 this->m_MeshReaderClass = name;
107 else if( category == "MeshWriter" )
108 this->m_MeshWriterClass = name;
109 else if( category == "ImageToImageFilter" )
112 this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) );
114 action, SIGNAL( triggered( ) ),
115 this, SLOT( _triggered_actionImageToImage( ) )
118 else if( category == "ImageToMeshFilter" )
121 this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) );
123 action, SIGNAL( triggered( ) ),
124 this, SLOT( _triggered_actionImageToMesh( ) )
130 QApplication::restoreOverrideCursor( );
131 this->setEnabled( true );
136 // -------------------------------------------------------------------------
137 std::string ImageMPR::
138 _LoadImage( TPluginImage::Pointer& image, const QStringList& names )
141 QApplication::setOverrideCursor( Qt::WaitCursor );
142 this->setEnabled( false );
144 std::string ret = "";
147 // Get a reader from loaded plugins
148 TPluginFilter::Pointer reader =
149 this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass );
150 if( reader.IsNotNull( ) )
153 TParameters params = reader->GetDefaultParameters( );
154 QStringList::const_iterator qIt = names.begin( );
155 for( ; qIt != names.end( ); ++qIt )
156 params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
157 params.SetValueAsBool( "VectorType", false );
158 reader->SetParameters( params );
160 // Execute and get error message, if any
161 ret = reader->Update( );
163 // Assign fresh image, if any
166 image = reader->GetOutput< TPluginImage >( 0 );
167 reader->DisconnectOutputs( );
172 ret = "No suitable reader object found in loaded plugins.";
175 QApplication::restoreOverrideCursor( );
176 this->setEnabled( true );
180 // -------------------------------------------------------------------------
182 _triggered_actionOpenPlugins( )
184 // Show dialog and check if it was accepted
185 QFileDialog dialog( this );
186 dialog.setFileMode( QFileDialog::ExistingFile );
187 dialog.setDirectory( "." );
188 dialog.setNameFilter( tr( PLUGIN_REGEX ) );
189 dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
190 if( !( dialog.exec( ) ) )
193 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
194 if( !( _LoadPlugins( fname ) ) )
195 QMessageBox::critical(
197 tr( "Ignoring plugin" ),
202 // -------------------------------------------------------------------------
204 _triggered_actionOpenInputImage( )
206 // Show dialog and check if it was accepted
207 QFileDialog dialog( this );
208 dialog.setFileMode( QFileDialog::ExistingFiles );
209 dialog.setDirectory( tr( "." ) );
210 dialog.setNameFilter(
211 tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
213 dialog.setDefaultSuffix( tr( "mhd" ) );
214 if( !( dialog.exec( ) ) )
219 this->_LoadImage( this->m_InputImage, dialog.selectedFiles( ) );
222 vtkImageData* vtk_id = this->m_InputImage->GetVTKImageData( );
225 this->m_MPRObjects->SetImage( vtk_id );
226 this->m_MPRObjects->ActivateInteractors( );
227 this->m_MPRObjects->ResetCameras( );
228 this->m_MPRObjects->RenderAll( );
231 QMessageBox::critical(
233 tr( "Error message" ),
234 tr( "Read image does not have a valid VTK converter." )
238 QMessageBox::critical(
240 tr( "Error reading single image" ),
245 // -------------------------------------------------------------------------
247 _triggered_actionOpenSegmentation( )
249 if( this->m_InputImage.IsNull( ) )
251 QMessageBox::critical(
253 tr( "Error message" ),
254 tr( "Before reading a segmentation, first load a raw image." )
260 // Show dialog and check if it was accepted
261 QFileDialog dialog( this );
262 dialog.setFileMode( QFileDialog::ExistingFiles );
263 dialog.setDirectory( tr( "." ) );
264 dialog.setNameFilter(
265 tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
267 dialog.setDefaultSuffix( tr( "mhd" ) );
268 if( !( dialog.exec( ) ) )
273 this->_LoadImage( this->m_InputSegmentation, dialog.selectedFiles( ) );
276 vtkImageData* vtk_id = this->m_InputSegmentation->GetVTKImageData( );
279 this->m_MPRObjects->AddAuxiliaryImage( vtk_id );
280 this->m_MPRObjects->RenderAll( );
283 QMessageBox::critical(
285 tr( "Error message" ),
286 tr( "Read image does not have a valid VTK converter." )
290 QMessageBox::critical(
292 tr( "Error reading single image" ),
297 // -------------------------------------------------------------------------
299 _triggered_actionOpenInputPolyData( )
301 // Show dialog and check if it was accepted
302 QFileDialog dialog( this );
303 dialog.setFileMode( QFileDialog::ExistingFile );
304 dialog.setDirectory( tr( "." ) );
305 dialog.setNameFilter(
306 tr( "Mesh files (*.vtk *.obj);;All files (*)" )
308 dialog.setDefaultSuffix( tr( "vtk" ) );
309 if( !( dialog.exec( ) ) )
312 this->m_InputMesh = NULL;
314 // Get a reader from plugins
315 TPluginFilter::Pointer reader =
316 this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass );
319 TParameters reader_params = reader->GetDefaultParameters( );
320 QStringList q_fnames = dialog.selectedFiles( );
321 QStringList::const_iterator qIt = q_fnames.begin( );
322 for( ; qIt != q_fnames.end( ); ++qIt )
323 reader_params.SetValueAsString( "FileName", qIt->toStdString( ) );
324 reader->SetParameters( reader_params );
326 // Execute and get error message, if any
327 QApplication::setOverrideCursor( Qt::WaitCursor );
328 this->setEnabled( false );
329 std::string err = reader->Update( );
330 QApplication::restoreOverrideCursor( );
331 this->setEnabled( true );
334 // Assign fresh image, if any
337 this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 );
338 reader->DisconnectOutputs( );
339 if( this->m_InputMesh.IsNotNull( ) )
341 vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( );
342 if( vtk_actor != NULL )
344 this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor );
345 this->m_MPRObjects->Render( 4 );
348 QMessageBox::critical(
350 tr( "Error message" ),
351 tr( "Read mesh does not have a valid vtkActor." )
357 QMessageBox::critical(
359 tr( "Error reading mesh" ),
364 // -------------------------------------------------------------------------
366 _triggered_actionImageToImage( )
368 if( this->m_InputImage.IsNull( ) )
372 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
375 std::string name = action->text( ).toStdString( );
378 TPluginFilter::Pointer filter =
379 this->m_Plugins.CreateProcessObject( name );
380 bool dlg_ok = filter->ExecConfigurationDialog( NULL );
385 QApplication::setOverrideCursor( Qt::WaitCursor );
386 this->setEnabled( false );
387 filter->SetInput( 0, this->m_InputImage );
388 std::string err = filter->Update( );
389 QApplication::restoreOverrideCursor( );
390 this->setEnabled( true );
395 TPluginImage* result = filter->GetOutput< TPluginImage >( 0 );
396 result->DisconnectPipeline( );
397 this->m_InputImage = result;
398 if( this->m_InputImage.IsNotNull( ) )
399 this->m_MPRObjects->SetImage( this->m_InputImage->GetVTKImageData( ) );
402 QMessageBox::critical(
404 tr( "Error executing filter" ),
409 // -------------------------------------------------------------------------
411 _triggered_actionImageToMesh( )
413 if( this->m_InputImage.IsNull( ) )
417 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
420 std::string name = action->text( ).toStdString( );
423 TPluginFilter::Pointer filter =
424 this->m_Plugins.CreateProcessObject( name );
425 bool dlg_ok = filter->ExecConfigurationDialog( NULL );
430 QApplication::setOverrideCursor( Qt::WaitCursor );
431 this->setEnabled( false );
432 filter->SetInput( 0, this->m_InputImage );
433 std::string err = filter->Update( );
434 QApplication::restoreOverrideCursor( );
435 this->setEnabled( true );
440 TPluginMesh* result = filter->GetOutput< TPluginMesh >( 0 );
441 result->DisconnectPipeline( );
442 this->m_InputMesh = result;
443 if( this->m_InputMesh.IsNotNull( ) )
444 this->m_MPRObjects->Get3DRenderer( )->AddActor(
445 this->m_InputMesh->GetVTKActor( )
449 QMessageBox::critical(
451 tr( "Error executing filter" ),