1 #include <cpPlugins/ActorImageProperties.h>
5 #include <cpPlugins/ui_ActorImageProperties.h>
7 #include <vtkImageActor.h>
8 #include <vtkImageData.h>
9 #include <vtkImageMapper3D.h>
10 #include <vtkImageProperty.h>
12 // -------------------------------------------------------------------------
13 cpPlugins::ActorImageProperties::
14 ActorImageProperties( QWidget* parent )
15 : cpPlugins::ActorProperties( parent ),
16 m_UI( new Ui::ActorImageProperties )
18 this->m_UI->setupUi( this );
21 // -------------------------------------------------------------------------
22 cpPlugins::ActorImageProperties::
23 ~ActorImageProperties( )
28 // -------------------------------------------------------------------------
29 bool cpPlugins::ActorImageProperties::
30 addActor( vtkProp* obj )
32 auto actor = dynamic_cast< vtkImageActor* >( obj );
35 this->m_Actors.insert( obj );
36 if( this->m_Actors.size( ) == 1 )
37 this->_updateWidgets( );
44 // -------------------------------------------------------------------------
45 void cpPlugins::ActorImageProperties::
49 dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) );
54 auto prop = actor->GetProperty( );
55 auto mapper = actor->GetMapper( );
56 auto image = mapper->GetInput( );
58 image->GetScalarRange( r );
59 double win = prop->GetColorWindow( );
60 double lev = prop->GetColorLevel( );
61 double op = prop->GetOpacity( );
62 int interp = prop->GetInterpolationType( );
64 this->m_UI->ValueWindow->setMinimum( 0 );
65 this->m_UI->ValueWindow->setMaximum( r[ 1 ] - r[ 0 ] );
66 this->m_UI->ValueLevel->setMinimum( r[ 0 ] );
67 this->m_UI->ValueLevel->setMaximum( r[ 1 ] );
68 this->m_UI->ValueWindow->setValue( win );
69 this->m_UI->ValueLevel->setValue( lev );
71 double w = win / ( r[ 1 ] - r[ 0 ] );
72 double l = ( lev - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
74 op *= double( this->m_UI->Opacity->maximum( ) );
75 this->m_UI->Opacity->setValue( int( op ) );
77 w *= double( this->m_UI->Window->maximum( ) );
78 this->m_UI->Window->setValue( int( w ) );
80 l *= double( this->m_UI->Level->maximum( ) );
81 this->m_UI->Level->setValue( int( l ) );
83 if( interp == VTK_CUBIC_INTERPOLATION )
84 this->m_UI->Interpolation->setCurrentIndex( 0 );
85 else if( interp == VTK_LINEAR_INTERPOLATION )
86 this->m_UI->Interpolation->setCurrentIndex( 1 );
87 else if( interp == VTK_NEAREST_INTERPOLATION )
88 this->m_UI->Interpolation->setCurrentIndex( 2 );
92 this->m_UI->Opacity, SIGNAL( valueChanged( int ) ),
93 this, SLOT( _Opacity( int ) )
96 this->m_UI->Window, SIGNAL( valueChanged( int ) ),
97 this, SLOT( _Window( int ) )
100 this->m_UI->Level, SIGNAL( valueChanged( int ) ),
101 this, SLOT( _Level( int ) )
104 this->m_UI->ValueWindow, SIGNAL( valueChanged( double ) ),
105 this, SLOT( _Window( double ) )
108 this->m_UI->ValueLevel, SIGNAL( valueChanged( double ) ),
109 this, SLOT( _Level( double ) )
112 this->m_UI->Interpolation, SIGNAL( currentIndexChanged( int ) ),
113 this, SLOT( _Interpolation( int ) )
117 // -------------------------------------------------------------------------
118 void cpPlugins::ActorImageProperties::
121 double op = double( v ) / double( this->m_UI->Opacity->maximum( ) );
122 auto aIt = this->m_Actors.begin( );
123 for( ; aIt != this->m_Actors.end( ); ++aIt )
125 auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
126 ma->GetProperty( )->SetOpacity( op );
133 // -------------------------------------------------------------------------
134 void cpPlugins::ActorImageProperties::
137 double x = this->m_UI->ValueWindow->minimum( );
138 double y = this->m_UI->ValueWindow->maximum( );
139 double z = double( v ) / double( this->m_UI->Window->maximum( ) );
140 double w = ( ( y - x ) * z ) + x;
141 bool prev = this->m_UI->ValueWindow->blockSignals( true );
142 this->m_UI->ValueWindow->setValue( w );
143 this->m_UI->ValueWindow->blockSignals( prev );
144 auto aIt = this->m_Actors.begin( );
145 for( ; aIt != this->m_Actors.end( ); ++aIt )
147 auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
148 ma->GetProperty( )->SetColorWindow( w );
155 // -------------------------------------------------------------------------
156 void cpPlugins::ActorImageProperties::
159 double x = this->m_UI->ValueLevel->minimum( );
160 double y = this->m_UI->ValueLevel->maximum( );
161 double z = double( v ) / double( this->m_UI->Level->maximum( ) );
162 double l = ( ( y - x ) * z ) + x;
163 bool prev = this->m_UI->ValueLevel->blockSignals( true );
164 this->m_UI->ValueLevel->setValue( l );
165 this->m_UI->ValueLevel->blockSignals( prev );
166 auto aIt = this->m_Actors.begin( );
167 for( ; aIt != this->m_Actors.end( ); ++aIt )
169 auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
170 ma->GetProperty( )->SetColorLevel( l );
177 // -------------------------------------------------------------------------
178 void cpPlugins::ActorImageProperties::
181 auto aIt = this->m_Actors.begin( );
182 for( ; aIt != this->m_Actors.end( ); ++aIt )
184 auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
185 ma->GetProperty( )->SetColorWindow( v );
191 double x = this->m_UI->ValueWindow->minimum( );
192 double y = this->m_UI->ValueWindow->maximum( );
193 double z = ( v - x ) / ( y - x );
194 double w = double( z ) * double( this->m_UI->Window->maximum( ) );
195 bool prev = this->m_UI->Window->blockSignals( true );
196 this->m_UI->Window->setValue( int( w ) );
197 this->m_UI->Window->blockSignals( prev );
200 // -------------------------------------------------------------------------
201 void cpPlugins::ActorImageProperties::
204 auto aIt = this->m_Actors.begin( );
205 for( ; aIt != this->m_Actors.end( ); ++aIt )
207 auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
208 ma->GetProperty( )->SetColorLevel( v );
214 double x = this->m_UI->ValueLevel->minimum( );
215 double y = this->m_UI->ValueLevel->maximum( );
216 double z = ( v - x ) / ( y - x );
217 double l = double( z ) * double( this->m_UI->Level->maximum( ) );
218 bool prev = this->m_UI->Level->blockSignals( true );
219 this->m_UI->Level->setValue( int( l ) );
220 this->m_UI->Level->blockSignals( prev );
223 // -------------------------------------------------------------------------
224 void cpPlugins::ActorImageProperties::
225 _Interpolation( int v )
227 int interp = VTK_NEAREST_INTERPOLATION;
228 if ( v == 0 ) interp = VTK_CUBIC_INTERPOLATION;
229 else if( v == 1 ) interp = VTK_LINEAR_INTERPOLATION;
230 else if( v == 2 ) interp = VTK_NEAREST_INTERPOLATION;
232 auto aIt = this->m_Actors.begin( );
233 for( ; aIt != this->m_Actors.end( ); ++aIt )
235 auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
236 ma->GetProperty( )->SetInterpolationType( interp );
243 #endif // cpPlugins_QT4