1 #include <cpPlugins/ActorPolyDataProperties.h>
5 #include <cpPlugins/ui_ActorPolyDataProperties.h>
6 #include <QColorDialog>
9 #include <vtkProperty.h>
11 // -------------------------------------------------------------------------
12 cpPlugins::ActorPolyDataProperties::
13 ActorPolyDataProperties( QWidget* parent )
14 : cpPlugins::ActorProperties( parent ),
15 m_UI( new Ui::ActorPolyDataProperties )
17 this->m_UI->setupUi( this );
20 // -------------------------------------------------------------------------
21 cpPlugins::ActorPolyDataProperties::
22 ~ActorPolyDataProperties( )
27 // -------------------------------------------------------------------------
28 bool cpPlugins::ActorPolyDataProperties::
29 addActor( vtkProp* obj )
31 auto actor = dynamic_cast< vtkActor* >( obj );
34 this->m_Actors.insert( obj );
35 if( this->m_Actors.size( ) == 1 )
36 this->_updateWidgets( );
43 // -------------------------------------------------------------------------
44 void cpPlugins::ActorPolyDataProperties::
48 dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
53 auto mapp = actor->GetMapper( );
54 auto prop = actor->GetProperty( );
56 prop->GetColor( rgb );
57 rgb[ 0 ] *= double( 255 );
58 rgb[ 1 ] *= double( 255 );
59 rgb[ 2 ] *= double( 255 );
60 double op = prop->GetOpacity( );
61 double lw = prop->GetLineWidth( );
62 double ps = prop->GetPointSize( );
63 bool sv = ( mapp->GetScalarVisibility( ) == 1 );
64 int rep = prop->GetRepresentation( );
67 auto palette = this->m_UI->Color->palette( );
69 QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
71 this->m_UI->Color->setAutoFillBackground( true );
72 this->m_UI->Color->setPalette( palette );
74 op *= double( this->m_UI->Opacity->maximum( ) );
75 this->m_UI->Opacity->setValue( int( op ) );
76 this->m_UI->LineWidth->setValue( int( lw ) );
77 this->m_UI->PointSize->setValue( int( ps ) );
78 this->m_UI->ScalarVisibility->setChecked( sv );
80 if( rep == VTK_POINTS )
81 this->m_UI->Representation->setCurrentIndex( 0 );
82 else if( rep == VTK_WIREFRAME )
83 this->m_UI->Representation->setCurrentIndex( 1 );
84 else if( rep == VTK_SURFACE )
85 this->m_UI->Representation->setCurrentIndex( 2 );
89 this->m_UI->ScalarVisibility, SIGNAL( stateChanged( int ) ),
90 this, SLOT( _ScalarVisibility( int ) )
93 this->m_UI->Color, SIGNAL( clicked( ) ),
94 this, SLOT( _Color( ) )
97 this->m_UI->Opacity, SIGNAL( valueChanged( int ) ),
98 this, SLOT( _Opacity( int ) )
101 this->m_UI->LineWidth, SIGNAL( valueChanged( int ) ),
102 this, SLOT( _LineWidth( int ) )
105 this->m_UI->PointSize, SIGNAL( valueChanged( int ) ),
106 this, SLOT( _PointSize( int ) )
109 this->m_UI->Representation, SIGNAL( currentIndexChanged( int ) ),
110 this, SLOT( _Representation( int ) )
114 // -------------------------------------------------------------------------
115 void cpPlugins::ActorPolyDataProperties::
116 _ScalarVisibility( int v )
118 if( this->m_Actors.size( ) == 0 )
120 QPalette pal = this->m_UI->Color->palette( );
121 QColor color = pal.color( QPalette::Button );
123 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
124 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
125 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
127 auto aIt = this->m_Actors.begin( );
128 for( ; aIt != this->m_Actors.end( ); ++aIt )
130 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
131 if( !( this->m_UI->ScalarVisibility->isChecked( ) ) )
133 ma->GetMapper( )->ScalarVisibilityOff( );
134 ma->GetProperty( )->SetColor( rgb );
137 ma->GetMapper( )->ScalarVisibilityOn( );
144 // -------------------------------------------------------------------------
145 void cpPlugins::ActorPolyDataProperties::
148 if( this->m_Actors.size( ) == 0 )
150 QPalette pal = this->m_UI->Color->palette( );
152 QColorDialog::getColor(
153 pal.color( QPalette::Button ),
156 QColorDialog::DontUseNativeDialog
158 if( color.isValid( ) )
160 pal.setColor( QPalette::Button, color );
161 this->m_UI->Color->setAutoFillBackground( true );
162 this->m_UI->Color->setPalette( pal );
163 this->m_UI->Color->update( );
164 this->_ScalarVisibility( 0 );
169 // -------------------------------------------------------------------------
170 void cpPlugins::ActorPolyDataProperties::
173 double op = double( v ) / double( this->m_UI->Opacity->maximum( ) );
174 auto aIt = this->m_Actors.begin( );
175 for( ; aIt != this->m_Actors.end( ); ++aIt )
177 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
178 ma->GetProperty( )->SetOpacity( op );
185 // -------------------------------------------------------------------------
186 void cpPlugins::ActorPolyDataProperties::
189 auto aIt = this->m_Actors.begin( );
190 for( ; aIt != this->m_Actors.end( ); ++aIt )
192 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
193 ma->GetProperty( )->SetLineWidth( v );
200 // -------------------------------------------------------------------------
201 void cpPlugins::ActorPolyDataProperties::
204 auto aIt = this->m_Actors.begin( );
205 for( ; aIt != this->m_Actors.end( ); ++aIt )
207 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
208 ma->GetProperty( )->SetPointSize( v );
215 // -------------------------------------------------------------------------
216 void cpPlugins::ActorPolyDataProperties::
217 _Representation( int v )
219 int rep = VTK_POINTS + VTK_WIREFRAME + VTK_SURFACE;
220 if ( v == 0 ) rep = VTK_POINTS;
221 else if( v == 1 ) rep = VTK_WIREFRAME;
222 else if( v == 2 ) rep = VTK_SURFACE;
224 auto aIt = this->m_Actors.begin( );
225 for( ; aIt != this->m_Actors.end( ); ++aIt )
227 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
228 auto prop = ma->GetProperty( );
229 if( rep != VTK_POINTS && rep != VTK_WIREFRAME && rep != VTK_SURFACE )
232 prop->GetColor( rgb );
233 rgb[ 0 ] = double( 1 ) - rgb[ 0 ];
234 rgb[ 1 ] = double( 1 ) - rgb[ 1 ];
235 rgb[ 2 ] = double( 1 ) - rgb[ 2 ];
236 prop->SetRepresentation( VTK_SURFACE );
237 prop->SetEdgeColor( rgb );
238 prop->EdgeVisibilityOn( );
242 prop->EdgeVisibilityOff( );
243 prop->SetRepresentation( rep );
252 #endif // cpPlugins_QT4