]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/WindowLevelImageActor.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Visualization / WindowLevelImageActor.cxx
1 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
2 #include <cpExtensions/Visualization/ImageSliceMapper.h>
3
4 #include <vtkImageData.h>
5 #include <vtkImageProperty.h>
6
7 // -------------------------------------------------------------------------
8 cpExtensions::Visualization::WindowLevelImageActor::
9 Self* cpExtensions::Visualization::WindowLevelImageActor::
10 New( )
11 {
12   return( new Self( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 vtkImageData* cpExtensions::Visualization::WindowLevelImageActor::
17 GetImage( )
18 {
19   return( this->m_Mapper->GetInput( ) );
20 }
21
22 // -------------------------------------------------------------------------
23 const vtkImageData* cpExtensions::Visualization::WindowLevelImageActor::
24 GetImage( ) const
25 {
26   return( this->m_Mapper->GetInput( ) );
27 }
28
29 // -------------------------------------------------------------------------
30 void cpExtensions::Visualization::WindowLevelImageActor::
31 SetImage( vtkImageData* image )
32 {
33   this->m_Mapper->SetInputData( image );
34   this->ResetRange( );
35   this->Modified( );
36 }
37
38 // -------------------------------------------------------------------------
39 double cpExtensions::Visualization::WindowLevelImageActor::
40 GetLevel( ) const
41 {
42   Self* self = const_cast< Self* >( this );
43   return( self->GetProperty( )->GetColorLevel( ) );
44 }
45
46 // -------------------------------------------------------------------------
47 double cpExtensions::Visualization::WindowLevelImageActor::
48 GetWindow( ) const
49 {
50   Self* self = const_cast< Self* >( this );
51   return( self->GetProperty( )->GetColorWindow( ) );
52 }
53
54 // -------------------------------------------------------------------------
55 void cpExtensions::Visualization::WindowLevelImageActor::
56 GetWindowLevel( double wl[ 2 ] ) const
57 {
58   Self* self = const_cast< Self* >( this );
59   wl[ 0 ] = self->GetProperty( )->GetColorWindow( );
60   wl[ 1 ] = self->GetProperty( )->GetColorLevel( );
61 }
62
63 // -------------------------------------------------------------------------
64 void cpExtensions::Visualization::WindowLevelImageActor::
65 ResetWindowLevel( )
66 {
67   this->SetWindowLevel(
68     ( this->m_Range[ 1 ] - this->m_Range[ 0 ] ),
69     ( this->m_Range[ 1 ] + this->m_Range[ 0 ] ) / double( 2 )
70     );
71 }
72
73 // -------------------------------------------------------------------------
74 void cpExtensions::Visualization::WindowLevelImageActor::
75 SetLevel( double l )
76 {
77   double ol = this->GetProperty( )->GetColorLevel( );
78   if( l != ol && this->m_Range[ 0 ] <= l && l <= this->m_Range[ 1 ] )
79   {
80     this->GetProperty( )->SetColorLevel( l );
81     this->Modified( );
82
83   } // fi
84 }
85
86 // -------------------------------------------------------------------------
87 void cpExtensions::Visualization::WindowLevelImageActor::
88 SetWindow( double w )
89 {
90   double mw = this->m_Range[ 1 ] - this->m_Range[ 0 ];
91   double ow = this->GetProperty( )->GetColorWindow( );
92   if( w != ow && double( 0 ) <= w && w <= mw )
93   {
94     this->GetProperty( )->SetColorWindow( w );
95     this->Modified( );
96
97   } // fi
98 }
99
100 // -------------------------------------------------------------------------
101 void cpExtensions::Visualization::WindowLevelImageActor::
102 SetWindowLevel( double w, double l )
103 {
104   this->SetWindow( w );
105   this->SetLevel( l );
106 }
107
108 // -------------------------------------------------------------------------
109 void cpExtensions::Visualization::WindowLevelImageActor::
110 SetWindowLevel( double wl[ 2 ] )
111 {
112   this->SetWindow( wl[ 0 ] );
113   this->SetLevel( wl[ 1 ] );
114 }
115
116 // -------------------------------------------------------------------------
117 double cpExtensions::Visualization::WindowLevelImageActor::
118 GetMinimum( ) const
119 {
120   return( this->m_Range[ 0 ] );
121 }
122
123 // -------------------------------------------------------------------------
124 double cpExtensions::Visualization::WindowLevelImageActor::
125 GetMaximum( ) const
126 {
127   return( this->m_Range[ 0 ] );
128 }
129
130 // -------------------------------------------------------------------------
131 void cpExtensions::Visualization::WindowLevelImageActor::
132 GetRange( double r[ 2 ] ) const
133 {
134   r[ 0 ] = this->m_Range[ 0 ];
135   r[ 1 ] = this->m_Range[ 1 ];
136 }
137
138 // -------------------------------------------------------------------------
139 void cpExtensions::Visualization::WindowLevelImageActor::
140 ResetRange( )
141 {
142   this->GetImage( )->GetScalarRange( this->m_Range );
143   this->ResetWindowLevel( );
144 }
145
146 // -------------------------------------------------------------------------
147 void cpExtensions::Visualization::WindowLevelImageActor::
148 SetMinimum( double a )
149 {
150   if( this->m_Range[ 0 ] != a )
151   {
152     this->m_Range[ 0 ] = a;
153     this->ResetWindowLevel( );
154
155   } // fi
156 }
157
158 // -------------------------------------------------------------------------
159 void cpExtensions::Visualization::WindowLevelImageActor::
160 SetMaximum( double b )
161 {
162   if( this->m_Range[ 1 ] != b )
163   {
164     this->m_Range[ 1 ] = b;
165     this->ResetWindowLevel( );
166
167   } // fi
168 }
169
170 // -------------------------------------------------------------------------
171 void cpExtensions::Visualization::WindowLevelImageActor::
172 SetRange( double a, double b )
173 {
174   this->SetMinimum( a );
175   this->SetMaximum( b );
176 }
177
178 // -------------------------------------------------------------------------
179 void cpExtensions::Visualization::WindowLevelImageActor::
180 SetRange( double r[ 2 ] )
181 {
182   this->SetMinimum( r[ 0 ] );
183   this->SetMaximum( r[ 1 ] );
184 }
185
186 // -------------------------------------------------------------------------
187 cpExtensions::Visualization::WindowLevelImageActor::
188 WindowLevelImageActor( )
189   : Superclass( )
190 {
191   this->m_Range[ 0 ] = this->m_Range[ 1 ] = double( 0 );
192 }
193
194 // -------------------------------------------------------------------------
195 cpExtensions::Visualization::WindowLevelImageActor::
196 ~WindowLevelImageActor( )
197 {
198 }
199
200 // eof - $RCSfile$