1 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
2 #include <cpExtensions/Visualization/ImageSliceMapper.h>
4 #include <vtkImageData.h>
5 #include <vtkImageProperty.h>
7 // -------------------------------------------------------------------------
8 cpExtensions::Visualization::WindowLevelImageActor::
9 Self* cpExtensions::Visualization::WindowLevelImageActor::
12 return( new Self( ) );
15 // -------------------------------------------------------------------------
16 vtkImageData* cpExtensions::Visualization::WindowLevelImageActor::
19 return( this->m_Mapper->GetInput( ) );
22 // -------------------------------------------------------------------------
23 const vtkImageData* cpExtensions::Visualization::WindowLevelImageActor::
26 return( this->m_Mapper->GetInput( ) );
29 // -------------------------------------------------------------------------
30 void cpExtensions::Visualization::WindowLevelImageActor::
31 SetImage( vtkImageData* image )
33 this->m_Mapper->SetInputData( image );
34 image->GetScalarRange( this->m_Range );
35 this->ResetWindowLevel( );
39 // -------------------------------------------------------------------------
40 double cpExtensions::Visualization::WindowLevelImageActor::
43 return( this->GetProperty( )->GetColorLevel( ) );
46 // -------------------------------------------------------------------------
47 double cpExtensions::Visualization::WindowLevelImageActor::
50 return( this->GetProperty( )->GetColorWindow( ) );
53 // -------------------------------------------------------------------------
54 void cpExtensions::Visualization::WindowLevelImageActor::
57 double old_l = this->GetProperty( )->GetColorLevel( );
58 if( l != old_l && this->m_Range[ 0 ] <= l && l <= this->m_Range[ 1 ] )
60 this->GetProperty( )->SetColorLevel( l );
66 // -------------------------------------------------------------------------
67 void cpExtensions::Visualization::WindowLevelImageActor::
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 )
74 this->GetProperty( )->SetColorWindow( w );
80 // -------------------------------------------------------------------------
81 void cpExtensions::Visualization::WindowLevelImageActor::
82 SetWindowLevel( double w, double l )
88 // -------------------------------------------------------------------------
89 void cpExtensions::Visualization::WindowLevelImageActor::
93 this->m_Range[ 1 ] - this->m_Range[ 0 ],
94 ( this->m_Range[ 1 ] + this->m_Range[ 0 ] ) / double( 2 )
98 // -------------------------------------------------------------------------
99 void cpExtensions::Visualization::WindowLevelImageActor::
100 ConfigureWindowLevel( double min, double max )
102 this->m_Range[ 0 ] = ( min < max )? min: max;
103 this->m_Range[ 1 ] = ( min < max )? max: min;
104 this->ResetWindowLevel( );
107 // -------------------------------------------------------------------------
108 void cpExtensions::Visualization::WindowLevelImageActor::
109 GetRange( double r[ 2 ] ) const
111 r[ 0 ] = this->m_Range[ 0 ];
112 r[ 1 ] = this->m_Range[ 1 ];
115 // -------------------------------------------------------------------------
116 cpExtensions::Visualization::WindowLevelImageActor::
117 WindowLevelImageActor( )
120 this->ConfigureWindowLevel( 0, 0 );
123 // -------------------------------------------------------------------------
124 cpExtensions::Visualization::WindowLevelImageActor::
125 ~WindowLevelImageActor( )