From: ouv Date: Mon, 16 Apr 2012 09:54:58 +0000 (+0000) Subject: IPAL22901: Extending functionality of setting gradient and textured background of... X-Git-Tag: TRIPOLI_323~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=232dae19e7eb0f2b0115a377f29fc24264aea359;p=modules%2Fgui.git IPAL22901: Extending functionality of setting gradient and textured background of the VTK viewer Part 2: gradient background. --- diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index aaaea4eff..4ded57c09 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -103,8 +103,22 @@ SVTK_Viewer::~SVTK_Viewer() /*! Get data for supported background modes: gradient types, identifiers and supported image formats */ QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList ) { - gradList << tr( "GT_VERTICALGRADIENT" ); // only vertical type of gradient is supported - idList << VerticalGradient; // only vertical type of gradient is supported + gradList << tr( "GT_HORIZONTALGRADIENT" ) + << tr( "GT_VERTICALGRADIENT" ) + << tr( "GT_FIRSTDIAGONALGRADIENT" ) + << tr( "GT_SECONDDIAGONALGRADIENT" ) + << tr( "GT_FIRSTCORNERGRADIENT" ) + << tr( "GT_SECONDCORNERGRADIENT" ) + << tr( "GT_THIRDCORNERGRADIENT" ) + << tr( "GT_FOURTHCORNERGRADIENT" ); + idList << HorizontalGradient + << VerticalGradient + << FirstDiagonalGradient + << SecondDiagonalGradient + << FirstCornerGradient + << SecondCornerGradient + << ThirdCornerGradient + << FourthCornerGradient; #ifdef VTK_ENABLE_TEXTURED_BACKGROUND txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture; #endif diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index 81aa01310..b06714265 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -48,8 +48,15 @@ class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View public: /*! supported gradient types */ enum { + HorizontalGradient, VerticalGradient, - LastGradient = VerticalGradient, + FirstDiagonalGradient, + SecondDiagonalGradient, + FirstCornerGradient, + SecondCornerGradient, + ThirdCornerGradient, + FourthCornerGradient, + LastGradient = FourthCornerGradient, }; typedef SVTK_ViewWindow TViewWindow; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 44227e2e3..3a81fc72a 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -27,6 +27,7 @@ #include "SVTK_ViewParameterDlg.h" #include "SVTK_ViewModel.h" #include "VTKViewer_Texture.h" +#include "VTKViewer_OpenGLRenderer.h" #include "SALOME_Actor.h" @@ -591,28 +592,28 @@ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) } case Qtx::SimpleGradientBackground: { - QColor c1, c2; - int type = bgData.gradient( c1, c2 ); - // VSR: Currently, only vertical gradient is supported by VTK. - // In future, switch operator might be added here to process different supported gradient types. - if ( c1.isValid() && type == SVTK_Viewer::VerticalGradient ) { - if ( !c2.isValid() ) c2 = c1; - // show two-color gradient background - getRenderer()->SetTexturedBackground( false ); // cancel texture mode - getRenderer()->SetGradientBackground( true ); // switch to gradient mode - // VSR: In VTK, gradient is colored from bottom to top: - // - top color is set via SetBackground2() - // - bottom color is set via SetBackground() - // So, we reverse colors, to draw gradient from top to bottom instead. - getRenderer()->SetBackground( c2.red()/255.0, - c2.green()/255.0, - c2.blue()/255.0 ); // set first gradient color - getRenderer()->SetBackground2( c1.red()/255.0, - c1.green()/255.0, - c1.blue()/255.0 ); // set second gradient color - ok = true; - } - break; + QColor c1, c2; + int type = bgData.gradient( c1, c2 ); + if ( c1.isValid() ) + { + if ( !c2.isValid() ) + c2 = c1; + + // show two-color gradient background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( true ); // switch to gradient mode + + VTKViewer_OpenGLRenderer* aRenderer = + VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() ); + if( aRenderer ) + { + aRenderer->SetGradientType( type ); + aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() ); + aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() ); + ok = true; + } + } + break; } case Qtx::CustomGradientBackground: { diff --git a/src/SVTK/resources/SVTK_msg_en.ts b/src/SVTK/resources/SVTK_msg_en.ts index ec3a19da1..6e6ca4e84 100644 --- a/src/SVTK/resources/SVTK_msg_en.ts +++ b/src/SVTK/resources/SVTK_msg_en.ts @@ -595,10 +595,38 @@ Please, refer to the documentation. MEN_CHANGE_BACKGROUD Change background... + + GT_HORIZONTALGRADIENT + Horizontal gradient + GT_VERTICALGRADIENT Vertical gradient + + GT_FIRSTDIAGONALGRADIENT + First diagonal gradient + + + GT_SECONDDIAGONALGRADIENT + Second diagonal gradient + + + GT_FIRSTCORNERGRADIENT + First corner gradient + + + GT_SECONDCORNERGRADIENT + Second corner gradient + + + GT_THIRDCORNERGRADIENT + Third corner gradient + + + GT_FOURTHCORNERGRADIENT + Fourth corner gradient + BG_IMAGE_FILES Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha) diff --git a/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx b/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx index a9625143b..a7250fa2e 100644 --- a/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx +++ b/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx @@ -43,12 +43,18 @@ vtkStandardNewMacro(VTKViewer_OpenGLRenderer); VTKViewer_OpenGLRenderer::VTKViewer_OpenGLRenderer() { + this->GradientType = HorizontalGradient; } VTKViewer_OpenGLRenderer::~VTKViewer_OpenGLRenderer() { } +void VTKViewer_OpenGLRenderer::SetGradientType( const int theGradientType ) +{ + this->GradientType = theGradientType; +} + void VTKViewer_OpenGLRenderer::Clear(void) { GLbitfield clear_mask = 0; @@ -97,16 +103,92 @@ void VTKViewer_OpenGLRenderer::Clear(void) if( this->GradientBackground ) { - glBegin( GL_QUADS ); + double* corner1 = 0; + double* corner2 = 0; + double* corner3 = 0; + double* corner4 = 0; + double dcorner1[3]; + double dcorner2[3]; - glColor4d( this->Background[0], this->Background[1], this->Background[2], 0.0 ); - glVertex2f( 0.F, 0.F ); - glVertex2f( 1.F, 0.F ); - - glColor4d( this->Background2[0], this->Background2[1], this->Background2[2], 0.0 ); - glVertex2f( 1.F, 1.F ); - glVertex2f( 0.F, 1.F ); + switch( this->GradientType ) + { + case HorizontalGradient: + corner1 = this->Background; + corner2 = this->Background2; + corner3 = this->Background2; + corner4 = this->Background; + break; + case VerticalGradient: + corner1 = this->Background2; + corner2 = this->Background2; + corner3 = this->Background; + corner4 = this->Background; + break; + case FirstDiagonalGradient: + corner2 = this->Background2; + corner4 = this->Background; + dcorner1[0] = dcorner2[0] = 0.5F * ( corner2[0] + corner4[0] ); + dcorner1[1] = dcorner2[1] = 0.5F * ( corner2[1] + corner4[1] ); + dcorner1[2] = dcorner2[2] = 0.5F * ( corner2[2] + corner4[2] ); + corner1 = dcorner1; + corner3 = dcorner2; + break; + case SecondDiagonalGradient: + corner1 = this->Background2; + corner3 = this->Background; + dcorner1[0] = dcorner2[0] = 0.5F * ( corner1[0] + corner3[0] ); + dcorner1[1] = dcorner2[1] = 0.5F * ( corner1[1] + corner3[1] ); + dcorner1[2] = dcorner2[2] = 0.5F * ( corner1[2] + corner3[2] ); + corner2 = dcorner1; + corner4 = dcorner2; + break; + case FirstCornerGradient: + corner1 = this->Background2; + corner2 = this->Background2; + corner3 = this->Background2; + corner4 = this->Background; + break; + case SecondCornerGradient: + corner1 = this->Background2; + corner2 = this->Background2; + corner3 = this->Background; + corner4 = this->Background2; + break; + case ThirdCornerGradient: + corner1 = this->Background2; + corner2 = this->Background; + corner3 = this->Background2; + corner4 = this->Background2; + break; + case FourthCornerGradient: + corner1 = this->Background; + corner2 = this->Background2; + corner3 = this->Background2; + corner4 = this->Background2; + break; + default: // just in case + corner1 = this->Background; + corner2 = this->Background; + corner3 = this->Background; + corner4 = this->Background; + break; + } + glBegin( GL_TRIANGLE_FAN ); + if( this->GradientType != FirstCornerGradient && this->GradientType != ThirdCornerGradient ) + { + glColor3f( corner1[0], corner1[1], corner1[2] ); glVertex2f( 0.F, 0.F ); + glColor3f( corner2[0], corner2[1], corner2[2] ); glVertex2f( 1.F, 0.F ); + glColor3f( corner3[0], corner3[1], corner3[2] ); glVertex2f( 1.F, 1.F ); + glColor3f( corner4[0], corner4[1], corner4[2] ); glVertex2f( 0.F, 1.F ); + } + else //if( this->GradientType == FirstCornerGradient || this->GradientType == ThirdCornerGradient ) + { + glColor3f( corner2[0], corner2[1], corner2[2] ); glVertex2f( 1.F, 0.F ); + glColor3f( corner3[0], corner3[1], corner3[2] ); glVertex2f( 1.F, 1.F ); + glColor3f( corner4[0], corner4[1], corner4[2] ); glVertex2f( 0.F, 1.F ); + glColor3f( corner1[0], corner1[1], corner1[2] ); glVertex2f( 0.F, 0.F ); + } glEnd(); } diff --git a/src/VTKViewer/VTKViewer_OpenGLRenderer.h b/src/VTKViewer/VTKViewer_OpenGLRenderer.h index 797d21221..83bcc5ecc 100644 --- a/src/VTKViewer/VTKViewer_OpenGLRenderer.h +++ b/src/VTKViewer/VTKViewer_OpenGLRenderer.h @@ -35,16 +35,33 @@ class VTKVIEWER_EXPORT VTKViewer_OpenGLRenderer : public vtkOpenGLRenderer { +public: + enum { + HorizontalGradient, + VerticalGradient, + FirstDiagonalGradient, + SecondDiagonalGradient, + FirstCornerGradient, + SecondCornerGradient, + ThirdCornerGradient, + FourthCornerGradient + }; + public: static VTKViewer_OpenGLRenderer *New(); vtkTypeMacro(VTKViewer_OpenGLRenderer,vtkOpenGLRenderer); - virtual void Clear(void); + virtual void SetGradientType( const int ); + + virtual void Clear(void); protected: VTKViewer_OpenGLRenderer(); ~VTKViewer_OpenGLRenderer(); +private: + int GradientType; + private: VTKViewer_OpenGLRenderer(const VTKViewer_OpenGLRenderer&); // Not implemented. void operator=(const VTKViewer_OpenGLRenderer&); // Not implemented. diff --git a/src/VTKViewer/VTKViewer_ViewModel.cxx b/src/VTKViewer/VTKViewer_ViewModel.cxx index 44cb5fd90..15e4d90da 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.cxx +++ b/src/VTKViewer/VTKViewer_ViewModel.cxx @@ -64,8 +64,22 @@ VTKViewer_Viewer::~VTKViewer_Viewer() /*! Get data for supported background modes: gradient types, identifiers and supported image formats */ QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList ) { - gradList << tr( "GT_VERTICALGRADIENT" ); // only vertical type of gradient is supported - idList << VerticalGradient; // only vertical type of gradient is supported + gradList << tr( "GT_HORIZONTALGRADIENT" ) + << tr( "GT_VERTICALGRADIENT" ) + << tr( "GT_FIRSTDIAGONALGRADIENT" ) + << tr( "GT_SECONDDIAGONALGRADIENT" ) + << tr( "GT_FIRSTCORNERGRADIENT" ) + << tr( "GT_SECONDCORNERGRADIENT" ) + << tr( "GT_THIRDCORNERGRADIENT" ) + << tr( "GT_FOURTHCORNERGRADIENT" ); + idList << HorizontalGradient + << VerticalGradient + << FirstDiagonalGradient + << SecondDiagonalGradient + << FirstCornerGradient + << SecondCornerGradient + << ThirdCornerGradient + << FourthCornerGradient; #ifdef VTK_ENABLE_TEXTURED_BACKGROUND txtList << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture; #endif diff --git a/src/VTKViewer/VTKViewer_ViewModel.h b/src/VTKViewer/VTKViewer_ViewModel.h index a5c135e7f..9976152af 100755 --- a/src/VTKViewer/VTKViewer_ViewModel.h +++ b/src/VTKViewer/VTKViewer_ViewModel.h @@ -41,8 +41,15 @@ class VTKVIEWER_EXPORT VTKViewer_Viewer: public SUIT_ViewModel public: /*! supported gradient types */ enum { + HorizontalGradient, VerticalGradient, - LastGradient = VerticalGradient, + FirstDiagonalGradient, + SecondDiagonalGradient, + FirstCornerGradient, + SecondCornerGradient, + ThirdCornerGradient, + FourthCornerGradient, + LastGradient = FourthCornerGradient, }; /*!Initialize type of viewer.*/ diff --git a/src/VTKViewer/VTKViewer_ViewWindow.cxx b/src/VTKViewer/VTKViewer_ViewWindow.cxx index 3dfd85752..fcafdae31 100755 --- a/src/VTKViewer/VTKViewer_ViewWindow.cxx +++ b/src/VTKViewer/VTKViewer_ViewWindow.cxx @@ -485,25 +485,25 @@ void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) { QColor c1, c2; int type = bgData.gradient( c1, c2 ); - // VSR: Currently, only vertical gradient is supported by VTK. - // In future, switch operator might be added here to process different supported gradient types. - if ( c1.isValid() && type == VTKViewer_Viewer::VerticalGradient ) { - if ( !c2.isValid() ) c2 = c1; - // show two-color gradient background - getRenderer()->SetTexturedBackground( false ); // cancel texture mode - getRenderer()->SetGradientBackground( true ); // switch to gradient mode - // VSR: In VTK, gradient is colored from bottom to top: - // - top color is set via SetBackground2() - // - bottom color is set via SetBackground() - // So, we reverse colors, to draw gradient from top to bottom instead. - getRenderer()->SetBackground( c2.red()/255.0, - c2.green()/255.0, - c2.blue()/255.0 ); // set first gradient color - getRenderer()->SetBackground2( c1.red()/255.0, - c1.green()/255.0, - c1.blue()/255.0 ); // set second gradient color - ok = true; - } + if ( c1.isValid() ) + { + if ( !c2.isValid() ) + c2 = c1; + + // show two-color gradient background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( true ); // switch to gradient mode + + VTKViewer_OpenGLRenderer* aRenderer = + VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() ); + if( aRenderer ) + { + aRenderer->SetGradientType( type ); + aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() ); + aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() ); + ok = true; + } + } break; } case Qtx::CustomGradientBackground: diff --git a/src/VTKViewer/resources/VTKViewer_msg_en.ts b/src/VTKViewer/resources/VTKViewer_msg_en.ts index a05fe00af..0f27a1597 100644 --- a/src/VTKViewer/resources/VTKViewer_msg_en.ts +++ b/src/VTKViewer/resources/VTKViewer_msg_en.ts @@ -219,10 +219,38 @@ MEN_CHANGE_BACKGROUD Change Background... + + GT_HORIZONTALGRADIENT + Horizontal gradient + GT_VERTICALGRADIENT Vertical gradient + + GT_FIRSTDIAGONALGRADIENT + First diagonal gradient + + + GT_SECONDDIAGONALGRADIENT + Second diagonal gradient + + + GT_FIRSTCORNERGRADIENT + First corner gradient + + + GT_SECONDCORNERGRADIENT + Second corner gradient + + + GT_THIRDCORNERGRADIENT + Third corner gradient + + + GT_FOURTHCORNERGRADIENT + Fourth corner gradient + BG_IMAGE_FILES Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)