From: Leonardo Florez-Valencia Date: Sun, 12 Jun 2016 03:24:44 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~146 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=486e2fd13401f33b2349e023be1dfc01221b0ef3;p=cpPlugins.git ... --- diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index fe67abc..abe5bcb 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -3,6 +3,7 @@ #ifdef cpExtensions_QT4 #include +#include #include #include @@ -130,6 +131,7 @@ SetMainActor( vtkImageActor* actor, const std::string& name ) { this->Clear( ); vtkImageData* image = NULL; + int interp = actor->GetProperty( )->GetInterpolationType( ); for( unsigned int i = 0; i < 3; ++i ) { this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( ); @@ -160,6 +162,10 @@ SetMainActor( vtkImageActor* actor, const std::string& name ) this->m_NamedActors[ name ].insert( this->m_3DSlices[ i ]->GetImageActor( ) ); + this->m_2DSlices[ i ]->GetImageActor( )-> + GetProperty( )->SetInterpolationType( interp ); + this->m_3DSlices[ i ]->GetImageActor( )-> + GetProperty( )->SetInterpolationType( interp ); } // rof this->_AssociateSlices( ); diff --git a/lib/cpPlugins/ActorAxesProperties.cxx b/lib/cpPlugins/ActorAxesProperties.cxx new file mode 100644 index 0000000..9de5081 --- /dev/null +++ b/lib/cpPlugins/ActorAxesProperties.cxx @@ -0,0 +1,181 @@ +#include + +#ifdef cpPlugins_QT4 + +#include + +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::ActorAxesProperties:: +ActorAxesProperties( QWidget* parent ) + : cpPlugins::ActorProperties( parent ), + m_UI( new Ui::ActorAxesProperties ) +{ + this->m_UI->setupUi( this ); +} + +// ------------------------------------------------------------------------- +cpPlugins::ActorAxesProperties:: +~ActorAxesProperties( ) +{ + delete this->m_UI; +} + +// ------------------------------------------------------------------------- +bool cpPlugins::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 cpPlugins::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( )->GetProperty( ); + 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 cpPlugins::ActorAxesProperties:: +_Scale( double v ) +{ + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) + { + auto ma = dynamic_cast< vtkAxesActor* >( aIt->GetPointer( ) ); + ma->SetScale( v ); + ma->Modified( ); + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::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 cpPlugins::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( )->GetProperty( )->SetColor( rgb ); + ma->GetYAxisCaptionActor2D( )->GetProperty( )->SetColor( rgb ); + ma->GetZAxisCaptionActor2D( )->GetProperty( )->SetColor( rgb ); + ma->Modified( ); + + } // rof + this->_render( ); + + } // fi +} + +#endif // cpPlugins_QT4 + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorAxesProperties.h b/lib/cpPlugins/ActorAxesProperties.h new file mode 100644 index 0000000..244b597 --- /dev/null +++ b/lib/cpPlugins/ActorAxesProperties.h @@ -0,0 +1,50 @@ +#ifndef __CPPLUGINS__ACTORAXESPROPERTIES__H__ +#define __CPPLUGINS__ACTORAXESPROPERTIES__H__ + +#include + +#ifdef cpPlugins_QT4 + +#include + +// ------------------------------------------------------------------------- +namespace Ui +{ + class ActorAxesProperties; +} + +// ------------------------------------------------------------------------- +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT ActorAxesProperties + : public ActorProperties + { + Q_OBJECT; + + public: + explicit ActorAxesProperties( QWidget* parent = 0 ); + virtual ~ActorAxesProperties( ); + + virtual bool addActor( vtkProp* obj ) ITK_OVERRIDE; + + protected: + virtual void _updateWidgets( ) ITK_OVERRIDE; + + protected slots: + void _Scale( double v ); + void _TextChanged( const QString& text ); + void _TextColor( ); + + protected: + Ui::ActorAxesProperties* m_UI; + }; + +} // ecapseman + +#endif // cpPlugins_QT4 + +#endif // __CPPLUGINS__ACTORAXESPROPERTIES__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorAxesProperties.ui b/lib/cpPlugins/ActorAxesProperties.ui new file mode 100644 index 0000000..078f1bb --- /dev/null +++ b/lib/cpPlugins/ActorAxesProperties.ui @@ -0,0 +1,157 @@ + + + ActorAxesProperties + + + + 0 + 0 + 339 + 223 + + + + + 339 + 223 + + + + + 339 + 223 + + + + Form + + + + + + + + + 39 + 17 + + + + + 39 + 17 + + + + Scale: + + + + + + + 4 + + + 0.000100000000000 + + + 100000.000000000000000 + + + 1.000000000000000 + + + + + + + + + + + + 44 + 17 + + + + + 44 + 17 + + + + X text: + + + + + + + + + + + + + + + 44 + 17 + + + + + 44 + 17 + + + + Y text: + + + + + + + + + + + + + + + 43 + 17 + + + + + 43 + 17 + + + + Z text: + + + + + + + + + + + + Text color + + + + + + + + diff --git a/lib/cpPlugins/ActorImageProperties.cxx b/lib/cpPlugins/ActorImageProperties.cxx new file mode 100644 index 0000000..7ff91d0 --- /dev/null +++ b/lib/cpPlugins/ActorImageProperties.cxx @@ -0,0 +1,245 @@ +#include + +#ifdef cpPlugins_QT4 + +#include + +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::ActorImageProperties:: +ActorImageProperties( QWidget* parent ) + : cpPlugins::ActorProperties( parent ), + m_UI( new Ui::ActorImageProperties ) +{ + this->m_UI->setupUi( this ); +} + +// ------------------------------------------------------------------------- +cpPlugins::ActorImageProperties:: +~ActorImageProperties( ) +{ + delete this->m_UI; +} + +// ------------------------------------------------------------------------- +bool cpPlugins::ActorImageProperties:: +addActor( vtkProp* obj ) +{ + auto actor = dynamic_cast< vtkImageActor* >( obj ); + if( actor != NULL ) + { + this->m_Actors.insert( obj ); + if( this->m_Actors.size( ) == 1 ) + this->_updateWidgets( ); + return( true ); + } + else + return( false ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_updateWidgets( ) +{ + auto actor = + dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) ); + if( actor == NULL ) + return; + + // Get properties + auto prop = actor->GetProperty( ); + auto mapper = actor->GetMapper( ); + auto image = mapper->GetInput( ); + double r[ 2 ]; + image->GetScalarRange( r ); + double win = prop->GetColorWindow( ); + double lev = prop->GetColorLevel( ); + double op = prop->GetOpacity( ); + int interp = prop->GetInterpolationType( ); + + this->m_UI->ValueWindow->setMinimum( 0 ); + this->m_UI->ValueWindow->setMaximum( r[ 1 ] - r[ 0 ] ); + this->m_UI->ValueLevel->setMinimum( r[ 0 ] ); + this->m_UI->ValueLevel->setMaximum( r[ 1 ] ); + this->m_UI->ValueWindow->setValue( win ); + this->m_UI->ValueLevel->setValue( lev ); + + double w = win / ( r[ 1 ] - r[ 0 ] ); + double l = ( lev - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] ); + + op *= double( this->m_UI->Opacity->maximum( ) ); + this->m_UI->Opacity->setValue( int( op ) ); + + w *= double( this->m_UI->Window->maximum( ) ); + this->m_UI->Window->setValue( int( w ) ); + + l *= double( this->m_UI->Level->maximum( ) ); + this->m_UI->Level->setValue( int( l ) ); + + if( interp == VTK_CUBIC_INTERPOLATION ) + this->m_UI->Interpolation->setCurrentIndex( 0 ); + else if( interp == VTK_LINEAR_INTERPOLATION ) + this->m_UI->Interpolation->setCurrentIndex( 1 ); + else if( interp == VTK_NEAREST_INTERPOLATION ) + this->m_UI->Interpolation->setCurrentIndex( 2 ); + + // Connect stuff + this->connect( + this->m_UI->Opacity, SIGNAL( valueChanged( int ) ), + this, SLOT( _Opacity( int ) ) + ); + this->connect( + this->m_UI->Window, SIGNAL( valueChanged( int ) ), + this, SLOT( _Window( int ) ) + ); + this->connect( + this->m_UI->Level, SIGNAL( valueChanged( int ) ), + this, SLOT( _Level( int ) ) + ); + this->connect( + this->m_UI->ValueWindow, SIGNAL( valueChanged( double ) ), + this, SLOT( _Window( double ) ) + ); + this->connect( + this->m_UI->ValueLevel, SIGNAL( valueChanged( double ) ), + this, SLOT( _Level( double ) ) + ); + this->connect( + this->m_UI->Interpolation, SIGNAL( currentIndexChanged( int ) ), + this, SLOT( _Interpolation( int ) ) + ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_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< vtkImageActor* >( aIt->GetPointer( ) ); + ma->GetProperty( )->SetOpacity( op ); + ma->Modified( ); + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_Window( int v ) +{ + double x = this->m_UI->ValueWindow->minimum( ); + double y = this->m_UI->ValueWindow->maximum( ); + double z = double( v ) / double( this->m_UI->Window->maximum( ) ); + double w = ( ( y - x ) * z ) + x; + bool prev = this->m_UI->ValueWindow->blockSignals( true ); + this->m_UI->ValueWindow->setValue( w ); + this->m_UI->ValueWindow->blockSignals( prev ); + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) + { + auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); + ma->GetProperty( )->SetColorWindow( w ); + ma->Modified( ); + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_Level( int v ) +{ + double x = this->m_UI->ValueLevel->minimum( ); + double y = this->m_UI->ValueLevel->maximum( ); + double z = double( v ) / double( this->m_UI->Level->maximum( ) ); + double l = ( ( y - x ) * z ) + x; + bool prev = this->m_UI->ValueLevel->blockSignals( true ); + this->m_UI->ValueLevel->setValue( l ); + this->m_UI->ValueLevel->blockSignals( prev ); + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) + { + auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); + ma->GetProperty( )->SetColorLevel( l ); + ma->Modified( ); + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_Window( double v ) +{ + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) + { + auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); + ma->GetProperty( )->SetColorWindow( v ); + ma->Modified( ); + + } // rof + this->_render( ); + + double x = this->m_UI->ValueWindow->minimum( ); + double y = this->m_UI->ValueWindow->maximum( ); + double z = ( v - x ) / ( y - x ); + double w = double( z ) * double( this->m_UI->Window->maximum( ) ); + bool prev = this->m_UI->Window->blockSignals( true ); + this->m_UI->Window->setValue( int( w ) ); + this->m_UI->Window->blockSignals( prev ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_Level( double v ) +{ + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) + { + auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); + ma->GetProperty( )->SetColorLevel( v ); + ma->Modified( ); + + } // rof + this->_render( ); + + double x = this->m_UI->ValueLevel->minimum( ); + double y = this->m_UI->ValueLevel->maximum( ); + double z = ( v - x ) / ( y - x ); + double l = double( z ) * double( this->m_UI->Level->maximum( ) ); + bool prev = this->m_UI->Level->blockSignals( true ); + this->m_UI->Level->setValue( int( l ) ); + this->m_UI->Level->blockSignals( prev ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorImageProperties:: +_Interpolation( int v ) +{ + int interp = VTK_NEAREST_INTERPOLATION; + if ( v == 0 ) interp = VTK_CUBIC_INTERPOLATION; + else if( v == 1 ) interp = VTK_LINEAR_INTERPOLATION; + else if( v == 2 ) interp = VTK_NEAREST_INTERPOLATION; + + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) + { + auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); + ma->GetProperty( )->SetInterpolationType( interp ); + ma->Modified( ); + + } // rof + this->_render( ); +} + +#endif // cpPlugins_QT4 + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorImageProperties.h b/lib/cpPlugins/ActorImageProperties.h new file mode 100644 index 0000000..5c55562 --- /dev/null +++ b/lib/cpPlugins/ActorImageProperties.h @@ -0,0 +1,53 @@ +#ifndef __CPPLUGINS__ACTORIMAGEPROPERTIES__H__ +#define __CPPLUGINS__ACTORIMAGEPROPERTIES__H__ + +#include + +#ifdef cpPlugins_QT4 + +#include + +// ------------------------------------------------------------------------- +namespace Ui +{ + class ActorImageProperties; +} + +// ------------------------------------------------------------------------- +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT ActorImageProperties + : public ActorProperties + { + Q_OBJECT; + + public: + explicit ActorImageProperties( QWidget* parent = 0 ); + virtual ~ActorImageProperties( ); + + virtual bool addActor( vtkProp* obj ) ITK_OVERRIDE; + + protected: + virtual void _updateWidgets( ) ITK_OVERRIDE; + + protected slots: + void _Opacity( int v ); + void _Window( int v ); + void _Level( int v ); + void _Window( double v ); + void _Level( double v ); + void _Interpolation( int v ); + + protected: + Ui::ActorImageProperties* m_UI; + }; + +} // ecapseman + +#endif // cpPlugins_QT4 + +#endif // __CPPLUGINS__ACTORIMAGEPROPERTIES__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorImageProperties.ui b/lib/cpPlugins/ActorImageProperties.ui new file mode 100644 index 0000000..249a055 --- /dev/null +++ b/lib/cpPlugins/ActorImageProperties.ui @@ -0,0 +1,215 @@ + + + ActorImageProperties + + + + 0 + 0 + 626 + 158 + + + + + 626 + 158 + + + + + 626 + 158 + + + + Form + + + + + + + + + 92 + 17 + + + + + 92 + 17 + + + + Interpolation: + + + + + + + + Cubic + + + + + Linear + + + + + Nearest + + + + + + + + + + + + + 59 + 17 + + + + + 59 + 17 + + + + Window: + + + + + + + 4 + + + -100000.000000000000000 + + + 100000.000000000000000 + + + + + + + 0 + + + 1000 + + + 0 + + + Qt::Horizontal + + + + + + + + + + + + 39 + 17 + + + + + 39 + 17 + + + + Level: + + + + + + + 4 + + + -100000.000000000000000 + + + 100000.000000000000000 + + + + + + + 0 + + + 1000 + + + 0 + + + Qt::Horizontal + + + + + + + + + + + + 55 + 17 + + + + + 55 + 17 + + + + Opacity: + + + + + + + 100 + + + 100 + + + Qt::Horizontal + + + + + + + + + + diff --git a/lib/cpPlugins/ActorPolyDataProperties.cxx b/lib/cpPlugins/ActorPolyDataProperties.cxx new file mode 100644 index 0000000..5fd9fe1 --- /dev/null +++ b/lib/cpPlugins/ActorPolyDataProperties.cxx @@ -0,0 +1,254 @@ +#include + +#ifdef cpPlugins_QT4 + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +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$ diff --git a/lib/cpPlugins/ActorPolyDataProperties.h b/lib/cpPlugins/ActorPolyDataProperties.h new file mode 100644 index 0000000..457ee50 --- /dev/null +++ b/lib/cpPlugins/ActorPolyDataProperties.h @@ -0,0 +1,53 @@ +#ifndef __CPPLUGINS__ACTORPOLYDATAPROPERTIES__H__ +#define __CPPLUGINS__ACTORPOLYDATAPROPERTIES__H__ + +#include + +#ifdef cpPlugins_QT4 + +#include + +// ------------------------------------------------------------------------- +namespace Ui +{ + class ActorPolyDataProperties; +} + +// ------------------------------------------------------------------------- +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT ActorPolyDataProperties + : public ActorProperties + { + Q_OBJECT; + + public: + explicit ActorPolyDataProperties( QWidget* parent = 0 ); + virtual ~ActorPolyDataProperties( ); + + virtual bool addActor( vtkProp* obj ) ITK_OVERRIDE; + + protected: + virtual void _updateWidgets( ) ITK_OVERRIDE; + + protected slots: + void _ScalarVisibility( int v ); + void _Color( ); + void _Opacity( int v ); + void _LineWidth( int v ); + void _PointSize( int v ); + void _Representation( int v ); + + protected: + Ui::ActorPolyDataProperties* m_UI; + }; + +} // ecapseman + +#endif // cpPlugins_QT4 + +#endif // __CPPLUGINS__ACTORPOLYDATAPROPERTIES__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorPolyDataProperties.ui b/lib/cpPlugins/ActorPolyDataProperties.ui new file mode 100644 index 0000000..08ec1a8 --- /dev/null +++ b/lib/cpPlugins/ActorPolyDataProperties.ui @@ -0,0 +1,233 @@ + + + ActorPolyDataProperties + + + + 0 + 0 + 398 + 193 + + + + + 398 + 193 + + + + + 398 + 193 + + + + Form + + + + + + + + + 107 + 17 + + + + + 107 + 17 + + + + Representation: + + + + + + + + Points + + + + + Wireframe + + + + + Surface + + + + + Surface with edges + + + + + + + + + + + + + 73 + 17 + + + + + 73 + 17 + + + + Line width: + + + + + + + 1 + + + 10 + + + 1 + + + Qt::Horizontal + + + + + + + + + + + + 68 + 17 + + + + + 68 + 17 + + + + Point size: + + + + + + + 1 + + + 10 + + + Qt::Horizontal + + + + + + + + + + + + 55 + 17 + + + + + 55 + 17 + + + + Opacity: + + + + + + + 100 + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + 135 + 22 + + + + + 135 + 22 + + + + Scalar visibility? + + + + + + + + 98 + 27 + + + + + 16777215 + 27 + + + + Color + + + + + + + + + + diff --git a/lib/cpPlugins/ActorProperties.cxx b/lib/cpPlugins/ActorProperties.cxx new file mode 100644 index 0000000..eeb2de1 --- /dev/null +++ b/lib/cpPlugins/ActorProperties.cxx @@ -0,0 +1,38 @@ +#include + +#ifdef cpPlugins_QT4 + +// ------------------------------------------------------------------------- +cpPlugins::ActorProperties:: +ActorProperties( QWidget* parent ) + : QWidget( parent ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::ActorProperties:: +~ActorProperties( ) +{ +} + +// ------------------------------------------------------------------------- +bool cpPlugins::ActorProperties:: +addRenderWindow( vtkRenderWindow* win ) +{ + if( win == NULL ) + return( false ); + this->m_Windows.insert( win ); + return( true ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::ActorProperties:: +_render( ) +{ + for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i ) + ( *i )->Render( ); +} + +#endif // cpPlugins_QT4 + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorProperties.h b/lib/cpPlugins/ActorProperties.h new file mode 100644 index 0000000..9bf68e4 --- /dev/null +++ b/lib/cpPlugins/ActorProperties.h @@ -0,0 +1,60 @@ +#ifndef __CPPLUGINS__ACTORPROPERTIES__H__ +#define __CPPLUGINS__ACTORPROPERTIES__H__ + +#include + +#ifdef cpPlugins_QT4 + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT ActorProperties + : public QWidget + { + Q_OBJECT; + + public: + template< class _TObj > + struct TCmp + { + bool operator()( + const vtkSmartPointer< _TObj >& a, + const vtkSmartPointer< _TObj >& b ) const + { return( a.GetPointer( ) < b.GetPointer( ) ); } + }; + typedef vtkSmartPointer< vtkProp > TActor; + typedef vtkSmartPointer< vtkRenderWindow > TRenderWindow; + typedef std::set< TActor, TCmp< vtkProp > > TActors; + typedef std::set< TRenderWindow, TCmp< vtkRenderWindow > > TWindows; + + public: + explicit ActorProperties( QWidget* parent = 0 ); + virtual ~ActorProperties( ); + + virtual bool addActor( vtkProp* obj ) = 0; + bool addRenderWindow( vtkRenderWindow* win ); + void _render( ); + + protected: + virtual void _updateWidgets( ) = 0; + + protected: + TActors m_Actors; + TWindows m_Windows; + }; + +} // ecapseman + +#endif // cpPlugins_QT4 + +#endif // __CPPLUGINS__ACTORPROPERTIES__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/ActorPropertiesQtDialog.cxx b/lib/cpPlugins/ActorPropertiesQtDialog.cxx index 87b41c6..d126c3f 100644 --- a/lib/cpPlugins/ActorPropertiesQtDialog.cxx +++ b/lib/cpPlugins/ActorPropertiesQtDialog.cxx @@ -2,25 +2,31 @@ #ifdef cpPlugins_QT4 +#include +#include +#include + #include #include #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include +/* + #include + #include + #include + #include + + #include + #include + #include + #include + #include +*/ // ------------------------------------------------------------------------- cpPlugins::ActorPropertiesQtDialog:: ActorPropertiesQtDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ), - m_WidgetsUpdated( false ) + m_MainWidget( NULL ) { this->m_Title = new QLabel( this ); this->m_Title->setText( "Visualization properties" ); @@ -34,52 +40,75 @@ ActorPropertiesQtDialog( QWidget* parent, Qt::WindowFlags f ) cpPlugins::ActorPropertiesQtDialog:: ~ActorPropertiesQtDialog( ) { - this->m_Actors.clear( ); - this->m_Windows.clear( ); - delete this->m_Title; - delete this->m_ToolsLayout; - delete this->m_MainLayout; } // ------------------------------------------------------------------------- bool cpPlugins::ActorPropertiesQtDialog:: addActor( vtkProp* obj ) { - if( obj == NULL ) - return( false ); - - if( this->m_Actors.size( ) > 0 ) - { - bool s = this->_addActor< vtkAxesActor >( obj ); - if( !s ) s = this->_addActor< vtkImageActor >( obj ); - if( !s ) s = this->_addActor< vtkActor >( obj ); - return( s ); - } - else + if( this->m_MainWidget == NULL ) { - this->m_Actors.insert( obj ); - this->m_WidgetsUpdated = false; - return( true ); + std::stringstream title; + title << "Parameters for an object of class"; + auto mesh = dynamic_cast< vtkActor* >( obj ); + auto axes = dynamic_cast< vtkAxesActor* >( obj ); + auto image = dynamic_cast< vtkImageActor* >( obj ); + if( mesh != NULL ) + { + title << "\"Mesh\""; + this->m_MainWidget = new cpPlugins::ActorPolyDataProperties( this ); + } + else if( axes != NULL ) + { + title << "\"Axes\""; + this->m_MainWidget = new cpPlugins::ActorAxesProperties( this ); + } + else if( image != NULL ) + { + title << "\"Image\""; + this->m_MainWidget = new cpPlugins::ActorImageProperties( this ); + } + /* TODO + else if( axes != NULL ) + */ + + if( this->m_MainWidget != NULL ) + { + this->m_Title->setText( title.str( ).c_str( ) ); + this->m_ToolsLayout->addWidget( this->m_MainWidget ); + this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok ); + this->connect( + this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) + ); + this->connect( + this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) + ); + this->m_ToolsLayout->addWidget( this->m_Buttons ); + + } // fi } // fi + + if( this->m_MainWidget != NULL ) + return( this->m_MainWidget->addActor( obj ) ); + else + return( false ); } // ------------------------------------------------------------------------- bool cpPlugins::ActorPropertiesQtDialog:: addRenderWindow( vtkRenderWindow* win ) { - if( win == NULL ) + if( this->m_MainWidget != NULL && win != NULL ) + return( this->m_MainWidget->addRenderWindow( win ) ); + else return( false ); - this->m_Windows.insert( win ); - this->m_WidgetsUpdated = false; - return( true ); } // ------------------------------------------------------------------------- int cpPlugins::ActorPropertiesQtDialog:: exec( ) { - this->_updateWidgets( ); int ret = this->QDialog::exec( ); /* TODO if( ret == 1 ) @@ -91,6 +120,7 @@ exec( ) } // ------------------------------------------------------------------------- +/* TODO void cpPlugins::ActorPropertiesQtDialog:: _addButtons( ) { @@ -134,26 +164,6 @@ _configureForAxes( ) title << "Parameters for an object of class \"Axes\""; this->m_Title->setText( title.str( ).c_str( ) ); - /* - vtkAxesActor axes - 178 axes SetShaftTypeToCylinder - 179 axes SetXAxisLabelText "x" - 180 axes SetYAxisLabelText "y" - 181 axes SetZAxisLabelText "z" - 182 axes SetTotalLength 1.5 1.5 1.5 - 183 vtkTextProperty tprop - 184 tprop ItalicOn - 185 tprop ShadowOn - 186 tprop SetFontFamilyToTimes - 187 [ axes GetXAxisCaptionActor2D ] SetCaptionTextProperty tprop - 188 vtkTextProperty tprop2 - 189 tprop2 ShallowCopy tprop - 190 [ axes GetYAxisCaptionActor2D ] SetCaptionTextProperty tprop2 - 191 vtkTextProperty tprop3 - 192 tprop3 ShallowCopy tprop - 193 [ axes GetZAxisCaptionActor2D ] SetCaptionTextProperty tprop3 - */ - return( true ); } @@ -672,6 +682,7 @@ _color( ) } // fi } +*/ #endif // cpPlugins_QT4 diff --git a/lib/cpPlugins/ActorPropertiesQtDialog.h b/lib/cpPlugins/ActorPropertiesQtDialog.h index ca45b57..394fc6e 100644 --- a/lib/cpPlugins/ActorPropertiesQtDialog.h +++ b/lib/cpPlugins/ActorPropertiesQtDialog.h @@ -1,23 +1,25 @@ #ifndef __CPPLUGINS__ACTORPROPERTIESQTDIALOG__H__ #define __CPPLUGINS__ACTORPROPERTIESQTDIALOG__H__ -#include +#include #ifdef cpPlugins_QT4 -#include -#include -#include -#include - -#include #include #include #include #include #include +/* + #include + #include + #include + #include + + #include -class vtkProp; + class vtkProp; +*/ namespace cpPlugins { @@ -28,20 +30,6 @@ namespace cpPlugins { Q_OBJECT; - public: - template< class _TObj > - struct TCmp - { - bool operator()( - const vtkSmartPointer< _TObj >& a, - const vtkSmartPointer< _TObj >& b ) const - { return( a.GetPointer( ) < b.GetPointer( ) ); } - }; - typedef vtkSmartPointer< vtkProp > TActor; - typedef vtkSmartPointer< vtkRenderWindow > TRenderWindow; - typedef std::set< TActor, TCmp< vtkProp > > TActors; - typedef std::set< TRenderWindow, TCmp< vtkRenderWindow > > TWindows; - public: ActorPropertiesQtDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 @@ -53,30 +41,32 @@ namespace cpPlugins virtual int exec( ); protected: - virtual void _addButtons( ); - virtual void _updateWidgets( ); - - virtual bool _configureForAxes( ); - virtual bool _configureForImage( ); - virtual bool _configureForMesh( ); - - void _setWindow( double w ); - void _setLevel( double l ); - void _render( ); - - template< class _TActor > - inline bool _addActor( vtkProp* obj ); - - protected slots: - void _boxWindow( double v ); - void _sldWindow( int v ); - void _boxLevel( double v ); - void _sldLevel( int v ); - void _sldOpacity( int v ); - void _boxPointSize( int v ); - void _boxLineWidth( int v ); - void _scalarVisibility( int v ); - void _color( ); + /* TODO + virtual void _addButtons( ); + virtual void _updateWidgets( ); + + virtual bool _configureForAxes( ); + virtual bool _configureForImage( ); + virtual bool _configureForMesh( ); + + void _setWindow( double w ); + void _setLevel( double l ); + void _render( ); + + template< class _TActor > + inline bool _addActor( vtkProp* obj ); + + protected slots: + void _boxWindow( double v ); + void _sldWindow( int v ); + void _boxLevel( double v ); + void _sldLevel( int v ); + void _sldOpacity( int v ); + void _boxPointSize( int v ); + void _boxLineWidth( int v ); + void _scalarVisibility( int v ); + void _color( ); + */ /* TODO virtual void updateParameters( ); @@ -97,9 +87,7 @@ namespace cpPlugins */ protected: - TActors m_Actors; - TWindows m_Windows; - bool m_WidgetsUpdated; + cpPlugins::ActorProperties* m_MainWidget; QLabel* m_Title; QGridLayout* m_MainLayout; QVBoxLayout* m_ToolsLayout; diff --git a/lib/cpPlugins/CMakeLists.txt b/lib/cpPlugins/CMakeLists.txt index d06bf10..bb3bdb9 100644 --- a/lib/cpPlugins/CMakeLists.txt +++ b/lib/cpPlugins/CMakeLists.txt @@ -29,14 +29,25 @@ FILE(GLOB lib_SOURCES_CXX "*.cxx") IF(USE_QT4) SET( lib_QT_UI + ActorAxesProperties.ui + ActorImageProperties.ui + ActorPolyDataProperties.ui ) SET( lib_QT_Headers + ActorProperties.h + ActorAxesProperties.h + ActorImageProperties.h + ActorPolyDataProperties.h ActorPropertiesQtDialog.h ParametersQtDialog.h ) SET( lib_QT_Sources + ActorProperties.cxx + ActorAxesProperties.cxx + ActorImageProperties.cxx + ActorPolyDataProperties.cxx ActorPropertiesQtDialog.cxx ParametersQtDialog.cxx ) diff --git a/lib/cpPlugins/Image.cxx b/lib/cpPlugins/Image.cxx index 4d9cbd8..261d966 100644 --- a/lib/cpPlugins/Image.cxx +++ b/lib/cpPlugins/Image.cxx @@ -1,6 +1,7 @@ #include #include +#include #include // ------------------------------------------------------------------------- @@ -53,6 +54,7 @@ _CreateVTKActor( ) const vtkImageActor* actor = vtkImageActor::New( ); mapper->SetInputData( image ); actor->SetMapper( mapper ); + actor->GetProperty( )->SetInterpolationTypeToNearest( ); this->m_Actor = actor; mapper->Delete( );