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 ),
26 this->m_UI->setupUi( this );
28 // Create and associate renderers
29 this->m_MPR = new TMPR(
30 this->m_UI->m_XPlaneVTK->GetRenderWindow( ),
31 this->m_UI->m_YPlaneVTK->GetRenderWindow( ),
32 this->m_UI->m_ZPlaneVTK->GetRenderWindow( ),
33 this->m_UI->m_3DVTK->GetRenderWindow( )
38 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
39 this, SLOT( _triggered_actionOpenPlugins( ) )
42 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
43 this, SLOT( _triggered_actionOpenInputImage( ) )
46 this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ),
47 this, SLOT( _triggered_actionOpenInputPolyData( ) )
50 // Start: load all disponible plugins
52 std::string( PLUGIN_PREFIX ) +
53 std::string( "cpPlugins." ) +
54 std::string( PLUGIN_EXT )
58 // -------------------------------------------------------------------------
62 // Close all connections
63 this->m_Plugins.UnloadAll( );
70 // -------------------------------------------------------------------------
72 _LoadPlugins( const std::string& filename )
74 this->m_Plugins.UnloadAll( );
75 if( !( this->m_Plugins.Load( filename ) ) )
77 this->m_Plugins.UnloadAll( );
81 this->m_BaseClasses[ "ImageReader" ] = "cpPlugins::ImageReader";
82 this->m_BaseClasses[ "MeshReader" ] = "cpPlugins::MeshReader";
86 // -------------------------------------------------------------------------
88 _triggered_actionOpenPlugins( )
90 // Show dialog and check if it was accepted
91 QFileDialog dialog( this );
92 dialog.setFileMode( QFileDialog::ExistingFile );
93 dialog.setDirectory( "." );
94 dialog.setNameFilter( tr( PLUGIN_REGEX ) );
95 dialog.setDefaultSuffix( tr( PLUGIN_EXT ) );
96 if( !( dialog.exec( ) ) )
99 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
100 if( !( _LoadPlugins( fname ) ) )
101 QMessageBox::critical(
103 tr( "Ignoring plugin" ),
108 // -------------------------------------------------------------------------
110 _triggered_actionOpenInputImage( )
112 // Show dialog and check if it was accepted
113 QFileDialog dialog( this );
114 dialog.setFileMode( QFileDialog::ExistingFiles );
115 dialog.setDirectory( tr( "." ) );
116 dialog.setNameFilter(
117 tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
119 dialog.setDefaultSuffix( tr( "mhd" ) );
120 if( !( dialog.exec( ) ) )
123 this->m_InputImage = NULL;
125 // Get a reader from plugins
126 TPluginFilter::Pointer reader =
127 this->m_Plugins.CreateProcessObject(
128 this->m_BaseClasses[ "ImageReader" ]
132 TParameters reader_params = reader->GetDefaultParameters( );
135 QStringList q_fnames = dialog.selectedFiles( );
136 QStringList::const_iterator qIt = q_fnames.begin( );
137 for( ; qIt != q_fnames.end( ); ++qIt )
138 reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
139 reader->SetParameters( reader_params );
141 // Execute and get error message, if any
142 std::string err = reader->Update( );
144 // Assign fresh image, if any
148 dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) );
149 reader->DisconnectOutputs( );
150 if( this->m_InputImage.IsNotNull( ) )
151 this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) );
154 QMessageBox::critical(
156 tr( "Error reading single image" ),
161 // -------------------------------------------------------------------------
163 _triggered_actionOpenInputPolyData( )
165 // Show dialog and check if it was accepted
166 QFileDialog dialog( this );
167 dialog.setFileMode( QFileDialog::ExistingFile );
168 dialog.setDirectory( "." );
169 dialog.setNameFilter( tr( "VTK file (*.vtk);;All files (*)" ) );
170 dialog.setDefaultSuffix( tr( "vtk" ) );
171 if( !( dialog.exec( ) ) )
174 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
176 this->m_InputMesh = NULL;
178 // Get a reader from plugins
179 TPluginFilter::Pointer reader =
180 this->m_Plugins.CreateProcessObject(
181 this->m_BaseClasses[ "MeshReader" ]
185 TParameters reader_params = reader->GetDefaultParameters( );
186 reader_params.SetValueAsString( "FileName", fname );
187 reader->SetParameters( reader_params );
189 // Execute and get error message, if any
190 std::string err = reader->Update( );
192 // Assign fresh image, if any
196 dynamic_cast< TPluginMesh* >( reader->GetOutput( 0 ) );
197 reader->DisconnectOutputs( );
198 if( this->m_InputMesh.IsNotNull( ) )
200 this->m_InputMeshMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
201 this->m_InputMeshMapper->SetInputData( this->m_InputMesh->GetVTKPolyData( ) );
202 this->m_InputMeshActor = vtkSmartPointer< vtkActor >::New( );
203 this->m_InputMeshActor->SetMapper( this->m_InputMeshMapper );
204 this->m_MPR->Add3DActor( this->m_InputMeshActor );
209 QMessageBox::critical(
211 tr( "Error reading polydata" ),