]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
*** empty log message ***
authorouv <ouv@opencascade.com>
Thu, 29 Sep 2005 09:06:38 +0000 (09:06 +0000)
committerouv <ouv@opencascade.com>
Thu, 29 Sep 2005 09:06:38 +0000 (09:06 +0000)
src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx
src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx

index 672678900dd808187dbb6bbca762687f9b44bfe1..e72594627c1d33b63e96e1f773137121c3dbda4e 100755 (executable)
 
 #include "VISU_OpenGLPointSpriteMapper.hxx"
 
+#include <vtkCamera.h>
 #include <vtkCellArray.h>
 #include <vtkCellData.h>
 #include <vtkCommand.h>
 #include <vtkDataArray.h>
 #include <vtkFloatArray.h>
+#include <vtkImageData.h>
 #include <vtkMatrix4x4.h>
 #include <vtkObjectFactory.h>
 #include <vtkOpenGLRenderer.h>
+#include <vtkOpenGLRenderWindow.h>
 #include <vtkPointData.h>
 #include <vtkPolyData.h>
 #include <vtkPolygon.h>
 #include <vtkProperty.h>
 #include <vtkTimerLog.h>
 #include <vtkTriangle.h>
-#include <vtkOpenGLRenderWindow.h>
-#include <vtkOpenGLTexture.h>
-#include <vtkImageData.h>
 
 #include <GL/glext.h>
 //#include <GL/glx.h>
@@ -118,7 +118,7 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper()
   this->ExtensionsOK             = 0;
   this->AlphaChannelArray        = NULL;
   this->SizeChannelArray         = NULL;
-  this->DefaultPointSize         = 30.0;
+  this->DefaultPointSize         = 1.0;
   this->QuadraticPointDistanceAttenuation[0] = 1.0;
   this->QuadraticPointDistanceAttenuation[1] = 0.0;
   this->QuadraticPointDistanceAttenuation[2] = 0.0;
@@ -141,7 +141,8 @@ VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper()
 
   this->PointSpriteAlphaThreshold = 0.1;
   this->PointSpriteTexture       = 0;
-  this->IsUsingOpenGLMapper      = false;
+
+  this->UseOpenGLMapper          = false;
 }
 //-----------------------------------------------------------------------------
 VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper()
@@ -254,8 +255,6 @@ GLhandleARB VISU_OpenGLPointSpriteMapper::InitShader()
     (PFNGLATTACHOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glAttachObjectARB" );
   PFNGLLINKPROGRAMPROC glLinkProgramARB =
     (PFNGLLINKPROGRAMPROC)dlsym( this->OpenGLLibrary, "glLinkProgramARB" );
-  //PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB =
-  //  (PFNGLUSEPROGRAMOBJECTARBPROC)dlsym( this->OpenGLLibrary, "glUseProgramObjectARB" );
 
   GLhandleARB VertexShader = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
   glShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL );
@@ -268,12 +267,6 @@ GLhandleARB VISU_OpenGLPointSpriteMapper::InitShader()
   glLinkProgramARB( VertexProgram );
   //this->PrintInfoLog( VertexProgram );
 
-  //glUseProgramObjectARB( this->VertexProgram );
-
-  //this->SetShaderVariable( "clamp",         100.0 );
-  //this->SetShaderVariable( "minSize",        15.0 );
-  //this->SetShaderVariable( "maxSize",        50.0 );
-  //this->SetShaderVariable( "magnification",   1.0 );
   /*
   cout << "Shader from " << fileName << endl;
   for( int i = 0; i < strlen( shader ); i++ )
@@ -359,13 +352,12 @@ void VISU_OpenGLPointSpriteMapper::InitExtensions()
   //cout << "OpenGL extensions : " << ext << endl;
 
   if( strstr( ext, "GL_ARB_point_sprite" ) == NULL ||
-      //strstr( ext, "GL_ARB_vertex_program" ) == NULL ||
       strstr( ext, "GL_ARB_shader_objects" ) == NULL ||
       strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL )
   {
     vtkErrorMacro(<<"Initializing ARB extensions failed");
 
-    this->IsUsingOpenGLMapper = true;
+    this->UseOpenGLMapper = true;
 
     return;
   }
@@ -429,13 +421,13 @@ void VISU_OpenGLPointSpriteMapper::InitExtensions()
 //
 void VISU_OpenGLPointSpriteMapper::RenderPiece(vtkRenderer *ren, vtkActor *act)
 {
-  if( !this->ExtensionsInitialized && !this->IsUsingOpenGLMapper )
+  if( !this->ExtensionsInitialized && !this->UseOpenGLMapper )
   {
     this->InitExtensions();
     //act->GetProperty()->SetPointSize( 10.0f );
   }
 
-  if( this->IsUsingOpenGLMapper )
+  if( this->UseOpenGLMapper )
   {
     //cout << "Using OpenGLMapper" << endl;
     MAPPER_SUPERCLASS::RenderPiece( ren, act );
@@ -565,7 +557,7 @@ float VISU_OpenGLPointSpriteMapper::GetMaximumSupportedSize()
   return maximumSupportedSize;
 }
 //-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::InitPointSprites()
+void VISU_OpenGLPointSpriteMapper::InitPointSprites( vtkRenderer* theRenderer, vtkActor* theActor )
 {
   glEnable( GL_POINT_SPRITE_ARB );
   glEnable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
@@ -603,7 +595,31 @@ void VISU_OpenGLPointSpriteMapper::InitPointSprites()
 
   // Disable material properties
   glDisable( GL_COLOR_MATERIAL );
-
+  /*
+  // Set Quadratic Attenuation parameters
+  PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB =
+    (PFNGLPOINTPARAMETERFVARBPROC)dlsym( this->OpenGLLibrary, "glPointParameterfvARB" );
+
+  float size = this->DefaultPointSize;
+  vtkCamera* cam =  theRenderer->GetActiveCamera();
+  size *= theActor->GetMatrix()->Determinant();
+  float vp[4];
+  theRenderer->GetViewport(vp);
+  float w, h;
+  w = vp[2] - vp[0];
+  h = vp[3] - vp[1];
+  theRenderer->NormalizedDisplayToDisplay(w, h);
+  size *= h/2;
+  float quadratic[] = {0, 0, 0};
+  if(cam->GetParallelProjection())
+    quadratic[0] = cam->GetParallelScale()*cam->GetParallelScale()/(size*size); 
+  else
+  {
+    size *= 7.4*tan(cam->GetViewAngle()*3.14159/180.);
+    quadratic[2] = 1.0/(size*size);
+  }
+  glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );
+  */
   /*
   // Set Quadratic Attenuation parameters
   glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, this->QuadraticPointDistanceAttenuation );
@@ -631,6 +647,13 @@ void VISU_OpenGLPointSpriteMapper::CleanupPointSprites()
   glEnable( GL_LIGHTING );
   glEnable( GL_COLOR_MATERIAL );
 
+  // Reset Quadratic Attenuation parameters
+  PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB =
+    (PFNGLPOINTPARAMETERFVARBPROC)dlsym( this->OpenGLLibrary, "glPointParameterfvARB" );
+
+  float quadratic[] = {1, 0, 0};
+  glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );
+
   glDisable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB );
   glDisable( GL_POINT_SPRITE_ARB );
 }
@@ -684,12 +707,13 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx,
                                              vtkIdType &cellNum,
                                              int &noAbort,
                                              vtkCellArray *cells,
-                                             vtkRenderer *ren)
+                                             vtkRenderer *ren,
+                                             vtkActor* act)
 {
   //cout << "VISU_OpenGLPointSpriteMapper::DrawPoints" << endl;
 
   if( this->UsePointSprites )
-    this->InitPointSprites();
+    this->InitPointSprites( ren, act );
 
   glPointSize( this->DefaultPointSize );
 
@@ -702,17 +726,27 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx,
 
   vtkIdType *pts = 0;
   vtkIdType npts = 0;
-  unsigned short i = 0;
+  unsigned long i = 0;
   for( cells->InitTraversal(); cells->GetNextCell( npts, pts ); i++ )
   {
     aVertex[i].vx = p->GetPoint( pts[0] )[0];
     aVertex[i].vy = p->GetPoint( pts[0] )[1];
     aVertex[i].vz = p->GetPoint( pts[0] )[2];
 
-    unsigned char *col = colors->GetPointer(pts[0]<< 2);
-    aVertex[i].r = ( ( int )col[0] ) / 255.0;
-    aVertex[i].g = ( ( int )col[1] ) / 255.0;
-    aVertex[i].b = ( ( int )col[2] ) / 255.0;
+    if( colors )
+    {
+      unsigned char *col = colors->GetPointer(pts[0]<< 2);
+      aVertex[i].r = ( ( int )col[0] ) / 255.0;
+      aVertex[i].g = ( ( int )col[1] ) / 255.0;
+      aVertex[i].b = ( ( int )col[2] ) / 255.0;
+    }
+    else
+    {
+      float* col = act->GetProperty()->GetColor();
+      aVertex[i].r = col[0];
+      aVertex[i].g = col[1];
+      aVertex[i].b = col[2];
+    }
   }
 
   GLuint aBufferObjectID = 0;
@@ -749,7 +783,7 @@ void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx,
 // Draw method for OpenGL.
 int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *aren, vtkActor *act)
 {
-  if( this->IsUsingOpenGLMapper )
+  if( this->UseOpenGLMapper )
     return MAPPER_SUPERCLASS::Draw( aren, act );
 
   vtkOpenGLRenderer    *ren    = (vtkOpenGLRenderer *)aren;
@@ -823,7 +857,7 @@ int VISU_OpenGLPointSpriteMapper::Draw(vtkRenderer *aren, vtkActor *act)
   // we need to know the total number of cells so that we can report progress
   this->TotalCells = input->GetVerts()->GetNumberOfCells();
 
-  this->DrawPoints(idx, points, colors, alpha, cellNum, noAbort, input->GetVerts(), ren);
+  this->DrawPoints(idx, points, colors, alpha, cellNum, noAbort, input->GetVerts(), ren, act);
 
   this->UpdateProgress(1.0);
   return noAbort;
index ac975c68a11b637de88d2c6251112f30f23116e2..5bb6033d36698b80d0181af54a05ece0bd59acd1 100755 (executable)
@@ -182,13 +182,14 @@ protected:
                               vtkIdType &cellNum,
                               int &noAbort,
                               vtkCellArray *ca,
-                              vtkRenderer *ren);
+                              vtkRenderer *ren,
+                              vtkActor *act);
 
   // Initializing OpenGL extensions
   void              InitExtensions();
 
   // Activate/deactivate Point Sprites
-  void              InitPointSprites();
+  void              InitPointSprites( vtkRenderer*, vtkActor* );
   void              CleanupPointSprites();
 
   // Initializing textures for Point Sprites
@@ -231,7 +232,7 @@ protected:
 
   vtkSmartPointer<vtkImageData> ImageData;
 
-  bool              IsUsingOpenGLMapper;
+  bool              UseOpenGLMapper;
 };
 
 #endif