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_MPR = new TMPR(
34 this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
35 this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
36 this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
37 this->m_UI->m_3DVTK->GetRenderWindow( )
42 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
43 this, SLOT( _triggered_actionOpenPlugins( ) )
46 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
47 this, SLOT( _triggered_actionOpenInputImage( ) )
50 this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
51 this, SLOT( _triggered_actionOpenInputPolyData( ) )
54 // Start: load all disponible plugins
56 std::string( PLUGIN_PREFIX ) +
57 std::string( "cpPlugins." ) +
58 std::string( PLUGIN_EXT )
62 // -------------------------------------------------------------------------
66 // Close all connections
67 this->m_Plugins.UnloadAll( );
74 // -------------------------------------------------------------------------
76 _LoadPlugins( const std::string& filename )
78 this->m_ImageReaderClass = "";
79 this->m_ImageWriterClass = "";
80 this->m_MeshReaderClass = "";
81 this->m_MeshWriterClass = "";
82 this->m_ImageToImageFilters.clear( );
83 this->m_ImageToMeshFilters.clear( );
85 this->m_Plugins.UnloadAll( );
86 if( !( this->m_Plugins.Load( filename ) ) )
88 this->m_Plugins.UnloadAll( );
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" )
111 this->m_ImageToImageFilters.insert( name );
113 this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) );
115 action, SIGNAL( triggered( ) ),
116 this, SLOT( _triggered_actionImageToImage( ) )
119 else if( category == "ImageToMeshFilter" )
121 this->m_ImageToMeshFilters.insert( name );
123 this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) );
125 action, SIGNAL( triggered( ) ),
126 this, SLOT( _triggered_actionImageToMesh( ) )
135 // -------------------------------------------------------------------------
137 _triggered_actionOpenPlugins( )
139 // Show dialog and check if it was accepted
140 QFileDialog dialog( this );
141 dialog.setFileMode( QFileDialog::ExistingFile );
142 dialog.setDirectory( "." );
143 dialog.setNameFilter( tr( PLUGIN_REGEX ) );
144 dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
145 if( !( dialog.exec( ) ) )
148 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
149 if( !( _LoadPlugins( fname ) ) )
150 QMessageBox::critical(
152 tr( "Ignoring plugin" ),
157 // -------------------------------------------------------------------------
159 _triggered_actionOpenInputImage( )
161 // Show dialog and check if it was accepted
162 QFileDialog dialog( this );
163 dialog.setFileMode( QFileDialog::ExistingFiles );
164 dialog.setDirectory( tr( "." ) );
165 dialog.setNameFilter(
166 tr( "Medical image files (*.mhd *.bin *.dcm *.nrri);;All files (*)" )
168 dialog.setDefaultSuffix( tr( "mhd" ) );
169 if( !( dialog.exec( ) ) )
172 this->m_InputImage = NULL;
174 // Get a reader from plugins
175 TPluginFilter::Pointer reader =
176 this->m_Plugins.CreateProcessObject( this->m_ImageReaderClass );
179 TParameters reader_params = reader->GetDefaultParameters( );
180 QStringList q_fnames = dialog.selectedFiles( );
181 QStringList::const_iterator qIt = q_fnames.begin( );
182 for( ; qIt != q_fnames.end( ); ++qIt )
183 reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
184 reader->SetParameters( reader_params );
186 // Execute and get error message, if any
187 std::string err = reader->Update( );
189 // Assign fresh image, if any
193 dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) );
194 reader->DisconnectOutputs( );
195 if( this->m_InputImage.IsNotNull( ) )
196 this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
199 QMessageBox::critical(
201 tr( "Error reading single image" ),
206 // -------------------------------------------------------------------------
208 _triggered_actionOpenInputPolyData( )
211 // Show dialog and check if it was accepted
212 QFileDialog dialog( this );
213 dialog.setFileMode( QFileDialog::ExistingFile );
214 dialog.setDirectory( "." );
215 dialog.setNameFilter( tr( "VTK file (*.vtk);;All files (*)" ) );
216 dialog.setDefaultSuffix( tr( "vtk" ) );
217 if( !( dialog.exec( ) ) )
220 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
222 this->m_InputMesh = NULL;
224 // Get a reader from plugins
225 TPluginFilter::Pointer reader =
226 this->m_Plugins.CreateProcessObject(
227 this->m_BaseClasses[ "MeshReader" ]
231 TParameters reader_params = reader->GetDefaultParameters( );
232 reader_params.SetValueAsString( "FileName", fname );
233 reader->SetParameters( reader_params );
235 // Execute and get error message, if any
236 std::string err = reader->Update( );
238 // Assign fresh image, if any
242 dynamic_cast< TPluginMesh* >( reader->GetOutput( 0 ) );
243 reader->DisconnectOutputs( );
244 if( this->m_InputMesh.IsNotNull( ) )
246 this->m_InputMeshMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
247 this->m_InputMeshMapper->SetInputData( this->m_InputMesh->GetVTKPolyData( ) );
248 this->m_InputMeshActor = vtkSmartPointer< vtkActor >::New( );
249 this->m_InputMeshActor->SetMapper( this->m_InputMeshMapper );
250 this->m_MPR->Add3DActor( this->m_InputMeshActor );
255 QMessageBox::critical(
257 tr( "Error reading polydata" ),
263 // -------------------------------------------------------------------------
265 _triggered_actionImageToImage( )
267 if( this->m_InputImage.IsNull( ) )
271 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
274 std::string name = action->text( ).toStdString( );
277 TPluginFilter::Pointer filter =
278 this->m_Plugins.CreateProcessObject( name );
279 TParameters parameters = filter->GetDefaultParameters( );
281 cpPlugins::Interface::ParametersQtDialog(
282 parameters, filter->GetClassName( )
288 filter->SetParameters( parameters );
289 filter->SetInput( 0, this->m_InputImage );
290 std::string err = filter->Update( );
295 TPluginImage* result =
296 dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
297 result->DisconnectPipeline( );
298 this->m_InputImage = result;
299 if( this->m_InputImage.IsNotNull( ) )
300 this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
303 QMessageBox::critical(
305 tr( "Error executing filter" ),
310 // -------------------------------------------------------------------------
312 _triggered_actionImageToMesh( )
314 if( this->m_InputImage.IsNull( ) )
318 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
321 std::string name = action->text( ).toStdString( );
324 TPluginFilter::Pointer filter =
325 this->m_Plugins.CreateProcessObject( name );
326 TParameters parameters = filter->GetDefaultParameters( );
328 cpPlugins::Interface::ParametersQtDialog(
329 parameters, filter->GetClassName( )
335 filter->SetParameters( parameters );
336 filter->SetInput( 0, this->m_InputImage );
337 std::string err = filter->Update( );
343 TPluginImage* result =
344 dynamic_cast< TPluginImage* >( filter->GetOutput( 0 ) );
345 result->DisconnectPipeline( );
346 this->m_InputImage = result;
347 if( this->m_InputImage.IsNotNull( ) )
348 this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
352 QMessageBox::critical(
354 tr( "Error executing filter" ),