Part 2: gradient background.
/*! 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
public:
/*! supported gradient types */
enum {
+ HorizontalGradient,
VerticalGradient,
- LastGradient = VerticalGradient,
+ FirstDiagonalGradient,
+ SecondDiagonalGradient,
+ FirstCornerGradient,
+ SecondCornerGradient,
+ ThirdCornerGradient,
+ FourthCornerGradient,
+ LastGradient = FourthCornerGradient,
};
typedef SVTK_ViewWindow TViewWindow;
#include "SVTK_ViewParameterDlg.h"
#include "SVTK_ViewModel.h"
#include "VTKViewer_Texture.h"
+#include "VTKViewer_OpenGLRenderer.h"
#include "SALOME_Actor.h"
}
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:
{
<source>MEN_CHANGE_BACKGROUD</source>
<translation>Change background...</translation>
</message>
+ <message>
+ <source>GT_HORIZONTALGRADIENT</source>
+ <translation>Horizontal gradient</translation>
+ </message>
<message>
<source>GT_VERTICALGRADIENT</source>
<translation>Vertical gradient</translation>
</message>
+ <message>
+ <source>GT_FIRSTDIAGONALGRADIENT</source>
+ <translation>First diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDDIAGONALGRADIENT</source>
+ <translation>Second diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_FIRSTCORNERGRADIENT</source>
+ <translation>First corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDCORNERGRADIENT</source>
+ <translation>Second corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_THIRDCORNERGRADIENT</source>
+ <translation>Third corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_FOURTHCORNERGRADIENT</source>
+ <translation>Fourth corner gradient</translation>
+ </message>
<message>
<source>BG_IMAGE_FILES</source>
<translation>Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>
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;
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();
}
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.
/*! 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
public:
/*! supported gradient types */
enum {
+ HorizontalGradient,
VerticalGradient,
- LastGradient = VerticalGradient,
+ FirstDiagonalGradient,
+ SecondDiagonalGradient,
+ FirstCornerGradient,
+ SecondCornerGradient,
+ ThirdCornerGradient,
+ FourthCornerGradient,
+ LastGradient = FourthCornerGradient,
};
/*!Initialize type of viewer.*/
{
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:
<source>MEN_CHANGE_BACKGROUD</source>
<translation>Change Background...</translation>
</message>
+ <message>
+ <source>GT_HORIZONTALGRADIENT</source>
+ <translation>Horizontal gradient</translation>
+ </message>
<message>
<source>GT_VERTICALGRADIENT</source>
<translation>Vertical gradient</translation>
</message>
+ <message>
+ <source>GT_FIRSTDIAGONALGRADIENT</source>
+ <translation>First diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDDIAGONALGRADIENT</source>
+ <translation>Second diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_FIRSTCORNERGRADIENT</source>
+ <translation>First corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDCORNERGRADIENT</source>
+ <translation>Second corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_THIRDCORNERGRADIENT</source>
+ <translation>Third corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_FOURTHCORNERGRADIENT</source>
+ <translation>Fourth corner gradient</translation>
+ </message>
<message>
<source>BG_IMAGE_FILES</source>
<translation>Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>