1 #include <cpExtensions/QT/MPR3DWidget.h>
3 #ifdef cpExtensions_QT4
5 #include <cpExtensions/Visualization/ImageOutlineActor.h>
6 #include <cpExtensions/Visualization/MeshActor.h>
7 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
9 #include <vtkImageData.h>
11 #include <vtkPolyData.h>
14 #include <cpExtensions/Visualization/MPR3DActors.h>
15 #include <cpExtensions/Visualization/LUTImageActor.h>
20 // -------------------------------------------------------------------------
21 cpExtensions::QT::MPR3DWidget::
22 MPR3DWidget( QWidget* parent, Qt::WindowFlags f )
23 : Superclass( parent, f ),
28 vtkSmartPointer< cpExtensions::Visualization::MPR3DActors >::New( );
32 // -------------------------------------------------------------------------
33 cpExtensions::QT::MPR3DWidget::
36 for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
38 this->m_Actors.clear( );
41 // -------------------------------------------------------------------------
42 void cpExtensions::QT::MPR3DWidget::
45 this->RemoveViewProps( );
46 this->m_ImageName = "";
49 // -------------------------------------------------------------------------
50 void cpExtensions::QT::MPR3DWidget::
51 SetImage( vtkImageData* image, const std::string& name )
55 if( this->m_ImageName != "" )
57 this->m_ImageName = name;
59 for( unsigned int o = 0; o < 3; ++o )
61 this->m_WLActors[ o ] = vtkSmartPointer< TWLActor >::New( );
62 this->m_WLActors[ o ]->SetImage( image );
63 this->m_WLActors[ o ]->SetOrientation( o );
65 this->m_OLActors[ o ] = vtkSmartPointer< TOLActor >::New( );
66 this->m_OLActors[ o ]->SetBounds(
67 o, image->GetBounds( )[ o << 1 ], image->GetBounds( )
70 this->AddViewProp( this->m_WLActors[ o ], this->m_ImageName );
71 this->AddAuxViewProp( this->m_OLActors[ o ], this->m_ImageName );
77 // -------------------------------------------------------------------------
78 void cpExtensions::QT::MPR3DWidget::
79 Add( vtkDataSet* data, const std::string& name )
81 auto image = dynamic_cast< vtkImageData* >( data );
82 auto pdata = dynamic_cast< vtkPolyData* >( data );
86 if( this->m_ImageName != "" )
90 this->SetImage( image, name );
93 else if( pdata != NULL )
95 TActor* actor = new TActor( );
96 actor->SetMesh( pdata );
97 this->m_Actors.push_back( actor );
98 this->AddViewProp( actor->GetActor( ), name );
100 if( this->m_ImageName == "" )
101 this->ResetCamera( );
106 // -------------------------------------------------------------------------
107 cpExtensions::QT::MPR3DWidget::
108 TWLActor* cpExtensions::QT::MPR3DWidget::
109 GetImageActor( int o )
111 return( this->m_WLActors[ o % 3 ] );
114 // -------------------------------------------------------------------------
115 const cpExtensions::QT::MPR3DWidget::
116 TWLActor* cpExtensions::QT::MPR3DWidget::
117 GetImageActor( int o ) const
119 return( this->m_WLActors[ o % 3 ] );
122 // -------------------------------------------------------------------------
123 void cpExtensions::QT::MPR3DWidget::
124 SetSliceNumber( int orientation, int slice )
126 int o = orientation % 3;
127 this->m_WLActors[ o ]->SetSliceNumber( slice );
128 this->m_OLActors[ o ]->SetBounds(
130 this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
131 this->m_WLActors[ o ]->GetImage( )->GetBounds( )
136 // -------------------------------------------------------------------------
137 void cpExtensions::QT::MPR3DWidget::
138 SetSlicesNumbers( int x, int y, int z )
140 int s[] = { x, y, z };
141 for( int o = 0; o < 3; ++o )
143 this->m_WLActors[ o ]->SetSliceNumber( s[ o ] );
144 this->m_OLActors[ o ]->SetBounds(
146 this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
147 this->m_WLActors[ o ]->GetImage( )->GetBounds( )
154 // -------------------------------------------------------------------------
156 void cpExtensions::QT::MPR3DWidget::
157 SetImage( vtkImageData* image, const std::string& name )
159 if( this->m_ImageName != "" )
161 // TODO: Clear visualization
165 this->m_Actors->SetImage( image );
166 this->m_ImageName = name;
168 vtkSmartPointer< vtkPropCollection > props =
169 vtkSmartPointer< vtkPropCollection >::New( );
170 props->AddItem( this->m_Actors->GetWindowLevelImageActor( 0 ) );
171 props->AddItem( this->m_Actors->GetWindowLevelImageActor( 1 ) );
172 props->AddItem( this->m_Actors->GetWindowLevelImageActor( 2 ) );
173 this->AddViewProps( props, name );
174 this->AddAuxViewProp( this->m_Actors->GetImageOutlineActor( 0 ), name );
175 this->AddAuxViewProp( this->m_Actors->GetImageOutlineActor( 1 ), name );
176 this->AddAuxViewProp( this->m_Actors->GetImageOutlineActor( 2 ), name );
177 this->ResetCamera( );
181 // -------------------------------------------------------------------------
182 void cpExtensions::QT::MPR3DWidget::
183 SetSliceNumber( int orientation, int slice )
185 this->m_Actors->SetSliceNumber( orientation, slice );
189 // -------------------------------------------------------------------------
190 void cpExtensions::QT::MPR3DWidget::
191 SetSlicesNumbers( int x, int y, int z )
193 this->m_Actors->SetSliceNumber( 0, x );
194 this->m_Actors->SetSliceNumber( 1, y );
195 this->m_Actors->SetSliceNumber( 2, z );
199 // -------------------------------------------------------------------------
200 void cpExtensions::QT::MPR3DWidget::
201 SetScalarRange( double r[ 2 ] )
203 this->m_Actors->SetScalarRange( r );
207 // -------------------------------------------------------------------------
208 void cpExtensions::QT::MPR3DWidget::
209 SetWindowLevel( double wl[ 2 ] )
211 this->m_Actors->SetWindowLevel( wl );
215 // -------------------------------------------------------------------------
216 void cpExtensions::QT::MPR3DWidget::
217 SetImageOpacity( double o )
219 this->m_Actors->SetImageOpacity( o );
223 // -------------------------------------------------------------------------
224 void cpExtensions::QT::MPR3DWidget::
225 SetImageInterpolation( unsigned char i )
227 this->m_Actors->SetImageInterpolation( i );
232 #endif // cpExtensions_QT4