From: ouv Date: Thu, 29 Sep 2005 09:06:38 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: BR-D5-38-2003_D2005-12-10~112 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2f9802ccd3def10d16df47a2665fc0debe9892bb;p=modules%2Fvisu.git *** empty log message *** --- diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx index 67267890..e7259462 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.cxx @@ -27,23 +27,23 @@ #include "VISU_OpenGLPointSpriteMapper.hxx" +#include #include #include #include #include #include +#include #include #include #include +#include #include #include #include #include #include #include -#include -#include -#include #include //#include @@ -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; diff --git a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx index ac975c68..5bb6033d 100755 --- a/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx +++ b/src/PIPELINE/VISU_OpenGLPointSpriteMapper.hxx @@ -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 ImageData; - bool IsUsingOpenGLMapper; + bool UseOpenGLMapper; }; #endif