]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx
Image interaction updated.
[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 AddDoubleClickObserver( vtkCommand* observer )
78 {
79   for( int i = 0; i < 3; ++i )
80     if( this->m_Styles[ i ].GetPointer( ) != NULL )
81       this->m_Styles[ i ]->AddDoubleClickObserver( observer );
82 }
83
84 // -------------------------------------------------------------------------
85 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
86 RemoveDoubleClickObserver( vtkCommand* observer )
87 {
88   for( int i = 0; i < 3; ++i )
89     if( this->m_Styles[ i ].GetPointer( ) != NULL )
90       this->m_Styles[ i ]->RemoveDoubleClickObserver( observer );
91 }
92
93 // -------------------------------------------------------------------------
94 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
95 RemoveDoubleClickObservers( )
96 {
97   for( int i = 0; i < 3; ++i )
98     if( this->m_Styles[ i ].GetPointer( ) != NULL )
99       this->m_Styles[ i ]->RemoveDoubleClickObservers( );
100 }
101
102 // -------------------------------------------------------------------------
103 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
104 SetImage( vtkImageData* image )
105 {
106   this->m_MPRActors->SetInputData( image );
107   this->m_MPRActors->PushDataInto(
108     this->m_Renderers[ 0 ],
109     this->m_Renderers[ 1 ],
110     this->m_Renderers[ 2 ],
111     this->m_Renderers[ 3 ]
112     );
113
114   // First rendering
115   this->ResetCameras( );
116   this->RenderAll( );
117 }
118
119 // -------------------------------------------------------------------------
120 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
121 SetSegmentation( vtkImageData* image )
122 {
123   this->m_MPRActors->SetSegmentationData( image );
124   this->m_MPRActors->PushDataInto(
125     this->m_Renderers[ 0 ],
126     this->m_Renderers[ 1 ],
127     this->m_Renderers[ 2 ],
128     this->m_Renderers[ 3 ]
129     );
130
131   this->Render( 0 );
132   this->Render( 1 );
133   this->Render( 2 );
134 }
135
136 // -------------------------------------------------------------------------
137 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
138 ResetCamera( const int& id )
139 {
140   if( id < 4 )
141     if( this->m_Windows[ id ] != NULL )
142       this->m_Renderers[ id ]->ResetCamera( );
143 }
144
145 // -------------------------------------------------------------------------
146 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
147 ResetCameras( )
148 {
149   for( int i = 0; i < 4; ++i )
150     if( this->m_Windows[ i ] != NULL )
151       this->m_Renderers[ i ]->ResetCamera( );
152 }
153
154 // -------------------------------------------------------------------------
155 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
156 Render( const int& id )
157 {
158   if( id < 4 )
159     if( this->m_Windows[ id ] != NULL )
160       this->m_Windows[ id ]->Render( );
161 }
162
163 // -------------------------------------------------------------------------
164 void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows::
165 RenderAll( )
166 {
167   for( int i = 0; i < 4; ++i )
168     if( this->m_Windows[ i ] != NULL )
169       this->m_Windows[ i ]->Render( );
170 }
171
172 // eof - $RCSfile$