#include <vtkDataSet.h>
#include <vtkMath.h>
+static float Tolerance = 1.0 / VTK_LARGE_FLOAT;
+
using namespace std;
vtkStandardNewMacro(VISU_FieldTransform);
-double VISU_FieldTransform::Ident(double theArg){
+double
+VISU_FieldTransform
+::Ident(double theArg)
+{
return theArg;
}
-double VISU_FieldTransform::Log10(double theArg){
- if(theArg <= 0.0) return -VTK_LARGE_FLOAT;
+
+double
+VISU_FieldTransform
+::Log10(double theArg)
+{
+ if(theArg <= 0.0)
+ return -VTK_LARGE_FLOAT;
+
return log10(theArg);
}
-VISU_FieldTransform::VISU_FieldTransform(){
+VISU_FieldTransform
+::VISU_FieldTransform()
+{
myFunction = &Ident;
myTransform = NULL;
}
-VISU_FieldTransform::~VISU_FieldTransform() {
+VISU_FieldTransform
+::~VISU_FieldTransform()
+{
SetSpaceTransform(NULL);
}
-void VISU_FieldTransform::Update(){
- if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime())
- Modified();
+void
+VISU_FieldTransform
+::Update()
+{
vtkSource::Update();
}
-unsigned long VISU_FieldTransform::GetMTime(){
- if(myTransform && myTransform->GetMTime() > vtkSource::GetMTime())
- return myTransform->GetMTime();
- return vtkSource::GetMTime();
+unsigned long
+VISU_FieldTransform
+::GetMTime()
+{
+ unsigned long aTime = Superclass::GetMTime();
+ if(myTransform)
+ aTime = max(aTime,myTransform->GetMTime());
+
+ return aTime;
}
-void VISU_FieldTransform::SetScalarTransform(TTransformFun theFunction) {
+void
+VISU_FieldTransform
+::SetScalarTransform(TTransformFun theFunction)
+{
+ if(myFunction == theFunction)
+ return;
+
+ if(theFunction == NULL)
+ theFunction = &Ident;
+
myFunction = theFunction;
- if(myFunction == NULL) myFunction = &Ident;
+
Modified();
}
void VISU_FieldTransform::SetSpaceTransform(VTKViewer_Transform* theTransform){
- if(myTransform != theTransform){
- if (myTransform != NULL) myTransform->UnRegister(this);
- myTransform = theTransform;
- if (myTransform != NULL) myTransform->Register(this);
- this->Modified();
- }
+ if(myTransform == theTransform)
+ return;
+
+ if(myTransform != NULL)
+ myTransform->UnRegister(this);
+
+ myTransform = theTransform;
+
+ if(theTransform != NULL)
+ theTransform->Register(this);
+
+ Modified();
}
-void VISU_FieldTransform::SetScalarRange(float theScalarRange[2]) {
+void
+VISU_FieldTransform
+::SetScalarRange(float theScalarRange[2])
+{
+ float aDelta =
+ fabs(myScalarRange[0] - theScalarRange[0]) +
+ fabs(myScalarRange[1] - theScalarRange[1]);
+ if(aDelta < Tolerance)
+ return;
+
myScalarRange[0] = theScalarRange[0];
myScalarRange[1] = theScalarRange[1];
+
Modified();
}
-void VISU_FieldTransform::SetScalarMin(float theValue){
+
+void
+VISU_FieldTransform
+::SetScalarMin(float theValue)
+{
float aScalarRange[2] = {theValue, GetScalarRange()[1]};
SetScalarRange(aScalarRange);
}
-void VISU_FieldTransform::SetScalarMax(float theValue){
+
+void
+VISU_FieldTransform
+::SetScalarMax(float theValue)
+{
float aScalarRange[2] = {GetScalarRange()[0], theValue};
SetScalarRange(aScalarRange);
}
newScalars->Delete();
}
-void VISU_FieldTransform::Execute(){
+void
+VISU_FieldTransform
+::Execute()
+{
vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
output->CopyStructure(input);
if(myFunction != &Ident || (myTransform && !myTransform->IsIdentity())){
#include <vtkTimerLog.h>
#include <vtkTriangle.h>
-//#include <GL/glext.h>
-
#include <dlfcn.h>
#include <stdio.h>
};
static int IsARBInitialized = InitializeARB();
+static float Tolerance = 1.0 / VTK_LARGE_FLOAT;
//-----------------------------------------------------------------------------
// Construct empty object.
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPrimitiveType( int thePrimitiveType )
{
+ if(this->PrimitiveType == thePrimitiveType)
+ return;
+
this->PrimitiveType = thePrimitiveType;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteMode( int theMode )
{
+ if(this->PointSpriteMode == theMode)
+ return;
+
this->PointSpriteMode = theMode;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteClamp( float theClamp )
{
+ if(fabs(this->PointSpriteClamp - theClamp) < Tolerance)
+ return;
+
this->PointSpriteClamp = theClamp;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteSize( float theSize )
{
+ if(fabs(this->PointSpriteSize - theSize) < Tolerance)
+ return;
+
this->PointSpriteSize = theSize;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteMinSize( float theMinSize )
{
+ if(fabs(this->PointSpriteMinSize - theMinSize) < Tolerance)
+ return;
+
this->PointSpriteMinSize = theMinSize;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteMaxSize( float theMaxSize )
{
+ if(fabs(this->PointSpriteMaxSize - theMaxSize) < Tolerance)
+ return;
+
this->PointSpriteMaxSize = theMaxSize;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteMagnification( float theMagnification )
{
+ if(fabs(this->PointSpriteMagnification - theMagnification) < Tolerance)
+ return;
+
this->PointSpriteMagnification = theMagnification;
this->Modified();
}
//-----------------------------------------------------------------------------
void VISU_OpenGLPointSpriteMapper::SetPointSpriteAlphaThreshold( float theAlphaThreshold )
{
+ if(fabs(this->PointSpriteAlphaThreshold - theAlphaThreshold) < Tolerance)
+ return;
+
this->PointSpriteAlphaThreshold = theAlphaThreshold;
this->Modified();
}
}
//-----------------------------------------------------------------------------
-void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *p,
- vtkUnsignedCharArray *colors,
- vtkFloatArray *alpha,
- vtkIdType &cellNum,
- int &noAbort,
- vtkCellArray *cells,
- vtkRenderer *ren,
- vtkActor* act)
+void VISU_OpenGLPointSpriteMapper::DrawPoints(vtkPoints *thePoints,
+ vtkUnsignedCharArray *theColors,
+ vtkFloatArray *theAlpha,
+ vtkIdType &theCellNum,
+ int &theNoAbort,
+ vtkCellArray *theCells,
+ vtkRenderer *theRenderer,
+ vtkActor* theActor)
{
if( this->UsePointSprites ) //&& this->PrimitiveType == VISU_OpenGLPointSpriteMapper::PointSprite )
this->InitPointSprites();
this->SetShaderVariable( "clamp_size", this->PointSpriteClamp );
- TVertex* aVertex = new TVertex[ this->TotalCells ];
+ TVertex* aVertexArr = new TVertex[ this->TotalCells ];
+
+ float* aPropertyColor = theActor->GetProperty()->GetColor();
+ float aColor[3] = {aPropertyColor[0], aPropertyColor[1], aPropertyColor[2]};
+ int aRed = int(255*aColor[0]), aGreen = int(255*aColor[1]), aBlue = int(255*aColor[1]);
+ float aHue = ComputeHue( aRed, aGreen, aBlue );
- float* aPropertyColor = act->GetProperty()->GetColor();
- float aPropertyColorRed = aPropertyColor[0];
- float aPropertyColorGreen = aPropertyColor[1];
- float aPropertyColorBlue = aPropertyColor[2];
+ float aViewToDisplay = ViewToDisplay( theRenderer );
+ float aSize = this->PointSpriteSize;
+ unsigned long i = 0;
vtkIdType *pts = 0;
vtkIdType npts = 0;
- unsigned long i = 0;
- for( cells->InitTraversal(); cells->GetNextCell( npts, pts ); i++ )
+ for( theCells->InitTraversal(); theCells->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];
-
- float red, green, blue;
- if( colors && this->PointSpriteMode != 1 )
- {
- unsigned char *col = colors->GetPointer(pts[0]<< 2);
- red = ( ( int )col[0] ) / 255.0;
- green = ( ( int )col[1] ) / 255.0;
- blue = ( ( int )col[2] ) / 255.0;
- }
- else
+ TVertex& aVertex = aVertexArr[i];
+ vtkIdType aPointId = pts[0];
+ float* aCoords = thePoints->GetPoint( aPointId );
+ aVertex.vx = aCoords[0];
+ aVertex.vy = aCoords[1];
+ aVertex.vz = aCoords[2];
+
+ int aRed, aGreen, aBlue;
+ if( theColors && this->PointSpriteMode != 1 )
{
- red = aPropertyColorRed;
- green = aPropertyColorGreen;
- blue = aPropertyColorBlue;
+ unsigned char *col = theColors->GetPointer(pts[0] << 2);
+ aRed = int(col[0]);
+ aGreen = int(col[1]);
+ aBlue = int(col[2]);
+
+ aColor[0] = aRed / 255.0;
+ aColor[1] = aGreen / 255.0;
+ aColor[2] = aBlue / 255.0;
}
- aVertex[i].r = red;
- aVertex[i].g = green;
- aVertex[i].b = blue;
+ aVertex.r = aColor[0];
+ aVertex.g = aColor[1];
+ aVertex.b = aColor[2];
- float size = 0.0;
if( this->PointSpriteMode == 0 )
{
- float h = ComputeHue( ( int )( red * 255 ), ( int )( green * 255 ), ( int )( blue * 255 ) );
- size = this->PointSpriteMinSize + ( PointSpriteMaxSize - PointSpriteMinSize ) * ( 1 - h / 241.0f );
+ aHue = ComputeHue( aRed, aGreen, aBlue );
+ aSize = this->PointSpriteMinSize + ( PointSpriteMaxSize - PointSpriteMinSize ) * ( 1 - aHue / 241.0f );
}
else
- size = this->PointSpriteSize;
+ aSize = this->PointSpriteSize;
- aVertex[i].hue = ViewToDisplay( ren ) * this->AverageCellSize * this->PointSpriteMagnification * size;
+ aVertex.hue = aViewToDisplay * this->AverageCellSize * this->PointSpriteMagnification * aSize;
}
GLuint aBufferObjectID = 0;
vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );
int nArrayObjectSize = sizeof( TVertex ) * this->TotalCells;
- vglBufferDataARB( GL_ARRAY_BUFFER_ARB, nArrayObjectSize, aVertex, GL_STATIC_DRAW_ARB );
+ vglBufferDataARB( GL_ARRAY_BUFFER_ARB, nArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB );
- delete [] aVertex;
+ delete [] aVertexArr;
vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID );