Salome HOME
Merge from V5_1_main 10/06/2010
[modules/visu.git] / src / PIPELINE / VISU_OpenGLPointSpriteMapper.cxx
index fd54f6e014905a3bfdc4b6ab4331ed59de36082c..56c18d9330e6fd8edc590051614fdf6716038156 100755 (executable)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  VISU OBJECT : interactive object for VISU entities implementation
 // File:    VISU_OpenGLPointSpriteMapper.cxx
 // Author:  
@@ -26,7 +27,7 @@
 //
 #include "VISU_OpenGLPointSpriteMapper.hxx"
 
-#include "SVTK_Extension.h"
+//#include "SVTK_Extension.h"
 
 #include <vtkCamera.h>
 #include <vtkCellArray.h>
@@ -244,6 +245,7 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper()
   this->PointSpriteMagnification = 1.0;
 
   this->PointSpriteAlphaThreshold = 0.5;
+  this->PointSpriteOpacity       = 1.0;
   this->PointSpriteTexture       = 0;
 
   this->UseOpenGLMapper          = false;
@@ -371,6 +373,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteClamp( float theClamp )
     return;
 
   this->PointSpriteClamp = theClamp;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -380,6 +383,7 @@ void VISU_OpenGLPointSpriteMapper::SetAverageCellSize(float theSize)
     return;
 
   this->AverageCellSize = theSize;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -389,6 +393,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteSize( float theSize )
     return;
 
   this->PointSpriteSize = theSize;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -398,6 +403,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteMinSize( float theMinSize )
     return;
 
   this->PointSpriteMinSize = theMinSize;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -407,6 +413,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteMaxSize( float theMaxSize )
     return;
 
   this->PointSpriteMaxSize = theMaxSize;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -416,6 +423,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteMagnification( float theMagnifi
     return;
 
   this->PointSpriteMagnification = theMagnification;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -425,6 +433,7 @@ void VISU_OpenGLPointSpriteMapper::SetPointSpriteAlphaThreshold( float theAlphaT
     return;
 
   this->PointSpriteAlphaThreshold = theAlphaThreshold;
+  this->Modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -646,11 +655,16 @@ void VISU_OpenGLPointSpriteMapper::InitPointSprites()
   glEnable( GL_POINT_SPRITE_ARB );
   glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
 
+  glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT );
+
+  this->RenderMode = this->PointSpriteOpacity < 1.0 ? VISU_OpenGLPointSpriteMapper::Accumulate : VISU_OpenGLPointSpriteMapper::Occlude;
+
   switch (this->RenderMode)
   {
     case VISU_OpenGLPointSpriteMapper::Accumulate:
     {
-      glDisable(GL_DEPTH_TEST);
+      glDepthFunc( GL_LESS );
+      glEnable( GL_DEPTH_TEST );
 
       glEnable( GL_BLEND );
       glBlendFunc( GL_SRC_ALPHA, GL_ONE );
@@ -688,13 +702,7 @@ void VISU_OpenGLPointSpriteMapper::InitPointSprites()
 void VISU_OpenGLPointSpriteMapper::CleanupPointSprites()
 {
   // Set GL params back to normal to stop other vtkMappers displaying wrongly
-  glDisable( GL_ALPHA_TEST );
-
-  glEnable( GL_BLEND );
-
-  glEnable( GL_DEPTH_TEST );
-  glEnable( GL_LIGHTING );
-  glEnable( GL_COLOR_MATERIAL );
+  glPopAttrib();
 
   glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
   glDisable( GL_POINT_SPRITE_ARB );
@@ -735,7 +743,7 @@ void VISU_OpenGLPointSpriteMapper::InitTextures()
   int* aSize = GetImageData()->GetDimensions();
   unsigned char* dataPtr = (unsigned char*)GetImageData()->GetScalarPointer();
   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aSize[0], aSize[1], 0,
-               GL_RGBA, GL_UNSIGNED_BYTE, dataPtr );
+                GL_RGBA, GL_UNSIGNED_BYTE, dataPtr );
 
   //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
   glEnable( GL_TEXTURE_2D );
@@ -899,11 +907,11 @@ struct TCellColors2Color : TColors2Color
 //-----------------------------------------------------------------------------
 template < class TCoordinates >
 void DrawPoints( TCoordinates *theStartPoints,
-                vtkCellArray *theCells,
-                TColorFunctorBase* theColorFunctor,
-                TVertex* theVertexArr,
-                vtkIdType &theCellId,
-                vtkIdType &theVertexId )
+                 vtkCellArray *theCells,
+                 TColorFunctorBase* theColorFunctor,
+                 TVertex* theVertexArr,
+                 vtkIdType &theCellId,
+                 vtkIdType &theVertexId )
 {
   vtkIdType *ptIds = theCells->GetPointer();
   vtkIdType *endPtIds = ptIds + theCells->GetNumberOfConnectivityEntries();
@@ -936,9 +944,9 @@ void DrawPoints( TCoordinates *theStartPoints,
 //-----------------------------------------------------------------------------
 template < class TCoordinates >
 void DrawCellsPoints( vtkPolyData *theInput,
-                     vtkPoints* thePoints,
-                     TColorFunctorBase* theColorFunctor,
-                     TVertex* theVertexArr )
+                      vtkPoints* thePoints,
+                      TColorFunctorBase* theColorFunctor,
+                      TVertex* theVertexArr )
 {
   vtkIdType aCellId = 0, aVertexId = 0;
 
@@ -970,13 +978,9 @@ int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *theRenderer, vtkActor *theAc
   vtkPoints            *points;
   int noAbort = 1;
   int cellScalars = 0;
-  float  tran;
-
-  // get the transparency
-  tran = theActor->GetProperty()->GetOpacity();
 
   // if the primitives are invisable then get out of here
-  if (tran <= 0.0)
+  if (this->PointSpriteOpacity <= 0.0)
   {
     return noAbort;
   }
@@ -1021,62 +1025,62 @@ int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *theRenderer, vtkActor *theAc
       glPointSize( this->DefaultPointSize );
 
       {
-       TColorFunctorBase* aColorFunctor = NULL;
-       if( colors && this->PointSpriteMode != 1 ) {
-         if ( cellScalars )
-           aColorFunctor = new TCellColors2Color( colors );
-         else
-           aColorFunctor = new TPointColors2Color( colors );
-       } else {
-         aColorFunctor = new TPropertyColor( theActor->GetProperty() );
-       }
-       if ( points->GetDataType() == VTK_FLOAT )
-         ::DrawCellsPoints< float >( input, points, aColorFunctor, aVertexArr );
-       else
-         ::DrawCellsPoints< double >( input, points, aColorFunctor, aVertexArr );
-
-       delete aColorFunctor;
+        TColorFunctorBase* aColorFunctor = NULL;
+        if( colors && this->PointSpriteMode != 1 ) {
+          if ( cellScalars )
+            aColorFunctor = new TCellColors2Color( colors );
+          else
+            aColorFunctor = new TPointColors2Color( colors );
+        } else {
+          aColorFunctor = new TPropertyColor( theActor->GetProperty() );
+        }
+        if ( points->GetDataType() == VTK_FLOAT )
+          ::DrawCellsPoints< float >( input, points, aColorFunctor, aVertexArr );
+        else
+          ::DrawCellsPoints< double >( input, points, aColorFunctor, aVertexArr );
+
+        delete aColorFunctor;
       }
 
       if( this->ExtensionsInitialized ) {
-       GLuint aBufferObjectID = 0;
-       vglGenBuffersARB( 1, &aBufferObjectID );
-       vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
-       
-       int anArrayObjectSize = sizeof( TVertex ) * aTotalConnectivitySize;
-       vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
-       
-       delete [] aVertexArr;
-       
-       vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
-       vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
-       
-       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 );
-       
-       glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
-       
-       glDisableClientState( GL_COLOR_ARRAY );
-       glDisableClientState( GL_VERTEX_ARRAY );
-       
-       vglDeleteBuffersARB( 1, &aBufferObjectID );
+        GLuint aBufferObjectID = 0;
+        vglGenBuffersARB( 1, &aBufferObjectID );
+        vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
+        
+        int anArrayObjectSize = sizeof( TVertex ) * aTotalConnectivitySize;
+        vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
+        
+        delete [] aVertexArr;
+        
+        vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
+        vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
+        
+        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 );
+        
+        glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
+        
+        glDisableClientState( GL_COLOR_ARRAY );
+        glDisableClientState( GL_VERTEX_ARRAY );
+        
+        vglDeleteBuffersARB( 1, &aBufferObjectID );
       } else { // there are not extensions
-       glColorPointer( 4, GL_FLOAT, sizeof(TVertex), aVertexArr );
-       glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), 
-                        (void*)((GLfloat*)((void*)(aVertexArr)) + 4));
-
-       glEnableClientState( GL_VERTEX_ARRAY );
-       glEnableClientState( GL_COLOR_ARRAY );
-       
-       glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
-       
-       glDisableClientState( GL_COLOR_ARRAY );
-       glDisableClientState( GL_VERTEX_ARRAY );
-
-       delete [] aVertexArr;
+        glColorPointer( 4, GL_FLOAT, sizeof(TVertex), aVertexArr );
+        glVertexPointer( 3, GL_FLOAT, sizeof(TVertex), 
+                         (void*)((GLfloat*)((void*)(aVertexArr)) + 4));
+
+        glEnableClientState( GL_VERTEX_ARRAY );
+        glEnableClientState( GL_COLOR_ARRAY );
+        
+        glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize );
+        
+        glDisableClientState( GL_COLOR_ARRAY );
+        glDisableClientState( GL_VERTEX_ARRAY );
+
+        delete [] aVertexArr;
       }
     }