From a4835deeb188dcc112501a62b4faa6c326100b69 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 14 Dec 2005 09:36:22 +0000 Subject: [PATCH] Fixed bug GVIEW10828 : point sprite size computation not done on the graphic board --- resources/Vertex_Program_ARB.txt | 19 ++- src/PIPELINE/VISU_LookupTable.cxx | 19 +++ src/PIPELINE/VISU_LookupTable.hxx | 8 +- src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx | 143 +++++++++--------- src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx | 1 + 5 files changed, 109 insertions(+), 81 deletions(-) diff --git a/resources/Vertex_Program_ARB.txt b/resources/Vertex_Program_ARB.txt index e13d0258..e9e7cde0 100755 --- a/resources/Vertex_Program_ARB.txt +++ b/resources/Vertex_Program_ARB.txt @@ -1,12 +1,21 @@ -attribute float clamp_size; +attribute float mode; +attribute float clampSize; +attribute float geomSize; +attribute float minSize; +attribute float maxSize; +attribute float magnification; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - gl_FrontColor.x = gl_Color.x; - gl_FrontColor.y = gl_Color.y; - gl_FrontColor.z = gl_Color.z; + gl_FrontColor = gl_Color; - gl_PointSize = min( gl_Color.w * gl_ProjectionMatrix[0].x, clamp_size ); + float size; + if( mode == 0 ) // Results + size = minSize + ( maxSize - minSize ) * ( 1 - gl_Color.w / 241.0f ); + else // Geometry and Uniform colored outside cursor + size = geomSize; + + gl_PointSize = clamp( magnification * size * gl_ProjectionMatrix[0].x, 2, clampSize ); } diff --git a/src/PIPELINE/VISU_LookupTable.cxx b/src/PIPELINE/VISU_LookupTable.cxx index e942e910..c15fdd27 100644 --- a/src/PIPELINE/VISU_LookupTable.cxx +++ b/src/PIPELINE/VISU_LookupTable.cxx @@ -42,6 +42,25 @@ VISU_LookupTable *VISU_LookupTable::New() { VISU_LookupTable::VISU_LookupTable(int sze, int ext) : vtkLookupTable(sze, ext), myScale(1.0), myBicolor(false) {} +void VISU_LookupTable::SetMapScale(float theScale) +{ + if( myScale != theScale ) + { + myScale = theScale; + Modified(); + } +} + +void VISU_LookupTable::SetBicolor( bool theBicolor ) +{ + if( myBicolor != theBicolor ) + { + myBicolor = theBicolor; + Modified(); + } +} + + int VISU_LookupTable::ComputeLogRange(float inRange[2], float outRange[2]){ if(inRange[0] >= inRange[1]) return -1; diff --git a/src/PIPELINE/VISU_LookupTable.hxx b/src/PIPELINE/VISU_LookupTable.hxx index cf3f6339..20f7c23e 100644 --- a/src/PIPELINE/VISU_LookupTable.hxx +++ b/src/PIPELINE/VISU_LookupTable.hxx @@ -20,11 +20,11 @@ class VISU_LookupTable: public vtkLookupTable { int inputDataType, int numberOfValues, int inputIncrement, int outputIncrement); - float GetMapScale() { return myScale; } - void SetMapScale(float theScale = 1.0) { myScale = theScale; Modified(); } + float GetMapScale() { return myScale; } + void SetMapScale(float theScale = 1.0); - float GetBicolor() { return myBicolor; } - void SetBicolor( bool theBicolor ) { myBicolor = theBicolor; Modified(); } + float GetBicolor() { return myBicolor; } + void SetBicolor( bool theBicolor ); static int ComputeLogRange(float inRange[2], float outRange[2]); unsigned char *MapValue(float v); diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx index 27ca5340..1041ef4b 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -180,25 +180,28 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper() this->PointSpriteMode = 0; this->PointSpriteClamp = 256.0; - this->PointSpriteSize = 0.15; - this->PointSpriteMinSize = 0.3; - this->PointSpriteMaxSize = 0.33; + this->PointSpriteSize = 0.2; + this->PointSpriteMinSize = 0.1; + this->PointSpriteMaxSize = 0.3; this->PointSpriteMagnification = 1.0; this->PointSpriteAlphaThreshold = 0.5; this->PointSpriteTexture = 0; this->UseOpenGLMapper = false; + + this->TempMapper = vtkPolyDataMapper::New(); } //----------------------------------------------------------------------------- VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper() { glDeleteTextures( 1, &PointSpriteTexture ); - if (this->LastWindow) - { + if( this->LastWindow ) this->ReleaseGraphicsResources(this->LastWindow); - } + + if( this->TempMapper ) + this->TempMapper->Delete(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::ShallowCopy( vtkAbstractMapper* mapper ) @@ -219,7 +222,10 @@ void VISU_OpenGLPointSpriteMapper::ShallowCopy( vtkAbstractMapper* mapper ) this->SetImageData( m->GetImageData() ); this->SetPointSpriteAlphaThreshold( m->GetPointSpriteAlphaThreshold() ); } - MAPPER_SUPERCLASS::ShallowCopy(mapper); + + this->TempMapper->ShallowCopy( m ); + this->TempMapper->SetInput( this->GetInput() ); + Superclass::ShallowCopy( this->TempMapper ); } //----------------------------------------------------------------------------- @@ -309,16 +315,15 @@ void VISU_OpenGLPointSpriteMapper::SetShaderVariable( const char* variable, floa //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPrimitiveType( int thePrimitiveType ) { - if(this->PrimitiveType == thePrimitiveType) + if( this->PrimitiveType == thePrimitiveType ) return; this->PrimitiveType = thePrimitiveType; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteMode( int theMode ) { - if(this->PointSpriteMode == theMode) + if( this->PointSpriteMode == theMode ) return; this->PointSpriteMode = theMode; @@ -327,56 +332,50 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteMode( int theMode ) //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteClamp( float theClamp ) { - if(fabs(this->PointSpriteClamp - theClamp) < Tolerance) + if( fabs( this->PointSpriteClamp - theClamp ) < Tolerance ) return; this->PointSpriteClamp = theClamp; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteSize( float theSize ) { - if(fabs(this->PointSpriteSize - theSize) < Tolerance) + if( fabs( this->PointSpriteSize - theSize ) < Tolerance ) return; this->PointSpriteSize = theSize; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteMinSize( float theMinSize ) { - if(fabs(this->PointSpriteMinSize - theMinSize) < Tolerance) + if( fabs( this->PointSpriteMinSize - theMinSize ) < Tolerance ) return; this->PointSpriteMinSize = theMinSize; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteMaxSize( float theMaxSize ) { - if(fabs(this->PointSpriteMaxSize - theMaxSize) < Tolerance) + if( fabs( this->PointSpriteMaxSize - theMaxSize ) < Tolerance ) return; this->PointSpriteMaxSize = theMaxSize; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteMagnification( float theMagnification ) { - if(fabs(this->PointSpriteMagnification - theMagnification) < Tolerance) + if( fabs( this->PointSpriteMagnification - theMagnification ) < Tolerance ) return; this->PointSpriteMagnification = theMagnification; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::SetPointSpriteAlphaThreshold( float theAlphaThreshold ) { - if(fabs(this->PointSpriteAlphaThreshold - theAlphaThreshold) < Tolerance) + if( fabs( this->PointSpriteAlphaThreshold - theAlphaThreshold ) < Tolerance ) return; this->PointSpriteAlphaThreshold = theAlphaThreshold; - this->Modified(); } //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::InitExtensions() @@ -400,6 +399,28 @@ void VISU_OpenGLPointSpriteMapper::InitExtensions() this->ExtensionsInitialized = 1; } + +//----------------------------------------------------------------------------- +float ViewToDisplay( vtkRenderer* theRenderer ) +{ + float p1[3], p2[3]; + + theRenderer->SetViewPoint( 0.0, 0.0, 0.0 ); + theRenderer->ViewToDisplay(); + theRenderer->GetDisplayPoint( p1 ); + + theRenderer->SetViewPoint( 1.0, 1.0, 1.0 ); + theRenderer->ViewToDisplay(); + theRenderer->GetDisplayPoint( p2 ); + + float coefficient = sqrt( pow( p2[0] - p1[0], 2 ) + pow( p2[1] - p1[1], 2 ) ) / sqrt( 2 ); + //cout << p1[0] << " " << p1[1] << " " << p1[2] << endl; + //cout << p2[0] << " " << p2[1] << " " << p2[2] << endl; + //cout << "ZOOM : " << coefficient << endl; + + return coefficient; +} + //----------------------------------------------------------------------------- // // Receives from Actor -> maps data to primitives @@ -412,7 +433,7 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) if( !this->ExtensionsInitialized && isUseThisMapper ) { this->InitExtensions(); - act->GetProperty()->SetPointSize( 10.0f ); + //act->GetProperty()->SetPointSize( 10.0f ); } if( !isUseThisMapper ) @@ -457,10 +478,22 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) // make sure our window is current ren->GetRenderWindow()->MakeCurrent(); + if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) + this->InitPointSprites(); + // Initializing the texture for Point Sprites if( this->UseTextures && this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) this->InitTextures(); + vglUseProgramObjectARB( this->VertexProgram ); + float aViewToDisplay = ViewToDisplay( ren ); + this->SetShaderVariable( "mode", this->PointSpriteMode ); + this->SetShaderVariable( "clampSize", this->PointSpriteClamp ); + this->SetShaderVariable( "geomSize", aViewToDisplay * this->AverageCellSize * this->PointSpriteSize ); + this->SetShaderVariable( "minSize", aViewToDisplay * this->AverageCellSize * this->PointSpriteMinSize ); + this->SetShaderVariable( "maxSize", aViewToDisplay * this->AverageCellSize * this->PointSpriteMaxSize ); + this->SetShaderVariable( "magnification", this->PointSpriteMagnification ); + // // if something has changed regenerate colors and display lists // if required @@ -533,6 +566,11 @@ void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act) // time so that it is not zero if ( this->TimeToDraw == 0.0 ) this->TimeToDraw = 0.0001; + + vglUseProgramObjectARB( 0 ); + + if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) + this->CleanupPointSprites(); } //----------------------------------------------------------------------------- float VISU_OpenGLPointSpriteMapper::GetMaximumSupportedSize() @@ -694,26 +732,6 @@ struct TVertex GLfloat vx, vy, vz; }; -float ViewToDisplay( vtkRenderer* theRenderer ) -{ - float p1[3], p2[3]; - - theRenderer->SetViewPoint( 0.0, 0.0, 0.0 ); - theRenderer->ViewToDisplay(); - theRenderer->GetDisplayPoint( p1 ); - - theRenderer->SetViewPoint( 1.0, 1.0, 1.0 ); - theRenderer->ViewToDisplay(); - theRenderer->GetDisplayPoint( p2 ); - - float coefficient = sqrt( pow( p2[0] - p1[0], 2 ) + pow( p2[1] - p1[1], 2 ) ) / sqrt( 2 ); - //cout << p1[0] << " " << p1[1] << " " << p1[2] << endl; - //cout << p2[0] << " " << p2[1] << " " << p2[2] << endl; - //cout << "ZOOM : " << coefficient << endl; - - return coefficient; -} - //----------------------------------------------------------------------------- void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints, vtkUnsignedCharArray *theColors, @@ -724,18 +742,13 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints, vtkRenderer *theRenderer, vtkActor* theActor) { - if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) - this->InitPointSprites(); + //cout << "VISU_OpenGLPointSpriteMapper::DrawPoints" << endl; - if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint ) - glEnable( GL_POINT_SMOOTH ); + //if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint ) + // glEnable( GL_POINT_SMOOTH ); glPointSize( this->DefaultPointSize ); - vglUseProgramObjectARB( this->VertexProgram ); - - this->SetShaderVariable( "clamp_size", this->PointSpriteClamp ); - TVertex* aVertexArr = new TVertex[ this->TotalCells ]; float* aPropertyColor = theActor->GetProperty()->GetColor(); @@ -766,24 +779,15 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints, aGreen = int(col[1]); aBlue = int(col[2]); - aColor[0] = aRed / 255.0; + aColor[0] = aRed / 255.0; aColor[1] = aGreen / 255.0; - aColor[2] = aBlue / 255.0; + aColor[2] = aBlue / 255.0; } aVertex.r = aColor[0]; aVertex.g = aColor[1]; aVertex.b = aColor[2]; - - if( this->PointSpriteMode == 0 ) - { - aHue = ComputeHue( aRed, aGreen, aBlue ); - aSize = this->PointSpriteMinSize + ( PointSpriteMaxSize - PointSpriteMinSize ) * ( 1 - aHue / 241.0f ); - } - else - aSize = this->PointSpriteSize; - - aVertex.hue = aViewToDisplay * this->AverageCellSize * this->PointSpriteMagnification * aSize; + aVertex.hue = ComputeHue( aRed, aGreen, aBlue ); } GLuint aBufferObjectID = 0; @@ -811,20 +815,16 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints, vglDeleteBuffersARB( 1, &aBufferObjectID ); - vglUseProgramObjectARB( 0 ); - - if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite ) - this->CleanupPointSprites(); - - if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint ) - glDisable( GL_POINT_SMOOTH ); + //if( this->PrimitiveType == VISU_OpenGLPointSpriteMapper::OpenGLPoint ) + // glDisable( GL_POINT_SMOOTH ); } //----------------------------------------------------------------------------- int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *aren, vtkActor *act) { - if( this->UseOpenGLMapper || this->PrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere ) + if( this->UseOpenGLMapper || + this->PrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere ) return MAPPER_SUPERCLASS::Draw( aren, act ); vtkOpenGLRenderer *ren = (vtkOpenGLRenderer *)aren; @@ -886,4 +886,3 @@ void VISU_OpenGLPointSpriteMapper::ReleaseGraphicsResources(vtkWindow *win) } this->LastWindow = NULL; } -//----------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx index 02bd4516..a05b57ad 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx @@ -279,6 +279,7 @@ private: float AverageCellSize; vtkSmartPointer ImageData; + vtkPolyDataMapper* TempMapper; }; #endif -- 2.39.2