1 #include <cpBaseQtApplication/ActorPolyDataProperties.h>
3 #include <cpBaseQtApplication/ui_ActorPolyDataProperties.h>
4 #include <QColorDialog>
7 #include <vtkProperty.h>
9 // -------------------------------------------------------------------------
10 cpBaseQtApplication::ActorPolyDataProperties::
11 ActorPolyDataProperties( QWidget* parent )
12 : cpBaseQtApplication::ActorProperties( parent ),
13 m_UI( new Ui::ActorPolyDataProperties )
15 this->m_UI->setupUi( this );
18 // -------------------------------------------------------------------------
19 cpBaseQtApplication::ActorPolyDataProperties::
20 ~ActorPolyDataProperties( )
25 // -------------------------------------------------------------------------
26 bool cpBaseQtApplication::ActorPolyDataProperties::
27 addActor( vtkProp* obj )
29 auto actor = dynamic_cast< vtkActor* >( obj );
32 this->m_Actors.insert( obj );
33 if( this->m_Actors.size( ) == 1 )
34 this->_updateWidgets( );
41 // -------------------------------------------------------------------------
42 void cpBaseQtApplication::ActorPolyDataProperties::
46 dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
51 auto mapp = actor->GetMapper( );
52 auto prop = actor->GetProperty( );
54 prop->GetColor( rgb );
55 rgb[ 0 ] *= double( 255 );
56 rgb[ 1 ] *= double( 255 );
57 rgb[ 2 ] *= double( 255 );
58 double op = prop->GetOpacity( );
59 double lw = prop->GetLineWidth( );
60 double ps = prop->GetPointSize( );
61 bool sv = ( mapp->GetScalarVisibility( ) == 1 );
62 int rep = prop->GetRepresentation( );
65 auto palette = this->m_UI->Color->palette( );
67 QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
69 this->m_UI->Color->setAutoFillBackground( true );
70 this->m_UI->Color->setPalette( palette );
72 op *= double( this->m_UI->Opacity->maximum( ) );
73 this->m_UI->Opacity->setValue( int( op ) );
74 this->m_UI->LineWidth->setValue( int( lw ) );
75 this->m_UI->PointSize->setValue( int( ps ) );
76 this->m_UI->ScalarVisibility->setChecked( sv );
78 if( rep == VTK_POINTS )
79 this->m_UI->Representation->setCurrentIndex( 0 );
80 else if( rep == VTK_WIREFRAME )
81 this->m_UI->Representation->setCurrentIndex( 1 );
82 else if( rep == VTK_SURFACE )
83 this->m_UI->Representation->setCurrentIndex( 2 );
87 this->m_UI->ScalarVisibility, SIGNAL( stateChanged( int ) ),
88 this, SLOT( _ScalarVisibility( int ) )
91 this->m_UI->Color, SIGNAL( clicked( ) ),
92 this, SLOT( _Color( ) )
95 this->m_UI->Opacity, SIGNAL( valueChanged( int ) ),
96 this, SLOT( _Opacity( int ) )
99 this->m_UI->LineWidth, SIGNAL( valueChanged( int ) ),
100 this, SLOT( _LineWidth( int ) )
103 this->m_UI->PointSize, SIGNAL( valueChanged( int ) ),
104 this, SLOT( _PointSize( int ) )
107 this->m_UI->Representation, SIGNAL( currentIndexChanged( int ) ),
108 this, SLOT( _Representation( int ) )
112 // -------------------------------------------------------------------------
113 void cpBaseQtApplication::ActorPolyDataProperties::
114 _ScalarVisibility( int v )
116 if( this->m_Actors.size( ) == 0 )
118 QPalette pal = this->m_UI->Color->palette( );
119 QColor color = pal.color( QPalette::Button );
121 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
122 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
123 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
125 auto aIt = this->m_Actors.begin( );
126 for( ; aIt != this->m_Actors.end( ); ++aIt )
128 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
129 if( !( this->m_UI->ScalarVisibility->isChecked( ) ) )
131 ma->GetMapper( )->ScalarVisibilityOff( );
132 ma->GetProperty( )->SetColor( rgb );
135 ma->GetMapper( )->ScalarVisibilityOn( );
142 // -------------------------------------------------------------------------
143 void cpBaseQtApplication::ActorPolyDataProperties::
146 if( this->m_Actors.size( ) == 0 )
148 QPalette pal = this->m_UI->Color->palette( );
150 QColorDialog::getColor(
151 pal.color( QPalette::Button ),
154 QColorDialog::DontUseNativeDialog
156 if( color.isValid( ) )
158 pal.setColor( QPalette::Button, color );
159 this->m_UI->Color->setAutoFillBackground( true );
160 this->m_UI->Color->setPalette( pal );
161 this->m_UI->Color->update( );
162 this->_ScalarVisibility( 0 );
167 // -------------------------------------------------------------------------
168 void cpBaseQtApplication::ActorPolyDataProperties::
171 double op = double( v ) / double( this->m_UI->Opacity->maximum( ) );
172 auto aIt = this->m_Actors.begin( );
173 for( ; aIt != this->m_Actors.end( ); ++aIt )
175 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
176 ma->GetProperty( )->SetOpacity( op );
183 // -------------------------------------------------------------------------
184 void cpBaseQtApplication::ActorPolyDataProperties::
187 auto aIt = this->m_Actors.begin( );
188 for( ; aIt != this->m_Actors.end( ); ++aIt )
190 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
191 ma->GetProperty( )->SetLineWidth( v );
198 // -------------------------------------------------------------------------
199 void cpBaseQtApplication::ActorPolyDataProperties::
202 auto aIt = this->m_Actors.begin( );
203 for( ; aIt != this->m_Actors.end( ); ++aIt )
205 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
206 ma->GetProperty( )->SetPointSize( v );
213 // -------------------------------------------------------------------------
214 void cpBaseQtApplication::ActorPolyDataProperties::
215 _Representation( int v )
217 int rep = VTK_POINTS + VTK_WIREFRAME + VTK_SURFACE;
218 if ( v == 0 ) rep = VTK_POINTS;
219 else if( v == 1 ) rep = VTK_WIREFRAME;
220 else if( v == 2 ) rep = VTK_SURFACE;
222 auto aIt = this->m_Actors.begin( );
223 for( ; aIt != this->m_Actors.end( ); ++aIt )
225 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
226 auto prop = ma->GetProperty( );
227 if( rep != VTK_POINTS && rep != VTK_WIREFRAME && rep != VTK_SURFACE )
230 prop->GetColor( rgb );
231 rgb[ 0 ] = double( 1 ) - rgb[ 0 ];
232 rgb[ 1 ] = double( 1 ) - rgb[ 1 ];
233 rgb[ 2 ] = double( 1 ) - rgb[ 2 ];
234 prop->SetRepresentation( VTK_SURFACE );
235 prop->SetEdgeColor( rgb );
236 prop->EdgeVisibilityOn( );
240 prop->EdgeVisibilityOff( );
241 prop->SetRepresentation( rep );