2 #include "ui_ImageMPR.h"
4 #include <vtkRenderWindow.h>
14 #include <vtkAnnotatedCubeActor.h>
15 #include <vtkAxesActor.h>
16 #include <vtkPropAssembly.h>
17 #include <vtkProperty.h>
19 #include <cpPlugins/Interface/Image.h>
21 // -------------------------------------------------------------------------
22 #define IDMS_QT_ACTION( name ) \
24 this->m_UI->action##name, SIGNAL( triggered( ) ), \
25 this, SLOT( _triggered_action##name( ) ) \
29 // -------------------------------------------------------------------------
30 ImageMPR::ImageMPR( QWidget* parent )
31 : QMainWindow( parent ),
32 m_UI( new Ui::ImageMPR ),
35 this->m_UI->setupUi( this );
37 // Create and associate renderers
38 this->m_3DRenderer = vtkSmartPointer< vtkRenderer >::New( );
39 this->m_XPlaneRenderer = vtkSmartPointer< vtkRenderer >::New( );
40 this->m_YPlaneRenderer = vtkSmartPointer< vtkRenderer >::New( );
41 this->m_ZPlaneRenderer = vtkSmartPointer< vtkRenderer >::New( );
42 this->m_3DRenderer->SetBackground( 0.2, 0.2, 0.2 );
43 this->m_XPlaneRenderer->SetBackground( 0.1, 0.3, 0.8 );
44 this->m_YPlaneRenderer->SetBackground( 0.1, 0.3, 0.8 );
45 this->m_ZPlaneRenderer->SetBackground( 0.1, 0.3, 0.8 );
46 this->m_UI->m_3DVTK->GetRenderWindow( )->
47 AddRenderer( this->m_3DRenderer );
48 this->m_UI->m_XPlaneVTK->GetRenderWindow( )->
49 AddRenderer( this->m_XPlaneRenderer );
50 this->m_UI->m_YPlaneVTK->GetRenderWindow( )->
51 AddRenderer( this->m_YPlaneRenderer );
52 this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->
53 AddRenderer( this->m_ZPlaneRenderer );
55 // Configure MPR actors
56 this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( );
58 // Prepare interaction
59 this->m_XStyle = vtkSmartPointer< TStyle >::New( );
60 this->m_YStyle = vtkSmartPointer< TStyle >::New( );
61 this->m_ZStyle = vtkSmartPointer< TStyle >::New( );
63 Configure( this->m_MPRActors->GetSliceActors( 0 ), this->m_MPRActors );
65 Configure( this->m_MPRActors->GetSliceActors( 1 ), this->m_MPRActors );
67 Configure( this->m_MPRActors->GetSliceActors( 2 ), this->m_MPRActors );
69 SetInteractor( this->m_UI->m_XPlaneVTK->GetInteractor( ), 0 );
71 SetInteractor( this->m_UI->m_YPlaneVTK->GetInteractor( ), 1 );
73 SetInteractor( this->m_UI->m_ZPlaneVTK->GetInteractor( ), 2 );
74 this->m_XStyle->SetModeToNavigation( );
75 this->m_YStyle->SetModeToNavigation( );
76 this->m_ZStyle->SetModeToNavigation( );
78 this->m_XStyle->AssociateInteractor(
79 this->m_UI->m_YPlaneVTK->GetInteractor( )
81 this->m_XStyle->AssociateInteractor(
82 this->m_UI->m_ZPlaneVTK->GetInteractor( )
84 this->m_XStyle->AssociateInteractor(
85 this->m_UI->m_3DVTK->GetInteractor( )
87 this->m_YStyle->AssociateInteractor(
88 this->m_UI->m_XPlaneVTK->GetInteractor( )
90 this->m_YStyle->AssociateInteractor(
91 this->m_UI->m_ZPlaneVTK->GetInteractor( )
93 this->m_YStyle->AssociateInteractor(
94 this->m_UI->m_3DVTK->GetInteractor( )
96 this->m_ZStyle->AssociateInteractor(
97 this->m_UI->m_XPlaneVTK->GetInteractor( )
99 this->m_ZStyle->AssociateInteractor(
100 this->m_UI->m_YPlaneVTK->GetInteractor( )
102 this->m_ZStyle->AssociateInteractor(
103 this->m_UI->m_3DVTK->GetInteractor( )
107 this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ),
108 this, SLOT( _triggered_actionOpenPlugins( ) )
111 this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ),
112 this, SLOT( _triggered_actionOpenInputImage( ) )
115 // Start: load all disponible plugins
116 this->_triggered_actionOpenPlugins( );
119 // -------------------------------------------------------------------------
123 // Close all connections
124 this->m_Plugins.UnloadAll( );
128 if( this->m_InputImage != NULL ) delete this->m_InputImage;
131 // -------------------------------------------------------------------------
133 _triggered_actionOpenPlugins( )
135 // Show dialog and check if it was accepted
136 QFileDialog dialog( this );
137 dialog.setFileMode( QFileDialog::ExistingFile );
138 dialog.setDirectory( "." );
139 dialog.setNameFilter(
140 tr( "Plugins file (*.so);;All files (*)" )
142 dialog.setDefaultSuffix( tr( "so" ) );
143 if( !( dialog.exec( ) ) )
146 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
147 this->m_Plugins.UnloadAll( );
148 if( !( this->m_Plugins.Load( fname ) ) )
150 QMessageBox::critical(
152 tr( "Ignoring plugin" ),
155 this->m_Plugins.UnloadAll( );
160 this->m_BaseClasses[ "ImageReader" ] =
161 "cpPlugins::Plugins::ImageReader";
162 this->m_BaseClasses[ "ImageSeriesReader" ] =
163 "cpPlugins::Plugins::ImageSeriesReader";
166 // -------------------------------------------------------------------------
168 _triggered_actionOpenInputImage( )
170 // Show dialog and check if it was accepted
171 QFileDialog dialog( this );
172 dialog.setFileMode( QFileDialog::ExistingFiles );
173 dialog.setDirectory( tr( "." ) );
174 dialog.setNameFilter(
175 tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" )
177 dialog.setDefaultSuffix( tr( "mhd" ) );
178 if( !( dialog.exec( ) ) )
181 if( this->m_InputImage != NULL )
182 delete this->m_InputImage;
183 this->m_InputImage = NULL;
184 unsigned int nFiles = dialog.selectedFiles( ).size( );
187 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
190 dynamic_cast< TPlugin* >(
191 this->m_Plugins.CreateObject( this->m_BaseClasses[ "ImageReader" ] )
194 TParameters reader_params = reader->GetDefaultParameters( );
195 reader_params[ "FileName" ].second = fname;
196 reader_params[ "PixelType" ].second = "short";
197 reader_params[ "ImageDimension" ].second = "3";
198 reader_params[ "IsColorImage" ].second = "0";
199 reader->SetParameters( reader_params );
200 std::string err = reader->Update( );
205 dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) );
206 reader->DisconnectOutputs( );
209 QMessageBox::critical(
211 tr( "Error reading single image" ),
216 else if( nFiles > 1 )
219 if( this->m_ImageSeriesReaderClassName == "" )
221 QMessageBox::critical(
223 tr( "No plugin to read an image series found!" ),
224 tr( "No plugin to read an image series found!" )
229 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
230 this->m_LastOpenedFile = fname;
236 if( this->m_InputImage != NULL )
238 this->m_MPRActors->SetInputData( this->m_InputImage->GetVTKImageData( ) );
239 this->m_MPRActors->PushDataInto(
240 this->m_XPlaneRenderer,
241 this->m_YPlaneRenderer,
242 this->m_ZPlaneRenderer,
247 this->m_3DRenderer->ResetCamera( );
248 this->m_XPlaneRenderer->ResetCamera( );
249 this->m_YPlaneRenderer->ResetCamera( );
250 this->m_ZPlaneRenderer->ResetCamera( );
253 this->m_UI->m_3DVTK->GetRenderWindow( )->Render( );
254 this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( );
255 this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( );
256 this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( );