]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/WindowLevelImageActor.cxx
Architecture updated.
[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   image->GetScalarRange( this->m_Range );
35   this->ResetWindowLevel( );
36   this->Modified( );
37 }
38
39 // -------------------------------------------------------------------------
40 double cpExtensions::Visualization::WindowLevelImageActor::
41 GetLevel( )
42 {
43   return( this->GetProperty( )->GetColorLevel( ) );
44 }
45
46 // -------------------------------------------------------------------------
47 double cpExtensions::Visualization::WindowLevelImageActor::
48 GetWindow( )
49 {
50   return( this->GetProperty( )->GetColorWindow( ) );
51 }
52
53 // -------------------------------------------------------------------------
54 void cpExtensions::Visualization::WindowLevelImageActor::
55 SetLevel( double l )
56 {
57   double old_l = this->GetProperty( )->GetColorLevel( );
58   if( l != old_l && this->m_Range[ 0 ] <= l && l <= this->m_Range[ 1 ] )
59   {
60     this->GetProperty( )->SetColorLevel( l );
61     this->Modified( );
62
63   } // fi
64 }
65
66 // -------------------------------------------------------------------------
67 void cpExtensions::Visualization::WindowLevelImageActor::
68 SetWindow( double w )
69 {
70   double max_w = this->m_Range[ 1 ] - this->m_Range[ 0 ];
71   double old_w = this->GetProperty( )->GetColorWindow( );
72   if( w != old_w && double( 0 ) <= w && w <= max_w )
73   {
74     this->GetProperty( )->SetColorWindow( w );
75     this->Modified( );
76
77   } // fi
78 }
79
80 // -------------------------------------------------------------------------
81 void cpExtensions::Visualization::WindowLevelImageActor::
82 SetWindowLevel( double w, double l )
83 {
84   this->SetWindow( w );
85   this->SetLevel( l );
86 }
87
88 // -------------------------------------------------------------------------
89 void cpExtensions::Visualization::WindowLevelImageActor::
90 ResetWindowLevel( )
91 {
92   this->SetWindowLevel(
93     this->m_Range[ 1 ] - this->m_Range[ 0 ],
94     ( this->m_Range[ 1 ] + this->m_Range[ 0 ] ) / double( 2 )
95     );
96 }
97
98 // -------------------------------------------------------------------------
99 void cpExtensions::Visualization::WindowLevelImageActor::
100 ConfigureWindowLevel( double min, double max )
101 {
102   this->m_Range[ 0 ] = ( min < max )? min: max;
103   this->m_Range[ 1 ] = ( min < max )? max: min;
104   this->ResetWindowLevel( );
105 }
106
107 // -------------------------------------------------------------------------
108 void cpExtensions::Visualization::WindowLevelImageActor::
109 GetRange( double r[ 2 ] ) const
110 {
111   r[ 0 ] = this->m_Range[ 0 ];
112   r[ 1 ] = this->m_Range[ 1 ];
113 }
114
115 // -------------------------------------------------------------------------
116 cpExtensions::Visualization::WindowLevelImageActor::
117 WindowLevelImageActor( )
118   : Superclass( )
119 {
120   this->ConfigureWindowLevel( 0, 0 );
121 }
122
123 // -------------------------------------------------------------------------
124 cpExtensions::Visualization::WindowLevelImageActor::
125 ~WindowLevelImageActor( )
126 {
127 }
128
129 // eof - $RCSfile$