#include <stdio.h>
#include <cmath>
#include <string>
-#include <vector>
#ifndef VTK_IMPLEMENT_MESA_CXX
vtkCxxRevisionMacro(VISU_OpenGLPointSpriteMapper, "Revision$");
#define VTK_PDPSM_NORMAL_TYPE_FLOAT 0x0010
#define VTK_PDPSM_NORMAL_TYPE_DOUBLE 0x0020
#define VTK_PDPSM_OPAQUE_COLORS 0x0040
-#define VTK_PDPSM_ALPHA_ARRAY 0x0080
#ifndef APIENTRY
#define APIENTRY
// Construct empty object.
VISU_OpenGLPointSpriteMapper::VISU_OpenGLPointSpriteMapper()
{
+ this->RenderMode = VISU_OpenGLPointSpriteMapper::Occlude;
+
this->ListId = 0;
this->TotalCells = 0;
+ this->ActorOpacity = 0;
this->ExtensionsInitialized = 0;
- this->ExtensionsOK = 0;
- this->AlphaChannelArray = NULL;
- this->SizeChannelArray = NULL;
this->DefaultPointSize = 50.0;
- this->QuadraticPointDistanceAttenuation[0] = 1.0;
- this->QuadraticPointDistanceAttenuation[1] = 0.0;
- this->QuadraticPointDistanceAttenuation[2] = 0.0;
-
- this->RenderMode = VISU_OpenGLPointSpriteMapper::Accumulate;
this->UsePointSprites = true;
this->UseTextures = true;
{
this->ReleaseGraphicsResources(this->LastWindow);
}
- if (this->AlphaChannelArray)
- {
- delete [] this->AlphaChannelArray;
- this->AlphaChannelArray = NULL;
- }
- if (this->SizeChannelArray)
- {
- delete [] this->SizeChannelArray;
- this->SizeChannelArray = NULL;
- }
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::ShallowCopy( vtkAbstractMapper* mapper )
vglCompileShaderARB( VertexShader );
//this->PrintInfoLog( VertexShader );
- myVertexProgram = vglCreateProgramObjectARB();
- vglAttachObjectARB( myVertexProgram, VertexShader );
+ this->VertexProgram = vglCreateProgramObjectARB();
+ vglAttachObjectARB( this->VertexProgram, VertexShader );
- vglLinkProgramARB( myVertexProgram );
+ vglLinkProgramARB( this->VertexProgram );
//this->PrintInfoLog( VertexProgram );
/*
cout << "Shader from " << fileName << endl;
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetShaderVariable( const char* variable, float value )
{
- //cout << myVertexProgram << " ";
- //cout << vglGetAttribLocationARB( myVertexProgram, variable ) << " ";
+ //cout << this->VertexProgram << " ";
+ //cout << vglGetAttribLocationARB( this->VertexProgram, variable ) << " ";
//cout << variable << " " << value << endl;
- vglVertexAttrib1fARB( vglGetAttribLocationARB( myVertexProgram, variable ), value );
+ vglVertexAttrib1fARB( vglGetAttribLocationARB( this->VertexProgram, variable ), value );
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteResults( bool theResults )
if( this->UseShader )
this->InitShader();
- this->ExtensionsOK = 1;
this->ExtensionsInitialized = 1;
}
//-----------------------------------------------------------------------------
};
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::DrawPoints(int idx,
- vtkPoints *p,
+void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *p,
vtkUnsignedCharArray *colors,
vtkFloatArray *alpha,
vtkIdType &cellNum,
glPointSize( this->DefaultPointSize );
- vglUseProgramObjectARB( myVertexProgram );
+ vglUseProgramObjectARB( this->VertexProgram );
this->SetShaderVariable( "results", this->PointSpriteResults );
this->SetShaderVariable( "clamp", this->PointSpriteClamp );
}
}
- unsigned long idx = 0;
- if (colors)
- {
- idx |= VTK_PDPSM_COLORS;
- if (colors->GetName())
- {
- // In the future, I will look at the number of components.
- // All paths will have to handle 3 component colors.
- idx |= VTK_PDPSM_OPAQUE_COLORS;
- }
- }
- if (cellScalars)
- {
- idx |= VTK_PDPSM_CELL_COLORS;
- }
-
- // store the types in the index
- if (points->GetDataType() == VTK_FLOAT)
- {
- idx |= VTK_PDPSM_POINT_TYPE_FLOAT;
- }
- else if (points->GetDataType() == VTK_DOUBLE)
- {
- idx |= VTK_PDPSM_POINT_TYPE_DOUBLE;
- }
-
- if (this->AlphaChannelArray && (alpha = vtkFloatArray::SafeDownCast(input->GetPointData()->GetArray(this->AlphaChannelArray)))
- )
- {
- idx |= VTK_PDPSM_ALPHA_ARRAY;
- }
-
// 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, act);
+ this->DrawPoints(points, colors, alpha, cellNum, noAbort, input->GetVerts(), ren, act);
this->UpdateProgress(1.0);
return noAbort;
this->LastWindow = NULL;
}
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::PrintSelf(ostream& os, vtkIndent indent)
-{
- this->Superclass::PrintSelf(os,indent);
-}
-//-----------------------------------------------------------------------------
typedef GLuint GLhandleARB;
#endif
+//----------------------------------------------------------------------------
+//! OpenGL Point Sprites PolyData Mapper.
+/*!
+ * VISU_OpenGLPointSpriteMapper is a class that maps polygonal data
+ * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
+ * to the rendering/graphics hardware/software. It is now possible to set a
+ * memory limit for the pipeline in the mapper. If the total estimated memory
+ * usage of the pipeline is larger than this limit, the mapper will divide
+ * the data into pieces and render each in a for loop.
+ */
class VISU_OpenGLPointSpriteMapper : public MAPPER_SUPERCLASS
{
public:
-//BTX
- enum RenderModes {
- Accumulate=0,
- Occlude
- };
-//ETX
+ enum RenderModes { Accumulate = 0, Occlude };
+
static VISU_OpenGLPointSpriteMapper *New();
vtkTypeRevisionMacro(VISU_OpenGLPointSpriteMapper,MAPPER_SUPERCLASS);
- virtual void PrintSelf(ostream& os, vtkIndent indent);
void ShallowCopy(vtkAbstractMapper*);
- // Description:
- // Specify the name of a scalar array which will be used to control
- // the alpha value of each point. The values should be between 0,1
- vtkSetStringMacro(AlphaChannelArray);
- vtkGetStringMacro(AlphaChannelArray);
-
- // Description:
- // Specify the name of a scalar array which will be used to control
- // the size of each point.
- // NOT YET IMPLEMENTED
- vtkSetStringMacro(SizeChannelArray);
- vtkGetStringMacro(SizeChannelArray);
-
- // Description:
- // Set the initial point size to be used. This value forms the
- // base upon which the distance attenuation acts.
- // Usually the pointsize is set to the maximum supported by the graphics
- // card for sprite display, then the quadratic factors are adjusted to
- // bring the size down.
- // Set the default size to -1 if you wish the value returned by
- // glGetFloatv( GL_POINT_SIZE_MAX_ARB, &MaximimSupportedSize );
- // to be used as the initial default point size.
+ //! Set the initial point size to be used.
+ /*!
+ * This value forms the base upon which the distance attenuation acts.
+ * Usually the pointsize is set to the maximum supported by the graphics
+ * card for sprite display, then the quadratic factors are adjusted to
+ * bring the size down.
+ */
vtkSetMacro(DefaultPointSize, float);
+
+ //! Get the initial point size to be used.
vtkGetMacro(DefaultPointSize, float);
- // Description:
- // Set the 3 values (a,b,c) of the parametric function which controls the
- // reduction in point size with increasing distance (d).
- // e.g. (1,0,0) will give all points the same size regardless of distance.
- // @verbatim
- // point fading = _____1_______
- // (a + bd + cd^2)
- // @endverbatim
- vtkSetVector3Macro(QuadraticPointDistanceAttenuation, float);
- vtkGetVector3Macro(QuadraticPointDistanceAttenuation, float);
-
- // Description:
- // Set/Get the RenderMode for this mapper. Currently 2 modes are supported
- // Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing
- // so that points are accumulated. Suitable for Galaxy plots.
- // Occlude : No blending. Particles are solid spheres and depth testing is
- // used as usual. Suitable for most particle simulations without the need
- // for opacity.
+ //! Set the RenderMode for the mapper.
+ /*!
+ * Accumulate : Uses glBlendFunc(GL_SRC_ALPHA, GL_ONE), and no depth testing
+ * so that points are accumulated. Suitable for Galaxy plots.
+ * Occlude : No blending. Particles are solid spheres and depth testing is
+ * used as usual. Suitable for most particle simulations without the need
+ * for opacity.
+ */
vtkSetMacro(RenderMode, int);
+
+ //! Get the RenderMode for the mapper.
vtkGetMacro(RenderMode, int);
- void SetRenderModeToAccumulate() { this->SetRenderMode(Accumulate); }
- void SetRenderModeToOcclude() { this->SetRenderMode(Occlude); }
- // Description:
- // Implement superclass render method.
+ //! Implement superclass render method.
virtual void RenderPiece(vtkRenderer *ren, vtkActor *a);
- // Description:
- // Release any graphics resources that are being consumed by this mapper.
- // The parameter window could be used to determine which graphic
- // resources to release.
+ //! Release any graphics resources that are being consumed by this mapper.
void ReleaseGraphicsResources(vtkWindow *);
- // Description:
- // Draw method for OpenGL.
+ //! Draw method for OpenGL.
virtual int Draw(vtkRenderer *ren, vtkActor *a);
- // Description:
- // Return the maximum point size supported by the graphics hardware.
+ //! Return the maximum point size supported by the graphics hardware.
float GetMaximumSupportedSize();
- // Set/Get usage of Point Sprites
+ //! Set usage of #vtkOpenGLPolyDataMapper.
+ /*!
+ * This flags prevents using of the VISU_OpenGLPointSpriteMapper
+ * (#vtkOpenGLPolyDataMapper is using instead).
+ */
+ vtkSetMacro(UseOpenGLMapper, bool);
+
+ //! Get usage of #vtkOpenGLPolyDataMapper.
+ vtkGetMacro(UseOpenGLMapper, bool);
+
+ //! Set usage of Point Sprites.
vtkSetMacro(UsePointSprites, bool);
+
+ //! Get usage of Point Sprites.
vtkGetMacro(UsePointSprites, bool);
- // Set/Get usage of textures for Point Sprites
- // (only if usage of Point Sprites is turned on)
+ //! Set usage of textures for Point Sprites.
+ /*! Works only if usage of Point Sprites is turned on. */
vtkSetMacro(UseTextures, bool);
+
+ //! Get usage of textures for Point Sprites.
vtkGetMacro(UseTextures, bool);
- // Set/Get usage of vertex shader
- // (only if usage of Point Sprites is turned on)
+ // Set usage of vertex shader.
+ /*! Works only if usage of Point Sprites is turned on. */
vtkSetMacro(UseShader, bool);
+
+ // Get usage of vertex shader.
vtkGetMacro(UseShader, bool);
- // Description:
- // Point Sprite drawing mode
- // (Results - multicolor, Geometry - fixed color)
- vtkGetMacro(PointSpriteResults, bool);
+ //! Set Point Sprite drawing mode.
+ /*! Results - multicolor, Geometry - fixed color. */
void SetPointSpriteResults( bool );
- // Description:
- // Point Sprite size parameters
- vtkGetMacro(PointSpriteClamp, float);
- vtkGetMacro(PointSpriteSize, float);
- vtkGetMacro(PointSpriteMinSize, float);
- vtkGetMacro(PointSpriteMaxSize, float);
- vtkGetMacro(PointSpriteMagnification, float);
+ //! Get Point Sprite drawing mode.
+ vtkGetMacro(PointSpriteResults, bool);
+ //! Set Point Sprite Clamp.
void SetPointSpriteClamp( float );
+
+ //! Get Point Sprite Clamp.
+ vtkGetMacro(PointSpriteClamp, float);
+
+ //! Set Point Sprite Const Size.
void SetPointSpriteSize( float );
+
+ //! Get Point Sprite Const Size.
+ vtkGetMacro(PointSpriteSize, float);
+
+ //! Set Point Sprite Minimum Size.
void SetPointSpriteMinSize( float );
+
+ //! Get Point Sprite Minimum Size.
+ vtkGetMacro(PointSpriteMinSize, float);
+
+ //! Set Point Sprite Maximum Size.
void SetPointSpriteMaxSize( float );
+
+ //! Get Point Sprite Maximum Size.
+ vtkGetMacro(PointSpriteMaxSize, float);
+
+ //! Set Point Sprite Magnification.
void SetPointSpriteMagnification( float );
- vtkGetMacro(PointSpriteAlphaThreshold, float);
+ //! Get Point Sprite Magnification.
+ vtkGetMacro(PointSpriteMagnification, float);
+
+ //! Set Point Sprite AlphaThreshold.
void SetPointSpriteAlphaThreshold( float );
+ //! Get Point Sprite AlphaThreshold.
+ vtkGetMacro(PointSpriteAlphaThreshold, float);
+
+ //! Set ImageData for Point Sprite Texture.
void SetImageData(vtkImageData* theImageData);
+
+ //! Get ImageData for Point Sprite Texture.
vtkImageData* GetImageData();
protected:
VISU_OpenGLPointSpriteMapper();
~VISU_OpenGLPointSpriteMapper();
- void DrawPoints(int idx,
- vtkPoints *p,
+ //! Internal method of the Point Sprites drawing.
+ void DrawPoints(vtkPoints *p,
vtkUnsignedCharArray *c,
vtkFloatArray *alpha,
vtkIdType &cellNum,
vtkRenderer *ren,
vtkActor *act);
- // Initializing OpenGL extensions
+ //! Initializing OpenGL extensions.
void InitExtensions();
- // Activate/deactivate Point Sprites
+ //! Activate Point Sprites.
void InitPointSprites();
+
+ //! Deactivate Point Sprites.
void CleanupPointSprites();
- // Initializing textures for Point Sprites
+ //! Initializing textures for Point Sprites.
void InitTextures();
+ //! Initializing of the Vertex Shader.
+ void InitShader();
+
+ //! Set Vertex Shader variable.
+ void SetShaderVariable( const char* variable, float value );
+
+ //! Getting information about Vertex Shader compiling and linking.
+ void PrintInfoLog( GLhandleARB );
+
+private:
+ bool UseOpenGLMapper;
+
bool UsePointSprites;
bool UseTextures;
bool UseShader;
-
- vtkIdType TotalCells;
-
+ int RenderMode;
int ListId;
- int ExtensionsInitialized;
- int ExtensionsOK;
- char *AlphaChannelArray;
+ vtkIdType TotalCells;
double ActorOpacity;
- char *SizeChannelArray;
+ int ExtensionsInitialized;
float DefaultPointSize;
- float QuadraticPointDistanceAttenuation[3];
- int RenderMode;
- void InitShader();
- void PrintInfoLog( GLhandleARB );
- void SetShaderVariable( const char* variable, float value );
-
- GLhandleARB myVertexProgram;
+ //! Vertex Program handle.
+ GLhandleARB VertexProgram;
bool PointSpriteResults;
float PointSpriteAlphaThreshold;
vtkSmartPointer<vtkImageData> ImageData;
-
- bool UseOpenGLMapper;
};
#endif