Renamed IndexedSurfacePatch to SurfaceMesh.

This commit is contained in:
David Williams
2010-02-20 00:20:43 +00:00
parent 3ed74a982c
commit 2d78808000
20 changed files with 143 additions and 143 deletions

View File

@ -24,18 +24,18 @@ freely, subject to the following restrictions:
#include "OpenGLImmediateModeSupport.h"
#include "OpenGLSupport.h"
#include "IndexedSurfacePatch.h"
#include "SurfaceMesh.h"
using namespace PolyVox;
using namespace std;
void renderRegionImmediateMode(PolyVox::IndexedSurfacePatch& isp, unsigned int uLodLevel)
void renderRegionImmediateMode(PolyVox::SurfaceMesh& mesh, unsigned int uLodLevel)
{
const vector<SurfaceVertex>& vecVertices = isp.getVertices();
const vector<PolyVox::uint32_t>& vecIndices = isp.getIndices();
const vector<SurfaceVertex>& vecVertices = mesh.getVertices();
const vector<PolyVox::uint32_t>& vecIndices = mesh.getIndices();
int beginIndex = isp.m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = isp.m_vecLodRecords[uLodLevel].endIndex;
int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = mesh.m_vecLodRecords[uLodLevel].endIndex;
glBegin(GL_TRIANGLES);
//for(vector<PolyVox::uint32_t>::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex)
@ -44,7 +44,7 @@ void renderRegionImmediateMode(PolyVox::IndexedSurfacePatch& isp, unsigned int u
const SurfaceVertex& 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>(isp.m_Region.getLowerCorner());
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());

View File

@ -28,6 +28,6 @@ freely, subject to the following restrictions:
#include "glew/glew.h"
void renderRegionImmediateMode(PolyVox::IndexedSurfacePatch& isp, unsigned int uLodLevel);
void renderRegionImmediateMode(PolyVox::SurfaceMesh& mesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLImmediateModeSupport_H__

View File

@ -24,22 +24,22 @@ freely, subject to the following restrictions:
#include "OpenGLSupport.h"
#include "OpenGLVertexBufferObjectSupport.h"
#include "IndexedSurfacePatch.h"
#include "SurfaceMesh.h"
using namespace PolyVox;
using namespace std;
OpenGLSurfacePatch BuildOpenGLSurfacePatch(const IndexedSurfacePatch& isp)
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh& mesh)
{
//Represents our filled in OpenGL vertex and index buffer objects.
OpenGLSurfacePatch result;
OpenGLSurfaceMesh result;
//The source
result.sourceISP = &isp;
result.sourceMesh = &mesh;
//Convienient access to the vertices and indices
const vector<SurfaceVertex>& vecVertices = isp.getVertices();
const vector<PolyVox::uint32_t>& vecIndices = isp.getIndices();
const vector<SurfaceVertex>& vecVertices = mesh.getVertices();
const vector<PolyVox::uint32_t>& vecIndices = mesh.getIndices();
//If we have any indices...
if(!vecIndices.empty())
@ -67,7 +67,7 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(const IndexedSurfacePatch& isp)
const SurfaceVertex& 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>(isp.m_Region.getLowerCorner());
const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
*ptr = v3dFinalVertexPos.getX();
ptr++;
@ -100,23 +100,23 @@ OpenGLSurfacePatch BuildOpenGLSurfacePatch(const IndexedSurfacePatch& isp)
return result;
}
void renderRegionVertexBufferObject(const OpenGLSurfacePatch& openGLSurfacePatch, unsigned int uLodLevel)
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel)
{
int beginIndex = openGLSurfacePatch.sourceISP->m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = openGLSurfacePatch.sourceISP->m_vecLodRecords[uLodLevel].endIndex;
glBindBuffer(GL_ARRAY_BUFFER, openGLSurfacePatch.vertexBuffer);
int beginIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].beginIndex;
int endIndex = openGLSurfaceMesh.sourceMesh->m_vecLodRecords[uLodLevel].endIndex;
glBindBuffer(GL_ARRAY_BUFFER, openGLSurfaceMesh.vertexBuffer);
glVertexPointer(3, GL_FLOAT, 36, 0);
glNormalPointer(GL_FLOAT, 36, (GLvoid*)12);
glColorPointer(3, GL_FLOAT, 36, (GLvoid*)24);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLSurfacePatch.indexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, openGLSurfaceMesh.indexBuffer);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//glDrawElements(GL_TRIANGLES, openGLSurfacePatch.noOfIndices, GL_UNSIGNED_INT, 0);
glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLSurfacePatch.noOfIndices,*/ GL_UNSIGNED_INT, 0);
//glDrawElements(GL_TRIANGLES, openGLSurfaceMesh.noOfIndices, GL_UNSIGNED_INT, 0);
glDrawRangeElements(GL_TRIANGLES, beginIndex, endIndex-1, endIndex - beginIndex,/* openGLSurfaceMesh.noOfIndices,*/ GL_UNSIGNED_INT, 0);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

View File

@ -28,15 +28,15 @@ freely, subject to the following restrictions:
#include "glew/glew.h"
struct OpenGLSurfacePatch
struct OpenGLSurfaceMesh
{
GLulong noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
const PolyVox::IndexedSurfacePatch* sourceISP;
const PolyVox::SurfaceMesh* sourceMesh;
};
OpenGLSurfacePatch BuildOpenGLSurfacePatch(const PolyVox::IndexedSurfacePatch& isp);
void renderRegionVertexBufferObject(const OpenGLSurfacePatch& openGLSurfacePatch, unsigned int uLodLevel);
OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh& mesh);
void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel);
#endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__

View File

@ -51,8 +51,8 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData)
{
//First we free anything from the previous volume (if there was one).
m_mapOpenGLSurfacePatches.clear();
m_mapIndexedSurfacePatches.clear();
m_mapOpenGLSurfaceMeshes.clear();
m_mapSurfaceMeshes.clear();
m_volData = volData;
//If we have any volume data then generate the new surface patches.
@ -89,63 +89,63 @@ void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData)
Vector3DInt16 regUpperCorner(regionEndX, regionEndY, regionEndZ);
//Extract the surface for this region
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent);
POLYVOX_SHARED_PTR<IndexedSurfacePatch> isp = surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner));
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent);
POLYVOX_SHARED_PTR<SurfaceMesh> mesh = surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner));
//computeNormalsForVertices(m_volData, *(isp.get()), SOBEL_SMOOTHED);
//*ispCurrent = getSmoothedSurface(*ispCurrent);
//isp->smooth(0.3f);
//ispCurrent->generateAveragedFaceNormals(true);
//computeNormalsForVertices(m_volData, *(mesh.get()), SOBEL_SMOOTHED);
//*meshCurrent = getSmoothedSurface(*meshCurrent);
//mesh->smooth(0.3f);
//meshCurrent->generateAveragedFaceNormals(true);
if(isp->m_vecTriangleIndices.size() > 0)
if(mesh->m_vecTriangleIndices.size() > 0)
{
//isp->makeProgressiveMesh();
//mesh->makeProgressiveMesh();
/*RenderDynamicMesh rdm;
rdm.buildFromIndexedSurfacePatch(*isp);*/
rdm.buildFromSurfaceMesh(*mesh);*/
//computeNormalsForVertices(m_volData, *(isp.get()), SOBEL_SMOOTHED);
//computeNormalsForVertices(m_volData, *(mesh.get()), SOBEL_SMOOTHED);
//isp->smoothPositions(0.3f);
//isp->generateAveragedFaceNormals(true);
//mesh->smoothPositions(0.3f);
//mesh->generateAveragedFaceNormals(true);
/*for(int ct = 0; ct < 20; ct ++)
{
//cout << "Before: " << isp->noOfDegenerateTris() << endl;
isp->decimate();
//cout << "After: " << isp->noOfDegenerateTris() << endl;
isp->removeDegenerateTris();
//cout << "After Remove: " << isp->noOfDegenerateTris() << endl << endl;
//cout << "Before: " << mesh->noOfDegenerateTris() << endl;
mesh->decimate();
//cout << "After: " << mesh->noOfDegenerateTris() << endl;
mesh->removeDegenerateTris();
//cout << "After Remove: " << mesh->noOfDegenerateTris() << endl << endl;
}*/
////////////////////////////////////////////////////////////////////////////////
//For decimation built into ISP
//isp->generateAveragedFaceNormals(true);
//For decimation built into Mesh
//mesh->generateAveragedFaceNormals(true);
isp->decimate(0.999f);
mesh->decimate(0.999f);
//isp->generateAveragedFaceNormals(true);
//mesh->generateAveragedFaceNormals(true);
////////////////////////////////////////////////////////////////////////////////
/*isp->generateAveragedFaceNormals(true);
/*mesh->generateAveragedFaceNormals(true);
Mesh mesh;
mesh.buildFromISP(isp.get());
mesh.buildFromMesh(mesh.get());
//mesh.removeEdge(*(mesh.m_edges.begin()));
mesh.decimateAll();
mesh.fillISP(isp.get());*/
mesh.fillMesh(mesh.get());*/
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_bUseOpenGLVertexBufferObjects)
{
OpenGLSurfacePatch openGLSurfacePatch = BuildOpenGLSurfacePatch(*(isp.get()));
m_mapOpenGLSurfacePatches.insert(make_pair(v3dRegPos, openGLSurfacePatch));
OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get()));
m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh));
}
//else
//{
m_mapIndexedSurfacePatches.insert(make_pair(v3dRegPos, isp));
m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh));
//}
//delete ispCurrent;
//delete meshCurrent;
}
}
}
@ -226,17 +226,17 @@ void OpenGLWidget::paintGL()
for(PolyVox::uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX)
{
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_mapIndexedSurfacePatches.find(v3dRegPos) != m_mapIndexedSurfacePatches.end())
if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end())
{
POLYVOX_SHARED_PTR<IndexedSurfacePatch> ispCurrent = m_mapIndexedSurfacePatches[v3dRegPos];
unsigned int uLodLevel = 0; //ispCurrent->m_vecLodRecords.size() - 1;
POLYVOX_SHARED_PTR<SurfaceMesh> meshCurrent = m_mapSurfaceMeshes[v3dRegPos];
unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1;
if(m_bUseOpenGLVertexBufferObjects)
{
renderRegionVertexBufferObject(m_mapOpenGLSurfacePatches[v3dRegPos], uLodLevel);
renderRegionVertexBufferObject(m_mapOpenGLSurfaceMeshes[v3dRegPos], uLodLevel);
}
else
{
renderRegionImmediateMode(*ispCurrent, uLodLevel);
renderRegionImmediateMode(*meshCurrent, uLodLevel);
}
}
}

View File

@ -30,7 +30,7 @@ freely, subject to the following restrictions:
#include <QTimer>
#include "Volume.h"
#include "IndexedSurfacePatch.h"
#include "SurfaceMesh.h"
#include "PolyVoxImpl/Utility.h"
#include "OpenGLImmediateModeSupport.h"
@ -72,8 +72,8 @@ class OpenGLWidget : public QGLWidget
PolyVox::Volume<PolyVox::uint8_t>* m_volData;
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
std::map<PolyVox::Vector3DUint8, OpenGLSurfacePatch> m_mapOpenGLSurfacePatches;
std::map<PolyVox::Vector3DUint8, POLYVOX_SHARED_PTR<PolyVox::IndexedSurfacePatch> > m_mapIndexedSurfacePatches;
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh> m_mapOpenGLSurfaceMeshes;
std::map<PolyVox::Vector3DUint8, POLYVOX_SHARED_PTR<PolyVox::SurfaceMesh> > m_mapSurfaceMeshes;
unsigned int m_uRegionSideLength;
unsigned int m_uVolumeWidthInRegions;

View File

@ -23,7 +23,7 @@ freely, subject to the following restrictions:
#include "Log.h"
#include "Volume.h"
#include "IndexedSurfacePatch.h"
#include "SurfaceMesh.h"
#include "PolyVoxImpl/Utility.h"
#include "OpenGLImmediateModeSupport.h"