Renamed vertex classes to the far more meaningful 'CubicVertex' and 'MarchingCubesVertex'. The old names didn't make much sense, even less so now they are templatized.

This commit is contained in:
David Williams
2014-05-11 15:17:59 +02:00
parent ae87dbee77
commit 573c36db87
24 changed files with 147 additions and 126 deletions

View File

@ -14,7 +14,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal<uint8_t> >& surfaceMesh)
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<CubicVertex<uint8_t> >& surfaceMesh)
{
//Convienient access to the vertices and indices
const auto& vecIndices = surfaceMesh.getIndices();
@ -27,7 +27,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
//The GL_ARRAY_BUFFER will contain the list of vertex positions
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<uint8_t>), vecVertices.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(CubicVertex<uint8_t>), vecVertices.data(), GL_STATIC_DRAW);
//and GL_ELEMENT_ARRAY_BUFFER will contain the indices
glGenBuffers(1, &indexBuffer);
@ -36,7 +36,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
//We need to tell OpenGL how to understand the format of the vertex data
glEnableVertexAttribArray(0); //We're talking about shader attribute '0'
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterialNormal<uint8_t>), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(CubicVertex<uint8_t>), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type)
glBindVertexArray(0);

View File

@ -42,7 +42,7 @@ public:
void mousePressEvent(QMouseEvent* event);
//Convert a SurfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<uint8_t> >& surfaceMesh);
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<uint8_t> >& surfaceMesh);
protected:
//Qt OpenGL functions

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[])
createSphereInVolume(volData, 30);
//A mesh object to hold the result of surface extraction
SurfaceMesh<PositionMaterialNormal<uint8_t> > mesh;
SurfaceMesh<CubicVertex<uint8_t> > mesh;
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
CubicSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);

View File

@ -29,9 +29,9 @@ freely, subject to the following restrictions:
using namespace PolyVox;
using namespace std;
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& mesh, unsigned int uLodLevel)
void renderRegionImmediateMode(PolyVox::SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> >& mesh, unsigned int uLodLevel)
{
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
const vector<MarchingCubesVertex<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex;
@ -41,7 +41,7 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh<PositionMaterialNormal<Mater
//for(vector<PolyVox::uint32_t>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
for(int index = beginIndex; index < endIndex; ++index)
{
const PositionMaterialNormal<MaterialDensityPair44> & vertex = vecVertices[vecIndices[index]];
const MarchingCubesVertex<MaterialDensityPair44> & vertex = vecVertices[vecIndices[index]];
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());

View File

@ -29,6 +29,6 @@ freely, subject to the following restrictions:
#include "glew/glew.h"
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& mesh, unsigned int uLodLevel);
void renderRegionImmediateMode(PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >& mesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__

View File

@ -30,7 +30,7 @@ freely, subject to the following restrictions:
using namespace PolyVox;
using namespace std;
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& mesh)
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> >& mesh)
{
//Represents our filled in OpenGL vertex and index buffer objects.
OpenGLSurfaceMesh result;
@ -39,7 +39,7 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
result.sourceMesh = &mesh;
//Convienient access to the vertices and indices
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
const vector<MarchingCubesVertex<MaterialDensityPair44> >& vecVertices = mesh.getVertices();
const vector<uint32_t>& vecIndices = mesh.getIndices();
//If we have any indices...
@ -63,9 +63,9 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNorma
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(GLfloat) * 9, 0, GL_STATIC_DRAW);
GLfloat* ptr = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
for (vector<PositionMaterialNormal<MaterialDensityPair44> >::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
for (vector<MarchingCubesVertex<MaterialDensityPair44> >::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
{
const PositionMaterialNormal<MaterialDensityPair44> & vertex = *iterVertex;
const MarchingCubesVertex<MaterialDensityPair44> & vertex = *iterVertex;
const Vector3DFloat& v3dVertexPos = vertex.getPosition();
//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());

View File

@ -33,10 +33,10 @@ struct OpenGLSurfaceMesh
GLulong noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >* sourceMesh;
const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >* sourceMesh;
};
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& mesh);
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> >& mesh);
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__

View File

@ -87,7 +87,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume<MaterialDensityPair44>* volDat
//Extract the surface for this region
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
std::shared_ptr< SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > > mesh(new SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >);
std::shared_ptr< SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> > > mesh(new SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> >);
MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get());
surfaceExtractor.execute();
@ -193,7 +193,7 @@ void OpenGLWidget::paintGL()
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
{
std::shared_ptr< SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
std::shared_ptr< SurfaceMesh<MarchingCubesVertex<MaterialDensityPair44> > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
if(m_bUseOpenGLVertexBufferObjects)
{

View File

@ -88,7 +88,7 @@ class OpenGLWidget : public QGLWidget
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh, Vector3DUint8Compare> m_mapOpenGLSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> > >, Vector3DUint8Compare> m_mapSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, std::shared_ptr<PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<PolyVox::MaterialDensityPair44> > >, Vector3DUint8Compare> m_mapSurfaceMeshes;
unsigned int m_uRegionSideLength;
unsigned int m_uVolumeWidthInRegions;

View File

@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> >& surfaceMesh)
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<CubicVertex<MaterialDensityPair44> >& surfaceMesh)
{
if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0))
{
@ -25,7 +25,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
//Convienient access to the vertices and indices
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
const vector<PositionMaterialNormal<MaterialDensityPair44> >& vecVertices = surfaceMesh.getVertices();
const vector<CubicVertex<MaterialDensityPair44> >& vecVertices = surfaceMesh.getVertices();
//Build an OpenGL index buffer
glGenBuffers(1, &indexBuffer);
@ -37,7 +37,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<MaterialDensityPair44>), pVertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(CubicVertex<MaterialDensityPair44>), pVertices, GL_STATIC_DRAW);
m_uBeginIndex = 0;
m_uEndIndex = vecIndices.size();
@ -109,8 +109,8 @@ void OpenGLWidget::paintGL()
//Bind the vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal<MaterialDensityPair44>), 0);
//glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal<MaterialDensityPair44>), (GLvoid*)12);
glVertexPointer(3, GL_FLOAT, sizeof(CubicVertex<MaterialDensityPair44>), 0);
//glNormalPointer(GL_FLOAT, sizeof(CubicVertex<MaterialDensityPair44>), (GLvoid*)12);
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
}

View File

@ -42,7 +42,7 @@ public:
void mousePressEvent(QMouseEvent* event);
//Convert a SrfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<PolyVox::MaterialDensityPair44> >& surfaceMesh);
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<PolyVox::MaterialDensityPair44> >& surfaceMesh);
protected:
//Qt OpenGL functions

View File

@ -186,7 +186,7 @@ int main(int argc, char *argv[])
std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl;
//Extract the surface
SurfaceMesh<PositionMaterialNormal<MaterialDensityPair44> > mesh;
SurfaceMesh<CubicVertex<MaterialDensityPair44> > mesh;
CubicSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
//MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);

View File

@ -21,11 +21,11 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterialNormal<uint8_t> >& surfaceMesh)
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<MarchingCubesVertex<uint8_t> >& surfaceMesh)
{
//Convienient access to the vertices and indices
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
const vector<PositionMaterialNormal<uint8_t> >& vecVertices = surfaceMesh.getVertices();
const vector<MarchingCubesVertex<uint8_t> >& vecVertices = surfaceMesh.getVertices();
//Build an OpenGL index buffer
glGenBuffers(1, &indexBuffer);
@ -37,17 +37,17 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<uint8_t>), pVertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(MarchingCubesVertex<uint8_t>), pVertices, GL_STATIC_DRAW);
m_uBeginIndex = 0;
m_uEndIndex = vecIndices.size();
}
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PositionMaterialNormal<uint8_t> >& surfaceMesh)
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<MarchingCubesVertex<uint8_t> >& surfaceMesh)
{
//Convienient access to the vertices and indices
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
const vector<PositionMaterialNormal<uint8_t> >& vecVertices = surfaceMesh.getVertices();
const vector<MarchingCubesVertex<uint8_t> >& vecVertices = surfaceMesh.getVertices();
//Build an OpenGL index buffer
glGenBuffers(1, &indexBufferLow);
@ -59,7 +59,7 @@ void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<Posit
glGenBuffers(1, &vertexBufferLow);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal<uint8_t>), pVertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(MarchingCubesVertex<uint8_t>), pVertices, GL_STATIC_DRAW);
m_uBeginIndexLow = 0;
m_uEndIndexLow = vecIndices.size();
@ -152,8 +152,8 @@ void OpenGLWidget::paintGL()
//Bind the vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), 0);
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), (GLvoid*)12);
glVertexPointer(3, GL_FLOAT, sizeof(MarchingCubesVertex<uint8_t>), 0);
glNormalPointer(GL_FLOAT, sizeof(MarchingCubesVertex<uint8_t>), (GLvoid*)12);
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
@ -162,8 +162,8 @@ void OpenGLWidget::paintGL()
//Bind the vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), 0);
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal<uint8_t>), (GLvoid*)12);
glVertexPointer(3, GL_FLOAT, sizeof(MarchingCubesVertex<uint8_t>), 0);
glNormalPointer(GL_FLOAT, sizeof(MarchingCubesVertex<uint8_t>), (GLvoid*)12);
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndexLow, m_uEndIndexLow-1, m_uEndIndexLow - m_uBeginIndexLow, GL_UNSIGNED_INT, 0);

View File

@ -41,8 +41,8 @@ public:
void mousePressEvent(QMouseEvent* event);
//Convert a SrfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal <uint8_t> >& surfaceMesh);
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal<uint8_t> >& surfaceMesh);
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex <uint8_t> >& surfaceMesh);
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::MarchingCubesVertex<uint8_t> >& surfaceMesh);
protected:
//Qt OpenGL functions

View File

@ -90,13 +90,13 @@ int main(int argc, char *argv[])
volumeResampler.execute();
//Extract the surface
SurfaceMesh<PositionMaterialNormal<uint8_t> > meshLowLOD;
SurfaceMesh<MarchingCubesVertex<uint8_t> > meshLowLOD;
MarchingCubesSurfaceExtractor< RawVolume<uint8_t> > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
surfaceExtractor.execute();
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
//Extract the surface
SurfaceMesh<PositionMaterialNormal<uint8_t> > meshHighLOD;
SurfaceMesh<MarchingCubesVertex<uint8_t> > meshHighLOD;
MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
surfaceExtractorHigh.execute();
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));