#include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpBaseQtApplication::ActorAxesProperties:: ActorAxesProperties( QWidget* parent ) : cpBaseQtApplication::ActorProperties( parent ), m_UI( new Ui::ActorAxesProperties ) { this->m_UI->setupUi( this ); } // ------------------------------------------------------------------------- cpBaseQtApplication::ActorAxesProperties:: ~ActorAxesProperties( ) { delete this->m_UI; } // ------------------------------------------------------------------------- bool cpBaseQtApplication::ActorAxesProperties:: addActor( vtkProp* obj ) { auto actor = dynamic_cast< vtkAxesActor* >( obj ); if( actor != NULL ) { this->m_Actors.insert( obj ); if( this->m_Actors.size( ) == 1 ) this->_updateWidgets( ); return( true ); } else return( false ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorAxesProperties:: _updateWidgets( ) { auto actor = dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( actor == NULL ) return; // Get properties std::string xtext( actor->GetXAxisLabelText( ) ); std::string ytext( actor->GetYAxisLabelText( ) ); std::string ztext( actor->GetZAxisLabelText( ) ); double scale = actor->GetScale( )[ 0 ]; auto prop = actor->GetXAxisCaptionActor2D( )->GetCaptionTextProperty( ); double rgb[ 3 ]; prop->GetColor( rgb ); rgb[ 0 ] *= double( 255 ); rgb[ 1 ] *= double( 255 ); rgb[ 2 ] *= double( 255 ); // Set widget values auto palette = this->m_UI->TextColor->palette( ); palette.setColor( QPalette::Button, QColor( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] ) ); this->m_UI->TextColor->setAutoFillBackground( true ); this->m_UI->TextColor->setPalette( palette ); this->m_UI->XText->setText( xtext.c_str( ) ); this->m_UI->YText->setText( ytext.c_str( ) ); this->m_UI->ZText->setText( ztext.c_str( ) ); this->m_UI->Scale->setValue( scale ); // Connect stuff this->connect( this->m_UI->Scale, SIGNAL( valueChanged( double ) ), this, SLOT( _Scale( double ) ) ); this->connect( this->m_UI->XText, SIGNAL( textChanged( const QString& ) ), this, SLOT( _TextChanged( const QString& ) ) ); this->connect( this->m_UI->YText, SIGNAL( textChanged( const QString& ) ), this, SLOT( _TextChanged( const QString& ) ) ); this->connect( this->m_UI->ZText, SIGNAL( textChanged( const QString& ) ), this, SLOT( _TextChanged( const QString& ) ) ); this->connect( this->m_UI->TextColor, SIGNAL( clicked( ) ), this, SLOT( _TextColor( ) ) ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorAxesProperties:: _Scale( double v ) { itk::Vector< double, 3 > x, y, z; auto aIt = this->m_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) ); auto matrix = ma->GetUserMatrix( ); for( unsigned int d = 0; d < 3; ++d ) { x[ d ] = matrix->GetElement( d, 0 ); y[ d ] = matrix->GetElement( d, 1 ); z[ d ] = matrix->GetElement( d, 2 ); } // rof auto nx = x.GetNorm( ); auto ny = y.GetNorm( ); auto nz = z.GetNorm( ); if( nx > double( 0 ) ) x /= nx; if( ny > double( 0 ) ) y /= ny; if( nz > double( 0 ) ) z /= nz; x *= v; y *= v; z *= v; for( unsigned int d = 0; d < 3; ++d ) { matrix->SetElement( d, 0, x[ d ] ); matrix->SetElement( d, 1, y[ d ] ); matrix->SetElement( d, 2, z[ d ] ); } // rof ma->Modified( ); } // rof this->_render( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorAxesProperties:: _TextChanged( const QString& text ) { auto obj = this->sender( ); auto aIt = this->m_Actors.begin( ); auto str = text.toStdString( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) ); if( obj == this->m_UI->XText ) ma->SetXAxisLabelText( str.c_str( ) ); else if( obj == this->m_UI->YText ) ma->SetYAxisLabelText( str.c_str( ) ); else if( obj == this->m_UI->ZText ) ma->SetZAxisLabelText( str.c_str( ) ); ma->Modified( ); } // rof this->_render( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorAxesProperties:: _TextColor( ) { if( this->m_Actors.size( ) == 0 ) return; QPalette pal = this->m_UI->TextColor->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->TextColor->setAutoFillBackground( true ); this->m_UI->TextColor->setPalette( pal ); this->m_UI->TextColor->update( ); 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< vtkAxesActor* >( aIt->GetPointer( ) ); ma->GetXAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb ); ma->GetYAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb ); ma->GetZAxisCaptionActor2D( )->GetCaptionTextProperty( )->SetColor( rgb ); ma->GetXAxisCaptionActor2D( )->Modified( ); ma->GetYAxisCaptionActor2D( )->Modified( ); ma->GetZAxisCaptionActor2D( )->Modified( ); ma->Modified( ); } // rof this->_render( ); } // fi } // eof - $RCSfile$