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