Commit 86b6ca6e authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'more_point_sprite'

2fda9d28 Add method to set the triangle scale
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !652
parents fec2e498 2fda9d28
......@@ -37,6 +37,7 @@ vtkPointGaussianMapper::vtkPointGaussianMapper()
this->ScaleFactor = 1.0;
this->Emissive = 1;
this->TriangleScale = 3.0;
}
//-----------------------------------------------------------------------------
......@@ -61,4 +62,5 @@ void vtkPointGaussianMapper::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Emissive: " << this->Emissive << "\n";
os << indent << "OpacityTableSize: " << this->OpacityTableSize << "\n";
os << indent << "ScaleTableSize: " << this->ScaleTableSize << "\n";
os << indent << "TriangleScale: " << this->TriangleScale << "\n";
}
......@@ -13,9 +13,12 @@
=========================================================================*/
// .NAME vtkPointGaussianMapper - draw PointGaussians using imposters
// .SECTION Description
// An mapper that uses imposters to draw PointGaussians. Supports
// transparency and picking as well. It draws all the points and
// does not require or look at any cell arrays
// An mapper that uses imposters to draw gaussian splats or other shapes if
// custom shader code is set. Supports transparency and picking as well. It
// draws all the points and does not require cell arrays. If cell arrays are
// provided it will only draw the points used by the Verts cell array. The shape
// of the imposter is a triangle.
#ifndef vtkPointGaussianMapper_h
#define vtkPointGaussianMapper_h
......@@ -94,6 +97,21 @@ public:
vtkSetStringMacro(SplatShaderCode);
vtkGetStringMacro(SplatShaderCode);
// Description:
// When drawing triangles as opposed too point mode
// (triangles are for splats shaders that are bigger than a pixel)
// this controls how large the triangle will be. By default it
// is large enough to contain a cicle of radius 3.0*scale which works
// well for gaussian splats as after 3.0 standard deviations the
// opacity is near zero. For custom shader codes a different
// value can be used. Generally you should use the lowest value you can
// as it will result in fewer fragments. For example if your custom
// shader only draws a disc of radius 1.0*scale, then set this to 1.0
// to avoid sending many fragments to the shader that will just get
// discarded.
vtkSetMacro(TriangleScale,float);
vtkGetMacro(TriangleScale,float);
protected:
vtkPointGaussianMapper();
~vtkPointGaussianMapper();
......@@ -111,6 +129,8 @@ protected:
double ScaleFactor;
int Emissive;
float TriangleScale;
private:
vtkPointGaussianMapper(const vtkPointGaussianMapper&); // Not implemented.
void operator=(const vtkPointGaussianMapper&); // Not implemented.
......
......@@ -90,7 +90,7 @@ int TestPointGaussianMapper(int argc, char *argv[])
mapper->SetInputConnection(randomAttr->GetOutputPort());
mapper->SelectColorArray("RandomPointVectors");
mapper->SetScalarModeToUsePointFieldData();
mapper->SetDefaultRadius(0.0);
mapper->SetScaleFactor(0.0);
mapper->EmissiveOff();
#endif
......@@ -102,7 +102,7 @@ int TestPointGaussianMapper(int argc, char *argv[])
mapper->SetInputConnection(reader->GetOutputPort());
mapper->SelectColorArray("Color");
mapper->SetScalarModeToUsePointFieldData();
mapper->SetDefaultRadius(0.0);
mapper->SetScalefactor(0.0);
mapper->EmissiveOff();
//actor->GetProperty()->SetPointSize(3.0);
......
......@@ -109,6 +109,10 @@ int TestPointGaussianMapperOpacity(int argc, char *argv[])
" if (abs(offsetVCVSOutput.x) < 0.6 && abs(offsetVCVSOutput.y) < 0.6) { discard; }\n"
);
// since this shader only uses a radus of sqrt(2) we will adjust the mapper
// to render a smaller area than the default radius of 3.0
mapper->SetTriangleScale(1.5);
vtkNew<vtkColorTransferFunction> ctf;
ctf->AddHSVPoint(0.0,0.1,0.7,1.0);
ctf->AddHSVPoint(1.0,0.9,0.7,1.0);
......
......@@ -39,6 +39,8 @@ attribute vec2 offsetMC;
varying vec2 offsetVCVSOutput;
uniform int cameraParallel;
uniform float triangleScale;
void main()
{
//VTK::Color::Impl
......@@ -53,10 +55,10 @@ void main()
vec4 vertexVC = MCVCMatrix * vertexMC;
// the offsets sent down are positioned
// at 2.0*radius*3.0 from the center of the
// at 2.0*radius*triangleScale from the center of the
// gaussian. This has to be consistent
// with the offsets we build into the VBO
float radius = sqrt(dot(offsetMC,offsetMC))/6.0;
float radius = 0.5*sqrt(dot(offsetMC,offsetMC))/triangleScale;
// make the triangle face the camera
if (cameraParallel == 0)
......
......@@ -56,6 +56,7 @@ public:
float *ScaleTable; // the table
double ScaleScale; // used for quick lookups
double ScaleOffset; // used for quick lookups
double TriangleScale;
protected:
vtkOpenGLPointGaussianMapperHelper();
......@@ -186,7 +187,6 @@ void vtkOpenGLPointGaussianMapperHelper::ReplaceShaderColor(
// compute the eye position and unit direction
"//VTK::Color::Impl\n"
" float dist2 = dot(offsetVCVSOutput.xy,offsetVCVSOutput.xy);\n"
" if (dist2 > 9.0) { discard; }\n"
" float gaussian = exp(-0.5*dist2);\n"
" opacity = opacity*gaussian;"
// " opacity = opacity*0.5;"
......@@ -286,11 +286,13 @@ void vtkOpenGLPointGaussianMapperHelper::SetCameraShaderParameters(vtkOpenGLHelp
}
//-----------------------------------------------------------------------------
void vtkOpenGLPointGaussianMapperHelper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
vtkRenderer *ren, vtkActor *actor)
void vtkOpenGLPointGaussianMapperHelper::SetMapperShaderParameters(
vtkOpenGLHelper &cellBO,
vtkRenderer *ren, vtkActor *actor)
{
if (!this->UsingPoints)
{
cellBO.Program->SetUniformf("triangleScale",this->TriangleScale);
if (cellBO.IBO->IndexCount && (this->VBOBuildTime > cellBO.AttributeUpdateTime ||
cellBO.ShaderSourceTime > cellBO.AttributeUpdateTime))
{
......@@ -374,7 +376,7 @@ void vtkOpenGLPointGaussianMapperHelperPackVBOTemplate3(
(tindex - itindex)*self->ScaleTable[itindex+1];
}
radius *= defaultScale;
radius *= 3.0;
radius *= self->TriangleScale;
float radiusFloat = static_cast<float>(radius);
float cos30 = cos(vtkMath::RadiansFromDegrees(30.0));
......@@ -562,6 +564,9 @@ void vtkOpenGLPointGaussianMapperHelper::BuildBufferObjects(
return;
}
// set the triangle scale
this->TriangleScale = this->Owner->GetTriangleScale();
bool hasScaleArray = this->Owner->GetScaleArray() != NULL &&
poly->GetPointData()->HasArray(this->Owner->GetScaleArray());
if (hasScaleArray && this->Owner->GetScaleFunction())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment