Commit 085a0364 authored by Ken Martin's avatar Ken Martin

Add a point gaussian mapper for cosmology and cleanup

Add in a mapper that renders points as gaussian splats.  In
the future we can extend it a bit more to do other useful
things. It colors the points and scales then based on
arrays that are passed in.

This patch also includes a performance improvement for
the spheremapper so that it uses less memory.  It is
the same basic code as the point gaussian mapper which
is why it is in the same patch.

Change-Id: I8bce4446be063eb5d6a5eb4bc1a51e4369ba61cf
parent 129e8abc
......@@ -27,7 +27,6 @@
attribute vec4 vertexMC;
attribute vec2 offsetMC;
attribute float radiusMC;
// optional normal declaration
//VTK::Normal::Dec
......@@ -66,7 +65,7 @@ void main()
// compute the projected vertex position
vertexVCClose = MCVCMatrix * vertexMC;
centerVC = vertexVCClose.xyz;
radiusVC = radiusMC;
radiusVC = length(offsetMC)*0.5;
// make the triangle face the camera
if (cameraParallel == 0)
......
......@@ -160,12 +160,6 @@ void vtkOpenGLSphereMapper::SetMapperShaderParameters(vtkgl::CellBO &cellBO,
{
vtkErrorMacro(<< "Error setting 'offsetMC' in shader VAO.");
}
if (!cellBO.vao.AddAttributeArray(cellBO.Program, this->VBO,
"radiusMC", layout.ColorOffset+sizeof(float)*3,
layout.Stride, VTK_FLOAT, 1, false))
{
vtkErrorMacro(<< "Error setting 'radiusMC' in shader VAO.");
}
}
cellBO.Program->SetUniformf("invertedDepth", this->Invert ? -1.0 : 1.0);
......@@ -198,8 +192,8 @@ vtkgl::VBOLayout vtkOpenGLSphereMapperCreateVBO(float * points, vtkIdType numPts
layout.ColorOffset = sizeof(float) * blockSize;
++blockSize;
// three more floats
blockSize += 3;
// two more floats
blockSize += 2;
layout.Stride = sizeof(float) * blockSize;
// Create a buffer, and copy the data over.
......@@ -225,7 +219,6 @@ vtkgl::VBOLayout vtkOpenGLSphereMapperCreateVBO(float * points, vtkIdType numPts
*(it++) = *reinterpret_cast<float *>(colorPtr);
*(it++) = -2.0f*radius*cos30;
*(it++) = -radius;
*(it++) = radius;
*(it++) = pointPtr[0];
*(it++) = pointPtr[1];
......@@ -233,7 +226,6 @@ vtkgl::VBOLayout vtkOpenGLSphereMapperCreateVBO(float * points, vtkIdType numPts
*(it++) = *reinterpret_cast<float *>(colorPtr);
*(it++) = 2.0f*radius*cos30;
*(it++) = -radius;
*(it++) = radius;
*(it++) = pointPtr[0];
*(it++) = pointPtr[1];
......@@ -241,7 +233,6 @@ vtkgl::VBOLayout vtkOpenGLSphereMapperCreateVBO(float * points, vtkIdType numPts
*(it++) = *reinterpret_cast<float *>(colorPtr);
*(it++) = 0.0f;
*(it++) = 2.0f*radius;
*(it++) = radius;
}
vertexBuffer.Upload(packedVBO, vtkgl::BufferObject::ArrayBuffer);
layout.VertexCount = numPts*3;
......@@ -249,21 +240,6 @@ vtkgl::VBOLayout vtkOpenGLSphereMapperCreateVBO(float * points, vtkIdType numPts
}
}
size_t vtkOpenGLSphereMapperCreateTriangleIndexBuffer(
vtkgl::BufferObject &indexBuffer,
int numPts)
{
std::vector<unsigned int> indexArray;
indexArray.reserve(numPts * 3);
for (int i = 0; i < numPts*3; i++)
{
indexArray.push_back(i);
}
indexBuffer.Upload(indexArray, vtkgl::BufferObject::ElementArrayBuffer);
return indexArray.size();
}
//-------------------------------------------------------------------------
void vtkOpenGLSphereMapper::UpdateVBO(vtkRenderer *vtkNotUsed(ren), vtkActor *act)
{
......@@ -296,9 +272,7 @@ void vtkOpenGLSphereMapper::UpdateVBO(vtkRenderer *vtkNotUsed(ren), vtkActor *ac
this->Points.indexCount = 0;
this->Lines.indexCount = 0;
this->TriStrips.indexCount = 0;
this->Tris.indexCount =
vtkOpenGLSphereMapperCreateTriangleIndexBuffer(this->Tris.ibo,
poly->GetPoints()->GetNumberOfPoints());
this->Tris.indexCount = this->Layout.VertexCount;
}
......@@ -328,12 +302,7 @@ void vtkOpenGLSphereMapper::RenderPieceDraw(vtkRenderer* ren, vtkActor *actor)
{
// First we do the triangles, update the shader, set uniforms, etc.
this->UpdateShader(this->Tris, ren, actor);
this->Tris.ibo.Bind();
glDrawRangeElements(GL_TRIANGLES, 0,
static_cast<GLuint>(layout.VertexCount - 1),
static_cast<GLsizei>(this->Tris.indexCount),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL));
this->Tris.ibo.Release();
glDrawArrays(GL_TRIANGLES, 0,
static_cast<GLuint>(layout.VertexCount));
}
}
......@@ -53,6 +53,7 @@ set(Module_SRCS
vtkMapperCollection.cxx
vtkMapper.cxx
vtkObserverMediator.cxx
vtkPointGaussianMapper.cxx
vtkPolyDataMapper2D.cxx
vtkPolyDataMapper.cxx
vtkProp3DCollection.cxx
......@@ -159,6 +160,7 @@ set_source_files_properties(
vtkInteractorObserver
vtkMapper
vtkMapper2D
vtkPointGaussianMapper
vtkProp
vtkProp3D
vtkRendererDelegate
......
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPointGaussianMapper.h"
#include "vtkObjectFactory.h"
//-----------------------------------------------------------------------------
vtkAbstractObjectFactoryNewMacro(vtkPointGaussianMapper)
//-----------------------------------------------------------------------------
vtkPointGaussianMapper::vtkPointGaussianMapper()
{
this->ScaleArray = 0;
}
//-----------------------------------------------------------------------------
vtkPointGaussianMapper::~vtkPointGaussianMapper()
{
this->SetScaleArray(0);
}
//-----------------------------------------------------------------------------
void vtkPointGaussianMapper::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Scale Array: " << this->ScaleArray << "\n";
}
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPointGaussianMapper - draw PointGaussians using imposters
// .SECTION Description
// An mapper that uses imposters to draw PointGaussians. Supports
// transparency and picking as well.
#ifndef __vtkPointGaussianMapper_h
#define __vtkPointGaussianMapper_h
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkPolyDataMapper.h"
class VTKRENDERINGCORE_EXPORT vtkPointGaussianMapper : public vtkPolyDataMapper
{
public:
static vtkPointGaussianMapper* New();
vtkTypeMacro(vtkPointGaussianMapper, vtkPolyDataMapper)
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Convenience method to set the array to scale with.
vtkSetStringMacro(ScaleArray);
vtkGetStringMacro(ScaleArray);
protected:
vtkPointGaussianMapper();
~vtkPointGaussianMapper();
char *ScaleArray;
private:
vtkPointGaussianMapper(const vtkPointGaussianMapper&); // Not implemented.
void operator=(const vtkPointGaussianMapper&); // Not implemented.
};
#endif
......@@ -37,6 +37,7 @@ set(Module_SRCS
vtkOpenGLImageMapper.cxx
vtkOpenGLImageSliceMapper.cxx
vtkOpenGLLight.cxx
vtkOpenGLPointGaussianMapper.cxx
vtkOpenGLPolyDataMapper.cxx
vtkOpenGLPolyDataMapper2D.cxx
vtkOpenGLProperty.cxx
......@@ -112,6 +113,7 @@ set(shader_files
glsl/vtkGaussianBlurPassVS.glsl
glsl/vtkSobelGradientMagnitudePass1FS.glsl
glsl/vtkSobelGradientMagnitudePass2FS.glsl
glsl/vtkPointGaussianVS.glsl
glsl/vtkTextureObjectFS.glsl
glsl/vtkTextureObjectVS.glsl
glsl/vtkglGlyph3DVSFragmentLit.glsl
......@@ -172,6 +174,7 @@ set(opengl_overrides
ImageSliceMapper
Glyph3DMapper
Light
PointGaussianMapper
PolyDataMapper
PolyDataMapper2D
Property
......
vtk_add_test_cxx(${vtk-module}CxxTests tests
#TestRenderWidget.cxx # Very experimental, fails, does nothing useful yet.
TestPointGaussianMapper.cxx
TestVBOPLYMapper.cxx
TestVBOPointsLines.cxx
TestGaussianBlurPass.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestSprites.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .SECTION Thanks
// <verbatim>
//
// This file is part of the PointSprites plugin developed and contributed by
//
// Copyright (c) CSCS - Swiss National Supercomputing Centre
// EDF - Electricite de France
//
// John Biddiscombe, Ugo Varetto (CSCS)
// Stephane Ploix (EDF)
//
// </verbatim>
// .SECTION Description
// this program tests the point sprite support by vtkPointSpriteProperty.
#include "vtkActor.h"
#include "vtkBrownianPoints.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPointGaussianMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.h"
#include "vtkDataObject.h"
#include "vtkDataSetAttributes.h"
#include "vtkRandomAttributeGenerator.h"
#include "vtkNew.h"
#include "vtkTimerLog.h"
#include "vtkPointSource.h"
#include "vtkColorTransferFunction.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
int TestPointGaussianMapper(int argc, char *argv[])
{
int desiredPoints = 1.0e4;
vtkNew<vtkPointSource> points;
points->SetNumberOfPoints(desiredPoints);
points->SetRadius(pow(desiredPoints,0.33)*5.0);
vtkNew<vtkBrownianPoints> randomVector;
randomVector->SetMinimumSpeed(0);
randomVector->SetMaximumSpeed(1);
randomVector->SetInputConnection(points->GetOutputPort());
vtkNew<vtkRandomAttributeGenerator> randomAttr;
randomAttr->SetDataTypeToFloat();
randomAttr->GeneratePointScalarsOn();
randomAttr->GeneratePointVectorsOn();
randomAttr->SetInputConnection(randomVector->GetOutputPort());
randomAttr->Update();
vtkNew<vtkPointGaussianMapper> mapper;
mapper->SetInputConnection(randomAttr->GetOutputPort());
mapper->SetColorModeToMapScalars();
mapper->SetScalarModeToUsePointFieldData();
mapper->SelectColorArray("RandomPointVectors");
mapper->SetInterpolateScalarsBeforeMapping(0);
mapper->SetScaleArray("RandomPointScalars");
vtkNew<vtkColorTransferFunction> ctf;
ctf->AddHSVPoint(0.0,0.1,1.0,0.8);
// ctf->AddHSVPoint(0.2,0.2,0.0,1.0);
// ctf->AddHSVPoint(0.7,0.6,0.0,1.0);
ctf->AddHSVPoint(1.0,0.2,0.5,1.0);
ctf->SetColorSpaceToRGB();
mapper->SetLookupTable(ctf.Get());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.Get());
vtkNew<vtkRenderer> renderer;
renderer->SetBackground(0.0, 0.0, 0.0);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(900, 900);
renderWindow->AddRenderer(renderer.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.Get());
vtkNew<vtkTimerLog> timer;
timer->StartTimer();
renderWindow->Render();
timer->StopTimer();
double firstRender = timer->GetElapsedTime();
cerr << "first render time: " << firstRender << endl;
timer->StartTimer();
int numRenders = 85;
for (int i = 0; i < numRenders; ++i)
{
renderer->GetActiveCamera()->Azimuth(1);
renderer->GetActiveCamera()->Elevation(1);
renderWindow->Render();
}
timer->StopTimer();
double elapsed = timer->GetElapsedTime();
cerr << "interactive render time: " << elapsed / numRenders << endl;
cerr << "number of points: " << desiredPoints << endl;
cerr << "points per second: " << desiredPoints*(numRenders/elapsed) << endl;
renderer->GetActiveCamera()->SetPosition(0,0,1);
renderer->GetActiveCamera()->SetFocalPoint(0,0,0);
renderer->GetActiveCamera()->SetViewUp(0,1,0);
renderer->ResetCamera();
renderWindow->SetSize(300, 300);
renderer->GetActiveCamera()->Zoom(10.0);
renderWindow->Render();
int retVal = vtkRegressionTestImage( renderWindow.Get() );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointGaussianVS.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// this shader implements imposters in OpenGL for Spheres
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
attribute vec2 offsetMC;
//attribute float radiusMC;
// optional normal declaration
//VTK::Normal::Dec
// Texture coordinates
//VTK::TCoord::Dec
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
// material property values
//VTK::Color::Dec
// clipping plane vars
//VTK::Clip::Dec
// camera and actor matrix values
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
varying vec2 offsetVC;
uniform int cameraParallel;
void main()
{
//VTK::Color::Impl
//VTK::Normal::Impl
//VTK::TCoord::Impl
//VTK::Clip::Impl
// compute the projected vertex position
vec4 vertexVC = MCVCMatrix * vertexMC;
float radius2 = dot(offsetMC,offsetMC)*0.25;
// make the triangle face the camera
if (cameraParallel == 0)
{
vec3 dir = normalize(-vertexVC.xyz);
vec3 base2 = normalize(cross(dir,vec3(1.0,0.0,0.0)));
vec3 base1 = cross(base2,dir);
vertexVC.xyz = vertexVC.xyz + offsetMC.x*base1 + offsetMC.y*base2;
}
else
{
// add in the offset
vertexVC.xy = vertexVC.xy + offsetMC;
}
offsetVC = offsetMC/radius2;
gl_Position = VCDCMatrix * vertexVC;
}
......@@ -17,6 +17,9 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// VC positon of this fragment
//VTK::PositionVC::Dec
varying vec4 fcolor;
// Texture coordinates
......
......@@ -24,6 +24,9 @@
// DC - Display Coordinates
attribute vec4 vertexMC;
// frag position in VC
//VTK::PositionVC::Dec
// material property values
//VTK::Color::Dec
......@@ -45,5 +48,5 @@ void main()
//VTK::Clip::Impl
gl_Position = VCDCMatrix * MCVCMatrix * vertexMC;
//VTK::PositionVC::Impl
}
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkOpenGLPointGaussianMapper - draw PointGaussians using imposters
// .SECTION Description
// An OpenGL mapper that uses imposters to draw PointGaussians. Supports
// transparency and picking as well.
#ifndef __vtkOpenGLPointGaussianMapper_h
#define __vtkOpenGLPointGaussianMapper_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkPointGaussianMapper.h"
class vtkOpenGLPointGaussianMapperHelper;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPointGaussianMapper : public vtkPointGaussianMapper
{
public:
static vtkOpenGLPointGaussianMapper* New();
vtkTypeMacro(vtkOpenGLPointGaussianMapper, vtkPointGaussianMapper)
void PrintSelf(ostream& os, vtkIndent indent);
protected:
vtkOpenGLPointGaussianMapper();
~vtkOpenGLPointGaussianMapper();
virtual void RenderPiece(vtkRenderer *ren, vtkActor *act);
vtkOpenGLPointGaussianMapperHelper *Helper;
vtkTimeStamp HelperUpdateTime;
private:
vtkOpenGLPointGaussianMapper(const vtkOpenGLPointGaussianMapper&); // Not implemented.
void operator=(const vtkOpenGLPointGaussianMapper&); // Not implemented.
};
#endif
......@@ -325,16 +325,26 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(std::string &VSSource,
// handle colors / materials
this->ReplaceShaderColorMaterialValues(VSSource, FSSource, GSSource, lightComplexity, ren, actor);
VSSource = replace(VSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVC;");
VSSource = replace(VSSource,
"//VTK::PositionVC::Impl",
"vertexVC = MCVCMatrix * vertexMC;\n"
" gl_Position = VCDCMatrix * vertexVC;\n");
FSSource = replace(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVC;");
// do we need the vertex in the shader in View Coordinates
if (lightComplexity > 0)
{
VSSource = replace(VSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVC;");
VSSource = replace(VSSource,
"//VTK::PositionVC::Impl",
"vertexVC = MCVCMatrix * vertexMC;\n"
" gl_Position = VCDCMatrix * vertexVC;\n");
FSSource = replace(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVC;");
}
else
{
VSSource = replace(VSSource,
"//VTK::PositionVC::Impl",
" gl_Position = VCDCMatrix * MCVCMatrix * vertexMC;\n");
}
// normals?
if (this->Layout.NormalOffset)
......
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