2 #include "ui_ImageMPR.h"
4 #include <vtkProperty.h>
5 #include <vtkRenderWindow.h>
11 # define PLUGIN_EXT "dll"
12 # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
14 # define PLUGIN_EXT "so"
15 # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
18 // -------------------------------------------------------------------------
19 ImageMPR::ImageMPR( QWidget* parent )
20 : QMainWindow( parent ),
21 m_UI( new Ui::ImageMPR ),
24 this->m_UI->setupUi( this );
26 // Create and associate renderers
27 this->m_MPR = new TMPR(
28 this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
29 this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
30 this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
31 this->m_UI->m_3DVTK->GetRenderWindow( )
36 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
37 this, SLOT( _triggered_actionOpenPlugins( ) )
40 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
41 this, SLOT( _triggered_actionOpenInputImage( ) )
44 this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
45 this, SLOT( _triggered_actionOpenInputPolyData( ) )
48 // Start: load all disponible plugins
49 this->_triggered_actionOpenPlugins( );
52 // -------------------------------------------------------------------------
56 // Close all connections
57 this->m_Plugins.UnloadAll( );
64 // -------------------------------------------------------------------------
66 _triggered_actionOpenPlugins( )
68 // Show dialog and check if it was accepted
69 QFileDialog dialog( this );
70 dialog.setFileMode( QFileDialog::ExistingFile );
71 dialog.setDirectory( "." );
72 dialog.setNameFilter( tr( PLUGIN_REGEX ) );
73 dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
74 if( !( dialog.exec( ) ) )
77 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
78 this->m_Plugins.UnloadAll( );
79 if( !( this->m_Plugins.Load( fname ) ) )
81 QMessageBox::critical(
83 tr( "Ignoring plugin" ),
86 this->m_Plugins.UnloadAll( );
91 this->m_BaseClasses[ "ImageReader" ] =
92 "cpPlugins::Plugins::ImageReader";
93 this->m_BaseClasses[ "PolyDataReader" ] =
94 "cpPlugins::Plugins::PolyDataReader";
97 // -------------------------------------------------------------------------
99 _triggered_actionOpenInputImage( )
101 // Show dialog and check if it was accepted
102 QFileDialog dialog( this );
103 dialog.setFileMode( QFileDialog::ExistingFiles );
104 dialog.setDirectory( tr( "." ) );
105 dialog.setNameFilter(
106 tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
108 dialog.setDefaultSuffix( tr( "mhd" ) );
109 if( !( dialog.exec( ) ) )
112 this->m_InputImage = NULL;
114 // Get a reader from plugins
115 TPlugin::Pointer reader =
116 this->m_Plugins.CreateProcessObject(
117 this->m_BaseClasses[ "ImageReader" ]
121 TParameters reader_params = reader->GetDefaultParameters( );
124 QStringList q_fnames = dialog.selectedFiles( );
125 QStringList::const_iterator qIt = q_fnames.begin( );
126 for( ; qIt != q_fnames.end( ); ++qIt )
127 reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
130 reader_params.SetValueAsString( "PixelType", "short" );
131 reader_params.SetValueAsUint( "ImageDimension", 3 );
132 reader_params.SetValueAsUint( "IsColorImage", 0 );
133 reader->SetParameters( reader_params );
135 // Execute and get error message, if any
136 std::string err = reader->Update( );
138 // Assign fresh image, if any
142 dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) );
143 reader->DisconnectOutputs( );
144 if( this->m_InputImage.IsNotNull( ) )
145 this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
148 QMessageBox::critical(
150 tr( "Error reading single image" ),
155 // -------------------------------------------------------------------------
157 _triggered_actionOpenInputPolyData( )
159 // Show dialog and check if it was accepted
160 QFileDialog dialog( this );
161 dialog.setFileMode( QFileDialog::ExistingFile );
162 dialog.setDirectory( "." );
163 dialog.setNameFilter( tr( "VTK file (*.vtk);;All files (*)" ) );
164 dialog.setDefaultSuffix( tr( "vtk" ) );
165 if( !( dialog.exec( ) ) )
168 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
170 this->m_InputPolyData = NULL;
172 // Get a reader from plugins
173 TPlugin::Pointer reader =
174 this->m_Plugins.CreateProcessObject(
175 this->m_BaseClasses[ "PolyDataReader" ]
179 TParameters reader_params = reader->GetDefaultParameters( );
180 reader_params.SetValueAsString( "FileName", fname );
181 reader->SetParameters( reader_params );
183 // Execute and get error message, if any
184 std::string err = reader->Update( );
186 // Assign fresh image, if any
189 this->m_InputPolyData =
190 dynamic_cast< TPluginPolyData* >( reader->GetOutput( 0 ) );
191 reader->DisconnectOutputs( );
192 if( this->m_InputPolyData.IsNotNull( ) )
194 this->m_InputPolyData->GetActor( )->GetProperty( )->SetColor( 1, 0, 1 );
195 this->m_MPR->Add3DActor( this->m_InputPolyData->GetActor( ) );
200 QMessageBox::critical(
202 tr( "Error reading polydata" ),