From 137d531ca5128563f2c1a167684cb1035a34a6bc Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 10 Oct 2005 16:24:51 +0000 Subject: [PATCH] Hue parameter computing. --- src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx index 0d20a0e9..91f7c70d 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -104,8 +104,9 @@ PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = NULL; struct TVertex { - GLfloat r, g, b; + GLfloat r, g, b, hue; GLfloat vx, vy, vz; + //GLfloat hue; }; //----------------------------------------------------------------------------- @@ -270,7 +271,6 @@ GLhandleARB VISU_OpenGLPointSpriteMapper::InitShader() glLinkProgramARB( VertexProgram ); //this->PrintInfoLog( VertexProgram ); - /* cout << "Shader from " << fileName << endl; for( int i = 0; i < strlen( shader ); i++ ) @@ -415,13 +415,9 @@ void VISU_OpenGLPointSpriteMapper::InitExtensions() // (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" ); //glUseProgramObjectARB( VISU_OpenGLPointSpriteMapper::VertexProgram ); /* - this->SetShaderVariable( "attrib1", 1.0 ); - this->SetShaderVariable( "attrib2", 1.0 ); - this->SetShaderVariable( "attrib3", 1.0 ); this->SetShaderVariable( "results", this->PointSpriteResults ); this->SetShaderVariable( "clamp", this->PointSpriteClamp ); this->SetShaderVariable( "geomSize", this->PointSpriteSize ); - this->SetShaderVariable( "attrib4", 1.0 ); this->SetShaderVariable( "minSize", this->PointSpriteMinSize ); this->SetShaderVariable( "maxSize", this->PointSpriteMaxSize ); this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); @@ -719,6 +715,52 @@ void VISU_OpenGLPointSpriteMapper::InitTextures() glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture ); } +//----------------------------------------------------------------------------- +int ComputeHue( int r, int g, int b ) +{ + int h = 0; + + int max = r; + int whatmax = 0; + if( g > max ) { + max = g; + whatmax = 1; + } + if( b > max ) { + max = b; + whatmax = 2; + } + + int min = r; + if ( g < min ) min = g; + if ( b < min ) min = b; + int delta = max-min; + + if( delta == 0 ) + h = 0; + else if( whatmax == 0 ) { + if ( g >= b ) + h = (120*(g-b)+delta)/(2*delta); + else + h = (120*(g-b+delta)+delta)/(2*delta) + 300; + } + else if( whatmax == 1 ) { + if ( b > r ) + h = 120 + (120*(b-r)+delta)/(2*delta); + else + h = 60 + (120*(b-r+delta)+delta)/(2*delta); + } + else { + if ( r > g ) + h = 240 + (120*(r-g)+delta)/(2*delta); + else + h = 180 + (120*(r-g+delta)+delta)/(2*delta); + } + + //cout << h << endl; + return h + 1; +} + //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, vtkPoints *p, @@ -748,13 +790,9 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, glUseProgramObjectARB( myVertexProgram ); - this->SetShaderVariable( "attrib1", 0.0 ); - this->SetShaderVariable( "attrib2", 0.0 ); - this->SetShaderVariable( "attrib3", 0.0 ); this->SetShaderVariable( "results", this->PointSpriteResults ); this->SetShaderVariable( "clamp", this->PointSpriteClamp ); this->SetShaderVariable( "geomSize", this->PointSpriteSize ); - this->SetShaderVariable( "attrib4", 0.0 ); this->SetShaderVariable( "minSize", this->PointSpriteMinSize ); this->SetShaderVariable( "maxSize", this->PointSpriteMaxSize ); this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); @@ -789,6 +827,10 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, aVertex[i].g = aPropertyColorGreen; aVertex[i].b = aPropertyColorBlue; } + + aVertex[i].hue = ComputeHue( ( int )( aVertex[i].r * 255 ), + ( int )( aVertex[i].g * 255 ), + ( int )( aVertex[i].b * 255 ) ); } GLuint aBufferObjectID = 0; @@ -803,10 +845,8 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx, glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); - static int aDisplacement = 3*sizeof(GLfloat); - - glColorPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)0 ); - glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)aDisplacement ); + glColorPointer( 4, GL_FLOAT, sizeof(TVertex), (void*)0 ); + glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), (void*)(4*sizeof(GLfloat)) ); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); -- 2.39.2