2 #include "ui_ImageMPR.h"
4 #include <cpPlugins/Interface/ParametersQtDialog.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderWindow.h>
10 #include <QMessageBox>
13 # define PLUGIN_PREFIX ""
14 # define PLUGIN_EXT "dll"
15 # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
17 # define PLUGIN_PREFIX "lib"
18 # define PLUGIN_EXT "so"
19 # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
22 // -------------------------------------------------------------------------
23 ImageMPR::ImageMPR( QWidget* parent )
24 : QMainWindow( parent ),
25 m_UI( new Ui::ImageMPR ),
26 m_ImageReaderClass( "" ),
27 m_ImageWriterClass( "" ),
30 this->m_UI->setupUi( this );
32 // Create and associate renderers
33 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
34 this->m_MPRObjects->SetRenderWindows(
35 this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
36 this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
37 this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
38 this->m_UI->m_3DVTK->GetRenderWindow( )
43 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
44 this, SLOT( _triggered_actionOpenPlugins( ) )
47 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
48 this, SLOT( _triggered_actionOpenInputImage( ) )
51 this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
52 this, SLOT( _triggered_actionOpenInputPolyData( ) )
55 // Start: load all disponible plugins
57 std::string( PLUGIN_PREFIX ) +
58 std::string( "cpPlugins." ) +
59 std::string( PLUGIN_EXT )
63 // -------------------------------------------------------------------------
67 // Close all connections
68 this->m_Plugins.UnloadAll( );
74 // -------------------------------------------------------------------------
76 _LoadPlugins( const std::string& filename )
78 QApplication::setOverrideCursor( Qt::WaitCursor );
79 this->setEnabled( false );
81 this->m_ImageReaderClass = "";
82 this->m_ImageWriterClass = "";
83 this->m_MeshReaderClass = "";
84 this->m_MeshWriterClass = "";
85 this->m_ImageToImageFilters.clear( );
86 this->m_ImageToMeshFilters.clear( );
88 this->m_Plugins.UnloadAll( );
89 if( !( this->m_Plugins.Load( filename ) ) )
91 this->m_Plugins.UnloadAll( );
96 typedef TPluginsInterface::TClasses _TClasses;
97 _TClasses::const_iterator cIt = this->m_Plugins.GetClasses( ).begin( );
98 for( ; cIt != this->m_Plugins.GetClasses( ).end( ); ++cIt )
100 TPluginFilter::Pointer o =
101 this->m_Plugins.CreateProcessObject( cIt->first );
102 std::string name = o->GetClassName( );
103 std::string category = o->GetClassCategory( );
104 if( category == "ImageReader" )
105 this->m_ImageReaderClass = name;
106 else if( category == "ImageWriter" )
107 this->m_ImageWriterClass = name;
108 else if( category == "MeshReader" )
109 this->m_MeshReaderClass = name;
110 else if( category == "MeshWriter" )
111 this->m_MeshWriterClass = name;
112 else if( category == "ImageToImageFilter" )
114 this->m_ImageToImageFilters.insert( name );
116 this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) );
118 action, SIGNAL( triggered( ) ),
119 this, SLOT( _triggered_actionImageToImage( ) )
122 else if( category == "ImageToMeshFilter" )
124 this->m_ImageToMeshFilters.insert( name );
126 this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) );
128 action, SIGNAL( triggered( ) ),
129 this, SLOT( _triggered_actionImageToMesh( ) )
135 QApplication::restoreOverrideCursor( );
136 this->setEnabled( true );
141 // -------------------------------------------------------------------------
143 _triggered_actionOpenPlugins( )
145 // Show dialog and check if it was accepted
146 QFileDialog dialog( this );
147 dialog.setFileMode( QFileDialog::ExistingFile );
148 dialog.setDirectory( "." );
149 dialog.setNameFilter( tr( PLUGIN_REGEX ) );
150 dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
151 if( !( dialog.exec( ) ) )
154 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
155 if( !( _LoadPlugins( fname ) ) )
156 QMessageBox::critical(
158 tr( "Ignoring plugin" ),
163 // -------------------------------------------------------------------------
165 _triggered_actionOpenInputImage( )
167 // Show dialog and check if it was accepted
168 QFileDialog dialog( this );
169 dialog.setFileMode( QFileDialog::ExistingFiles );
170 dialog.setDirectory( tr( "." ) );
171 dialog.setNameFilter(
172 tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
174 dialog.setDefaultSuffix( tr( "mhd" ) );
175 if( !( dialog.exec( ) ) )
178 this->m_InputImage = NULL;
180 // Get a reader from plugins
181 TPluginFilter::Pointer reader =
182 this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass );
185 TParameters reader_params = reader->GetDefaultParameters( );
186 QStringList q_fnames = dialog.selectedFiles( );
187 QStringList::const_iterator qIt = q_fnames.begin( );
188 for( ; qIt != q_fnames.end( ); ++qIt )
189 reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
190 reader->SetParameters( reader_params );
192 // Execute and get error message, if any
193 QApplication::setOverrideCursor( Qt::WaitCursor );
194 this->setEnabled( false );
195 std::string err = reader->Update( );
196 QApplication::restoreOverrideCursor( );
197 this->setEnabled( true );
199 // Assign fresh image, if any
202 this->m_InputImage = reader->GetOutput< TPluginImage >( 0 );
203 reader->DisconnectOutputs( );
204 if( this->m_InputImage.IsNotNull( ) )
206 vtkImageData* vtk_id = this->m_InputImage->GetVTKImageData( );
209 this->m_MPRObjects->SetImage( vtk_id );
210 this->m_MPRObjects->ResetCameras( );
211 this->m_MPRObjects->RenderAll( );
214 QMessageBox::critical(
216 tr( "Error message" ),
217 tr( "Read image does not have a valid VTK converter." )
223 QMessageBox::critical(
225 tr( "Error reading single image" ),
230 // -------------------------------------------------------------------------
232 _triggered_actionOpenInputPolyData( )
234 // Show dialog and check if it was accepted
235 QFileDialog dialog( this );
236 dialog.setFileMode( QFileDialog::ExistingFile );
237 dialog.setDirectory( tr( "." ) );
238 dialog.setNameFilter(
239 tr( "Mesh files (*.vtk *.obj);;All files (*)" )
241 dialog.setDefaultSuffix( tr( "vtk" ) );
242 if( !( dialog.exec( ) ) )
245 this->m_InputMesh = NULL;
247 // Get a reader from plugins
248 TPluginFilter::Pointer reader =
249 this->m_Plugins.CreateProcessObject( this->m_MeshReaderClass );
252 TParameters reader_params = reader->GetDefaultParameters( );
253 QStringList q_fnames = dialog.selectedFiles( );
254 QStringList::const_iterator qIt = q_fnames.begin( );
255 for( ; qIt != q_fnames.end( ); ++qIt )
256 reader_params.SetValueAsString( "FileName", qIt->toStdString( ) );
257 reader->SetParameters( reader_params );
259 // Execute and get error message, if any
260 QApplication::setOverrideCursor( Qt::WaitCursor );
261 this->setEnabled( false );
262 std::string err = reader->Update( );
263 QApplication::restoreOverrideCursor( );
264 this->setEnabled( true );
267 // Assign fresh image, if any
270 this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 );
271 reader->DisconnectOutputs( );
272 if( this->m_InputMesh.IsNotNull( ) )
274 vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( );
275 if( vtk_actor != NULL )
277 this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor );
278 this->m_MPRObjects->Render( 4 );
281 QMessageBox::critical(
283 tr( "Error message" ),
284 tr( "Read mesh does not have a valid vtkActor." )
290 QMessageBox::critical(
292 tr( "Error reading mesh" ),
297 // -------------------------------------------------------------------------
299 _triggered_actionImageToImage( )
301 if( this->m_InputImage.IsNull( ) )
305 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
308 std::string name = action->text( ).toStdString( );
311 TPluginFilter::Pointer filter =
312 this->m_Plugins.CreateProcessObject( name );
313 TParameters parameters = filter->GetDefaultParameters( );
315 cpPlugins::Interface::ParametersQtDialog(
316 parameters, filter->GetClassName( )
322 QApplication::setOverrideCursor( Qt::WaitCursor );
323 this->setEnabled( false );
324 filter->SetParameters( parameters );
325 filter->SetInput( 0, this->m_InputImage );
326 std::string err = filter->Update( );
327 QApplication::restoreOverrideCursor( );
328 this->setEnabled( true );
333 TPluginImage* result = filter->GetOutput< TPluginImage >( 0 );
334 result->DisconnectPipeline( );
335 this->m_InputImage = result;
336 if( this->m_InputImage.IsNotNull( ) )
337 this->m_MPRObjects->SetImage( this->m_InputImage->GetVTKImageData( ) );
340 QMessageBox::critical(
342 tr( "Error executing filter" ),
347 // -------------------------------------------------------------------------
349 _triggered_actionImageToMesh( )
351 if( this->m_InputImage.IsNull( ) )
355 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
358 std::string name = action->text( ).toStdString( );
361 TPluginFilter::Pointer filter =
362 this->m_Plugins.CreateProcessObject( name );
363 TParameters parameters = filter->GetDefaultParameters( );
365 cpPlugins::Interface::ParametersQtDialog(
366 parameters, filter->GetClassName( )
372 QApplication::setOverrideCursor( Qt::WaitCursor );
373 this->setEnabled( false );
374 filter->SetParameters( parameters );
375 filter->SetInput( 0, this->m_InputImage );
376 std::string err = filter->Update( );
377 QApplication::restoreOverrideCursor( );
378 this->setEnabled( true );
383 TPluginMesh* result = filter->GetOutput< TPluginMesh >( 0 );
384 result->DisconnectPipeline( );
385 this->m_InputMesh = result;
386 if( this->m_InputMesh.IsNotNull( ) )
387 this->m_MPRObjects->Get3DRenderer( )->AddActor(
388 this->m_InputMesh->GetVTKActor( )
392 QMessageBox::critical(
394 tr( "Error executing filter" ),