+#include <cpPlugins/ActorPolyDataProperties.h>
+
+#ifdef cpPlugins_QT4
+
+#include <cpPlugins/ui_ActorPolyDataProperties.h>
+#include <QColorDialog>
+#include <vtkActor.h>
+#include <vtkMapper.h>
+#include <vtkProperty.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::ActorPolyDataProperties::
+ActorPolyDataProperties( QWidget* parent )
+ : cpPlugins::ActorProperties( parent ),
+ m_UI( new Ui::ActorPolyDataProperties )
+{
+ this->m_UI->setupUi( this );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::ActorPolyDataProperties::
+~ActorPolyDataProperties( )
+{
+ delete this->m_UI;
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::ActorPolyDataProperties::
+addActor( vtkProp* obj )
+{
+ auto actor = dynamic_cast< vtkActor* >( obj );
+ if( actor != NULL )
+ {
+ this->m_Actors.insert( obj );
+ if( this->m_Actors.size( ) == 1 )
+ this->_updateWidgets( );
+ return( true );
+ }
+ else
+ return( false );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_updateWidgets( )
+{
+ auto actor =
+ dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
+ if( actor == NULL )
+ return;
+
+ // Get properties
+ auto mapp = actor->GetMapper( );
+ auto prop = actor->GetProperty( );
+ double rgb[ 3 ];
+ prop->GetColor( rgb );
+ rgb[ 0 ] *= double( 255 );
+ rgb[ 1 ] *= double( 255 );
+ rgb[ 2 ] *= double( 255 );
+ double op = prop->GetOpacity( );
+ double lw = prop->GetLineWidth( );
+ double ps = prop->GetPointSize( );
+ bool sv = ( mapp->GetScalarVisibility( ) == 1 );
+ int rep = prop->GetRepresentation( );
+
+ // Set widget values
+ auto palette = this->m_UI->Color->palette( );
+ palette.setColor(
+ QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] )
+ );
+ this->m_UI->Color->setAutoFillBackground( true );
+ this->m_UI->Color->setPalette( palette );
+
+ op *= double( this->m_UI->Opacity->maximum( ) );
+ this->m_UI->Opacity->setValue( int( op ) );
+ this->m_UI->LineWidth->setValue( int( lw ) );
+ this->m_UI->PointSize->setValue( int( ps ) );
+ this->m_UI->ScalarVisibility->setChecked( sv );
+
+ if( rep == VTK_POINTS )
+ this->m_UI->Representation->setCurrentIndex( 0 );
+ else if( rep == VTK_WIREFRAME )
+ this->m_UI->Representation->setCurrentIndex( 1 );
+ else if( rep == VTK_SURFACE )
+ this->m_UI->Representation->setCurrentIndex( 2 );
+
+ // Connect stuff
+ this->connect(
+ this->m_UI->ScalarVisibility, SIGNAL( stateChanged( int ) ),
+ this, SLOT( _ScalarVisibility( int ) )
+ );
+ this->connect(
+ this->m_UI->Color, SIGNAL( clicked( ) ),
+ this, SLOT( _Color( ) )
+ );
+ this->connect(
+ this->m_UI->Opacity, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _Opacity( int ) )
+ );
+ this->connect(
+ this->m_UI->LineWidth, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _LineWidth( int ) )
+ );
+ this->connect(
+ this->m_UI->PointSize, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _PointSize( int ) )
+ );
+ this->connect(
+ this->m_UI->Representation, SIGNAL( currentIndexChanged( int ) ),
+ this, SLOT( _Representation( int ) )
+ );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_ScalarVisibility( int v )
+{
+ if( this->m_Actors.size( ) == 0 )
+ return;
+ QPalette pal = this->m_UI->Color->palette( );
+ QColor color = pal.color( QPalette::Button );
+ double rgb[ 3 ];
+ rgb[ 0 ] = double( color.red( ) ) / double( 255 );
+ rgb[ 1 ] = double( color.green( ) ) / double( 255 );
+ rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
+
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
+ if( !( this->m_UI->ScalarVisibility->isChecked( ) ) )
+ {
+ ma->GetMapper( )->ScalarVisibilityOff( );
+ ma->GetProperty( )->SetColor( rgb );
+ }
+ else
+ ma->GetMapper( )->ScalarVisibilityOn( );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_Color( )
+{
+ if( this->m_Actors.size( ) == 0 )
+ return;
+ QPalette pal = this->m_UI->Color->palette( );
+ QColor color =
+ QColorDialog::getColor(
+ pal.color( QPalette::Button ),
+ this,
+ "Select Color",
+ QColorDialog::DontUseNativeDialog
+ );
+ if( color.isValid( ) )
+ {
+ pal.setColor( QPalette::Button, color );
+ this->m_UI->Color->setAutoFillBackground( true );
+ this->m_UI->Color->setPalette( pal );
+ this->m_UI->Color->update( );
+ this->_ScalarVisibility( 0 );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_Opacity( int v )
+{
+ double op = double( v ) / double( this->m_UI->Opacity->maximum( ) );
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetOpacity( op );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_LineWidth( int v )
+{
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetLineWidth( v );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_PointSize( int v )
+{
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetPointSize( v );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorPolyDataProperties::
+_Representation( int v )
+{
+ int rep = VTK_POINTS + VTK_WIREFRAME + VTK_SURFACE;
+ if ( v == 0 ) rep = VTK_POINTS;
+ else if( v == 1 ) rep = VTK_WIREFRAME;
+ else if( v == 2 ) rep = VTK_SURFACE;
+
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
+ auto prop = ma->GetProperty( );
+ if( rep != VTK_POINTS && rep != VTK_WIREFRAME && rep != VTK_SURFACE )
+ {
+ double rgb[ 3 ];
+ prop->GetColor( rgb );
+ rgb[ 0 ] = double( 1 ) - rgb[ 0 ];
+ rgb[ 1 ] = double( 1 ) - rgb[ 1 ];
+ rgb[ 2 ] = double( 1 ) - rgb[ 2 ];
+ prop->SetRepresentation( VTK_SURFACE );
+ prop->SetEdgeColor( rgb );
+ prop->EdgeVisibilityOn( );
+ }
+ else
+ {
+ prop->EdgeVisibilityOff( );
+ prop->SetRepresentation( rep );
+
+ } // fi
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+#endif // cpPlugins_QT4
+
+// eof - $RCSfile$