1 #include <cpBaseQtApplication/ActorImageProperties.h>
3 #include <cpBaseQtApplication/ui_ActorImageProperties.h>
5 #include <vtkImageSlice.h>
6 #include <vtkImageData.h>
7 #include <vtkImageMapper3D.h>
8 #include <vtkImageProperty.h>
10 // -------------------------------------------------------------------------
11 cpBaseQtApplication::ActorImageProperties::
12 ActorImageProperties( QWidget* parent )
13 : cpBaseQtApplication::ActorProperties( parent ),
14 m_UI( new Ui::ActorImageProperties )
16 this->m_UI->setupUi( this );
19 // -------------------------------------------------------------------------
20 cpBaseQtApplication::ActorImageProperties::
21 ~ActorImageProperties( )
26 // -------------------------------------------------------------------------
27 bool cpBaseQtApplication::ActorImageProperties::
28 addActor( vtkProp* obj )
30 auto actor = dynamic_cast< vtkImageSlice* >( obj );
33 this->m_Actors.insert( obj );
34 if( this->m_Actors.size( ) == 1 )
35 this->_updateWidgets( );
42 // -------------------------------------------------------------------------
43 void cpBaseQtApplication::ActorImageProperties::
47 dynamic_cast< vtkImageSlice* >( this->m_Actors.begin( )->GetPointer( ) );
52 auto prop = actor->GetProperty( );
53 auto mapper = actor->GetMapper( );
54 auto image = mapper->GetInput( );
56 image->GetScalarRange( r );
57 double win = prop->GetColorWindow( );
58 double lev = prop->GetColorLevel( );
59 double op = prop->GetOpacity( );
60 int interp = prop->GetInterpolationType( );
62 this->m_UI->ValueWindow->setMinimum( 0 );
63 this->m_UI->ValueWindow->setMaximum( r[ 1 ] - r[ 0 ] );
64 this->m_UI->ValueLevel->setMinimum( r[ 0 ] );
65 this->m_UI->ValueLevel->setMaximum( r[ 1 ] );
66 this->m_UI->ValueWindow->setValue( win );
67 this->m_UI->ValueLevel->setValue( lev );
69 double w = win / ( r[ 1 ] - r[ 0 ] );
70 double l = ( lev - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
72 op *= double( this->m_UI->Opacity->maximum( ) );
73 this->m_UI->Opacity->setValue( int( op ) );
75 w *= double( this->m_UI->Window->maximum( ) );
76 this->m_UI->Window->setValue( int( w ) );
78 l *= double( this->m_UI->Level->maximum( ) );
79 this->m_UI->Level->setValue( int( l ) );
81 if( interp == VTK_CUBIC_INTERPOLATION )
82 this->m_UI->Interpolation->setCurrentIndex( 0 );
83 else if( interp == VTK_LINEAR_INTERPOLATION )
84 this->m_UI->Interpolation->setCurrentIndex( 1 );
85 else if( interp == VTK_NEAREST_INTERPOLATION )
86 this->m_UI->Interpolation->setCurrentIndex( 2 );
90 this->m_UI->Opacity, SIGNAL( valueChanged( int ) ),
91 this, SLOT( _Opacity( int ) )
94 this->m_UI->Window, SIGNAL( valueChanged( int ) ),
95 this, SLOT( _Window( int ) )
98 this->m_UI->Level, SIGNAL( valueChanged( int ) ),
99 this, SLOT( _Level( int ) )
102 this->m_UI->ValueWindow, SIGNAL( valueChanged( double ) ),
103 this, SLOT( _Window( double ) )
106 this->m_UI->ValueLevel, SIGNAL( valueChanged( double ) ),
107 this, SLOT( _Level( double ) )
110 this->m_UI->Interpolation, SIGNAL( currentIndexChanged( int ) ),
111 this, SLOT( _Interpolation( int ) )
115 // -------------------------------------------------------------------------
116 void cpBaseQtApplication::ActorImageProperties::
119 double op = double( v ) / double( this->m_UI->Opacity->maximum( ) );
120 auto aIt = this->m_Actors.begin( );
121 for( ; aIt != this->m_Actors.end( ); ++aIt )
123 auto ma = dynamic_cast< vtkImageSlice* >( aIt->GetPointer( ) );
124 ma->GetProperty( )->SetOpacity( op );
131 // -------------------------------------------------------------------------
132 void cpBaseQtApplication::ActorImageProperties::
135 double x = this->m_UI->ValueWindow->minimum( );
136 double y = this->m_UI->ValueWindow->maximum( );
137 double z = double( v ) / double( this->m_UI->Window->maximum( ) );
138 double w = ( ( y - x ) * z ) + x;
139 bool prev = this->m_UI->ValueWindow->blockSignals( true );
140 this->m_UI->ValueWindow->setValue( w );
141 this->m_UI->ValueWindow->blockSignals( prev );
142 auto aIt = this->m_Actors.begin( );
143 for( ; aIt != this->m_Actors.end( ); ++aIt )
145 auto ma = dynamic_cast< vtkImageSlice* >( aIt->GetPointer( ) );
146 ma->GetProperty( )->SetColorWindow( w );
153 // -------------------------------------------------------------------------
154 void cpBaseQtApplication::ActorImageProperties::
157 double x = this->m_UI->ValueLevel->minimum( );
158 double y = this->m_UI->ValueLevel->maximum( );
159 double z = double( v ) / double( this->m_UI->Level->maximum( ) );
160 double l = ( ( y - x ) * z ) + x;
161 bool prev = this->m_UI->ValueLevel->blockSignals( true );
162 this->m_UI->ValueLevel->setValue( l );
163 this->m_UI->ValueLevel->blockSignals( prev );
164 auto aIt = this->m_Actors.begin( );
165 for( ; aIt != this->m_Actors.end( ); ++aIt )
167 auto ma = dynamic_cast< vtkImageSlice* >( aIt->GetPointer( ) );
168 ma->GetProperty( )->SetColorLevel( l );
175 // -------------------------------------------------------------------------
176 void cpBaseQtApplication::ActorImageProperties::
179 auto aIt = this->m_Actors.begin( );
180 for( ; aIt != this->m_Actors.end( ); ++aIt )
182 auto ma = dynamic_cast< vtkImageSlice* >( aIt->GetPointer( ) );
183 ma->GetProperty( )->SetColorWindow( v );
189 double x = this->m_UI->ValueWindow->minimum( );
190 double y = this->m_UI->ValueWindow->maximum( );
191 double z = ( v - x ) / ( y - x );
192 double w = double( z ) * double( this->m_UI->Window->maximum( ) );
193 bool prev = this->m_UI->Window->blockSignals( true );
194 this->m_UI->Window->setValue( int( w ) );
195 this->m_UI->Window->blockSignals( prev );
198 // -------------------------------------------------------------------------
199 void cpBaseQtApplication::ActorImageProperties::
202 auto aIt = this->m_Actors.begin( );
203 for( ; aIt != this->m_Actors.end( ); ++aIt )
205 auto ma = dynamic_cast< vtkImageSlice* >( aIt->GetPointer( ) );
206 ma->GetProperty( )->SetColorLevel( v );
212 double x = this->m_UI->ValueLevel->minimum( );
213 double y = this->m_UI->ValueLevel->maximum( );
214 double z = ( v - x ) / ( y - x );
215 double l = double( z ) * double( this->m_UI->Level->maximum( ) );
216 bool prev = this->m_UI->Level->blockSignals( true );
217 this->m_UI->Level->setValue( int( l ) );
218 this->m_UI->Level->blockSignals( prev );
221 // -------------------------------------------------------------------------
222 void cpBaseQtApplication::ActorImageProperties::
223 _Interpolation( int v )
225 int interp = VTK_NEAREST_INTERPOLATION;
226 if ( v == 0 ) interp = VTK_CUBIC_INTERPOLATION;
227 else if( v == 1 ) interp = VTK_LINEAR_INTERPOLATION;
228 else if( v == 2 ) interp = VTK_NEAREST_INTERPOLATION;
230 auto aIt = this->m_Actors.begin( );
231 for( ; aIt != this->m_Actors.end( ); ++aIt )
233 auto ma = dynamic_cast< vtkImageSlice* >( aIt->GetPointer( ) );
234 ma->GetProperty( )->SetInterpolationType( interp );