]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/MPR3DWidget.cxx
Raster filter updated. LUT image visualization strange bug :-(
[cpPlugins.git] / lib / cpExtensions / QT / MPR3DWidget.cxx
1 #include <cpExtensions/QT/MPR3DWidget.h>
2
3 #ifdef cpExtensions_QT4
4
5 #include <cpExtensions/Visualization/ImageOutlineActor.h>
6 #include <cpExtensions/Visualization/MeshActor.h>
7 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
8
9 #include <vtkImageData.h>
10 #include <vtkPlane.h>
11 #include <vtkPolyData.h>
12
13 /* TODO
14    #include <cpExtensions/Visualization/MPR3DActors.h>
15    #include <cpExtensions/Visualization/LUTImageActor.h>
16
17    #include <vtkActor.h>
18 */
19
20 // -------------------------------------------------------------------------
21 cpExtensions::QT::MPR3DWidget::
22 MPR3DWidget( QWidget* parent, Qt::WindowFlags f )
23   : Superclass( parent, f ),
24     m_ImageName( "" )
25 {
26   /* TODO
27      this->m_Actors =
28      vtkSmartPointer< cpExtensions::Visualization::MPR3DActors >::New( );
29   */
30 }
31
32 // -------------------------------------------------------------------------
33 cpExtensions::QT::MPR3DWidget::
34 ~MPR3DWidget( )
35 {
36   for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
37     delete *a;
38   this->m_Actors.clear( );
39 }
40
41 // -------------------------------------------------------------------------
42 void cpExtensions::QT::MPR3DWidget::
43 Clear( )
44 {
45   this->RemoveViewProps( );
46   this->m_ImageName = "";
47 }
48
49 // -------------------------------------------------------------------------
50 void cpExtensions::QT::MPR3DWidget::
51 SetImage( vtkImageData* image, const std::string& name )
52 {
53   if( name == "" )
54     return;
55   if( this->m_ImageName != "" )
56     this->Clear( );
57   this->m_ImageName = name;
58
59   for( unsigned int o = 0; o < 3; ++o )
60   {
61     this->m_WLActors[ o ] = vtkSmartPointer< TWLActor >::New( );
62     this->m_WLActors[ o ]->SetImage( image );
63     this->m_WLActors[ o ]->SetOrientation( o );
64
65     this->m_OLActors[ o ] = vtkSmartPointer< TOLActor >::New( );
66     this->m_OLActors[ o ]->SetBounds(
67       o, image->GetBounds( )[ o << 1 ], image->GetBounds( )
68       );
69
70     this->AddViewProp( this->m_WLActors[ o ], this->m_ImageName );
71     this->AddAuxViewProp( this->m_OLActors[ o ], this->m_ImageName );
72     this->ResetCamera( );
73
74   } // rof
75 }
76
77 // -------------------------------------------------------------------------
78 void cpExtensions::QT::MPR3DWidget::
79 Add( vtkDataSet* data, const std::string& name )
80 {
81   auto image = dynamic_cast< vtkImageData* >( data );
82   auto pdata = dynamic_cast< vtkPolyData* >( data );
83   if( image != NULL )
84   {
85     /* TODO
86        if( this->m_ImageName != "" )
87        {
88        }
89        else
90        this->SetImage( image, name );
91     */
92   }
93   else if( pdata != NULL )
94   {
95     TActor* actor = new TActor( );
96     actor->SetMesh( pdata );
97     this->m_Actors.push_back( actor );
98     this->AddViewProp( actor->GetActor( ), name );
99     this->Render( );
100     if( this->m_ImageName == "" )
101       this->ResetCamera( );
102
103   } // fi
104 }
105
106 // -------------------------------------------------------------------------
107 cpExtensions::QT::MPR3DWidget::
108 TWLActor* cpExtensions::QT::MPR3DWidget::
109 GetImageActor( int o )
110 {
111   return( this->m_WLActors[ o % 3 ] );
112 }
113
114 // -------------------------------------------------------------------------
115 const cpExtensions::QT::MPR3DWidget::
116 TWLActor* cpExtensions::QT::MPR3DWidget::
117 GetImageActor( int o ) const
118 {
119   return( this->m_WLActors[ o % 3 ] );
120 }
121
122 // -------------------------------------------------------------------------
123 void cpExtensions::QT::MPR3DWidget::
124 SetSliceNumber( int orientation, int slice )
125 {
126   int o = orientation % 3;
127   this->m_WLActors[ o ]->SetSliceNumber( slice );
128   this->m_OLActors[ o ]->SetBounds(
129     o,
130     this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
131     this->m_WLActors[ o ]->GetImage( )->GetBounds( )
132     );
133   this->Render( );
134 }
135
136 // -------------------------------------------------------------------------
137 void cpExtensions::QT::MPR3DWidget::
138 SetSlicesNumbers( int x, int y, int z )
139 {
140   int s[] = { x, y, z };
141   for( int o = 0; o < 3; ++o )
142   {
143     this->m_WLActors[ o ]->SetSliceNumber( s[ o ] );
144     this->m_OLActors[ o ]->SetBounds(
145       o,
146       this->m_WLActors[ o ]->GetSlicePlane( )->GetOrigin( )[ o ],
147       this->m_WLActors[ o ]->GetImage( )->GetBounds( )
148       );
149
150   } // rof
151   this->Render( );
152 }
153
154 // -------------------------------------------------------------------------
155 /*
156 void cpExtensions::QT::MPR3DWidget::
157 SetImage( vtkImageData* image, const std::string& name )
158 {
159   if( this->m_ImageName != "" )
160   {
161     // TODO: Clear visualization
162
163   } // fi
164
165   this->m_Actors->SetImage( image );
166   this->m_ImageName = name;
167
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( );
178   this->Render( );
179 }
180
181 // -------------------------------------------------------------------------
182 void cpExtensions::QT::MPR3DWidget::
183 SetSliceNumber( int orientation, int slice )
184 {
185   this->m_Actors->SetSliceNumber( orientation, slice );
186   this->Render( );
187 }
188
189 // -------------------------------------------------------------------------
190 void cpExtensions::QT::MPR3DWidget::
191 SetSlicesNumbers( int x, int y, int z )
192 {
193   this->m_Actors->SetSliceNumber( 0, x );
194   this->m_Actors->SetSliceNumber( 1, y );
195   this->m_Actors->SetSliceNumber( 2, z );
196   this->Render( );
197 }
198
199 // -------------------------------------------------------------------------
200 void cpExtensions::QT::MPR3DWidget::
201 SetScalarRange( double r[ 2 ] )
202 {
203   this->m_Actors->SetScalarRange( r );
204   this->Render( );
205 }
206
207 // -------------------------------------------------------------------------
208 void cpExtensions::QT::MPR3DWidget::
209 SetWindowLevel( double wl[ 2 ] )
210 {
211   this->m_Actors->SetWindowLevel( wl );
212   this->Render( );
213 }
214
215 // -------------------------------------------------------------------------
216 void cpExtensions::QT::MPR3DWidget::
217 SetImageOpacity( double o )
218 {
219   this->m_Actors->SetImageOpacity( o );
220   this->Render( );
221 }
222
223 // -------------------------------------------------------------------------
224 void cpExtensions::QT::MPR3DWidget::
225 SetImageInterpolation( unsigned char i )
226 {
227   this->m_Actors->SetImageInterpolation( i );
228   this->Render( );
229 }
230   */
231
232 #endif // cpExtensions_QT4
233
234 // eof - $RCSfile$