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