]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fixed bug GVIEW10828 : point sprite size computation not done on the graphic board
authorouv <ouv@opencascade.com>
Wed, 14 Dec 2005 09:36:22 +0000 (09:36 +0000)
committerouv <ouv@opencascade.com>
Wed, 14 Dec 2005 09:36:22 +0000 (09:36 +0000)
resources/Vertex_Program_ARB.txt
src/PIPELINE/VISU_LookupTable.cxx
src/PIPELINE/VISU_LookupTable.hxx
src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx
src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx

index e13d0258a4cf0b89f98f6e5812e28996064046a6..e9e7cde09572696b0fa12f1d266075b4707591ab 100755 (executable)
@@ -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 );
 }
index e942e910634352fa7daddc3a8ef5c88c12d62817..c15fdd27c4b9208735b23f3bd3573f99cd97776b 100644 (file)
@@ -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;
index cf3f6339d908602f5a176c7332a15b99a5d4795b..20f7c23e5b2b0673f2c7e974e4d51a8d71dca03a 100644 (file)
@@ -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);
index 27ca53402b6dfdce88669e804c1d2ac73a575b5d..1041ef4bd76d6a64361815b120c949ce1da80fa5 100755 (executable)
@@ -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;
 }
-//-----------------------------------------------------------------------------
index 02bd4516d8111a89462324503cb1f3500b393b8a..a05b57adcc9df4210719dc0f7e8134308b8e8def 100755 (executable)
@@ -279,6 +279,7 @@ private:
   float             AverageCellSize;
 
   vtkSmartPointer<vtkImageData> ImageData;
+  vtkPolyDataMapper* TempMapper;
 };
 
 #endif