]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx
...
[cpPlugins.git] / lib / cpPlugins / Extensions / Visualization / MPRWithDifferentWindows.cxx
1 #include <cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h>
2 #include <vtkCamera.h>
3
4 // -------------------------------------------------------------------------
5 cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
6 MPRWithDifferentWindows(
7   vtkRenderWindow* xWin,
8   vtkRenderWindow* yWin,
9   vtkRenderWindow* zWin,
10   vtkRenderWindow* auxWin
11   )
12 {
13   this->m_Windows[ 0 ] = xWin;
14   this->m_Windows[ 1 ] = yWin;
15   this->m_Windows[ 2 ] = zWin;
16   this->m_Windows[ 3 ] = auxWin;
17
18   // Prepare actors
19   this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( );
20
21   // Prepare renderers
22   for( int i = 0; i < 4; ++i )
23   {
24     if( this->m_Windows[ i ] == NULL )
25     {
26       this->m_Renderers[ i ] = NULL;
27       continue;
28
29     } // fi
30
31     // Renderers
32     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
33     this->m_Renderers[ i ]->SetBackground( 0.1, 0.3, 0.8 );
34     this->m_Windows[ i ]->AddRenderer( this->m_Renderers[ i ] );
35
36     // Image styles (just for 2D windows)
37     if( i < 3 )
38     {
39       this->m_Styles[ i ] = vtkSmartPointer< TStyle >::New( );
40       this->m_Styles[ i ]->Configure(
41         this->m_MPRActors->GetSliceActors( i ), this->m_MPRActors
42         );
43
44       this->m_Styles[ i ]->
45         SetInteractor( this->m_Windows[ i ]->GetInteractor( ), i );
46       this->m_Styles[ i ]->SetModeToNavigation( );
47
48     } // fi
49
50   } // rof
51   if( this->m_Windows[ 3 ] != NULL )
52     this->m_Renderers[ 3 ]->SetBackground( 0.2, 0.2, 0.2 );
53
54   for( int i = 0; i < 3; ++i )
55   {
56     for( int j = 0; j < 3; ++j )
57     {
58       if(
59         this->m_Windows[ i ] != NULL &&
60         this->m_Windows[ j ] != NULL &&
61         i != j
62         )
63         this->m_Styles[ i ]->
64           AssociateInteractor( this->m_Windows[ j ]->GetInteractor( ) );
65
66     } // rof
67     if( this->m_Windows[ 3 ] != NULL )
68       this->m_Styles[ i ]->
69         AssociateInteractor( this->m_Windows[ 3 ]->GetInteractor( ) );
70
71   } // rof
72 }
73
74 // -------------------------------------------------------------------------
75 cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
76 ~MPRWithDifferentWindows( )
77 {
78 }
79
80 // -------------------------------------------------------------------------
81 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
82 SetImage( vtkImageData* image )
83 {
84   this->m_MPRActors->SetInputData( image );
85   this->m_MPRActors->PushDataInto(
86     this->m_Renderers[ 0 ],
87     this->m_Renderers[ 1 ],
88     this->m_Renderers[ 2 ],
89     this->m_Renderers[ 3 ]
90     );
91
92   // Correct cameras positions
93   /* TODO
94      vtkCamera* zCam = this->m_Renderers[ 2 ]->GetActiveCamera( );
95      zCam->SetViewUp( 0, -1, 0 );
96      zCam->SetPosition( 0, 0, -1 );
97      zCam->SetFocalPoint( 0, 0, 0 );
98   */
99
100   // First rendering
101   this->ResetCameras( );
102   this->RenderAll( );
103 }
104
105 // -------------------------------------------------------------------------
106 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
107 SetModeToNavigation( )
108 {
109   for( unsigned int i = 0; i < 3; ++i )
110   {
111     if( this->m_Styles[ i ].GetPointer( ) != NULL )
112       this->m_Styles[ i ]->SetModeToNavigation( );
113     
114   } // rof
115 }
116
117 // -------------------------------------------------------------------------
118 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
119 SetModeToDeformation( )
120 {
121   for( unsigned int i = 0; i < 3; ++i )
122   {
123     if( this->m_Styles[ i ].GetPointer( ) != NULL )
124       this->m_Styles[ i ]->SetModeToDeformation( );
125     
126   } // rof
127 }
128
129 // -------------------------------------------------------------------------
130 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
131 ResetCamera( const int& id )
132 {
133   if( id < 4 )
134     if( this->m_Windows[ id ] != NULL )
135       this->m_Renderers[ id ]->ResetCamera( );
136 }
137
138 // -------------------------------------------------------------------------
139 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
140 ResetCameras( )
141 {
142   for( int i = 0; i < 4; ++i )
143     if( this->m_Windows[ i ] != NULL )
144       this->m_Renderers[ i ]->ResetCamera( );
145 }
146
147 // -------------------------------------------------------------------------
148 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
149 Render( const int& id )
150 {
151   if( id < 4 )
152     if( this->m_Windows[ id ] != NULL )
153       this->m_Windows[ id ]->Render( );
154 }
155
156 // -------------------------------------------------------------------------
157 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
158 RenderAll( )
159 {
160   for( int i = 0; i < 4; ++i )
161     if( this->m_Windows[ i ] != NULL )
162       this->m_Windows[ i ]->Render( );
163 }
164
165 // -------------------------------------------------------------------------
166 vtkRenderer* cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
167 GetRenderer( const int& id ) const
168 {
169   if( id < 4 )
170     return( this->m_Renderers[ id ] );
171   else
172     return( NULL );
173 }
174
175 // -------------------------------------------------------------------------
176 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
177 Add3DActor( vtkProp3D* prop )
178 {
179   if( this->m_Renderers[ 3 ] != NULL )
180   {
181     this->m_Renderers[ 3 ]->AddActor( prop );
182     this->ResetCamera( 3 );
183     this->Render( 3 );
184
185   } // fi
186 }
187
188 // eof - $RCSfile$