#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>
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;
this->PointSpriteAlphaThreshold = 0.1;
this->PointSpriteTexture = 0;
- this->IsUsingOpenGLMapper = false;
+
+ this->UseOpenGLMapper = false;
}
//-----------------------------------------------------------------------------
VISU_OpenGLPointSpriteMapper::~VISU_OpenGLPointSpriteMapper()
(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 );
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++ )
//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;
}
//
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 );
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 );
// 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 );
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 );
}
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 );
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;
// 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;
// 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;