Just tidying up the MeshDecimator stuff a bit...

This commit is contained in:
David Williams
2011-01-05 22:05:53 +00:00
parent d0e4b06051
commit a7828995d9
4 changed files with 106 additions and 74 deletions

View File

@ -32,6 +32,7 @@ freely, subject to the following restrictions:
#include "MeshDecimator.h"
#include <QApplication>
#include <QTime>
//Use the PolyVox namespace
using namespace PolyVox;
@ -41,7 +42,7 @@ void createSphereInVolume(Volume<MaterialDensityPair44>& volData, float fRadius)
//This vector hold the position of the center of the volume
//Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
Vector3DFloat v3dVolCenter(16, 16, 16);
Vector3DFloat v3dVolCenter(16, 16, 1);
//This three-level for loop iterates over every voxel in the volume
for (int z = 0; z < volData.getWidth(); z++)
@ -155,25 +156,35 @@ int main(int argc, char *argv[])
}
}*/
createSphereInVolume(volData, 10);
createSphereInVolume(volData, 24);
//Extract the surface
Region region(Vector3DInt16(0,0,0), Vector3DInt16(20,20,20));
Region region(Vector3DInt16(-1,-1,-1), Vector3DInt16(32,32,32));
SurfaceMesh<PositionMaterial> mesh;
//CubicSurfaceExtractor<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
QTime t;
t.start();
CubicSurfaceExtractor<MaterialDensityPair44> surfaceExtractor(&volData, region, &mesh);
surfaceExtractor.execute();
cout << "E: " << t.elapsed();
t.restart();
/*SurfaceMesh<PositionMaterialNormal> meshWithNormals;
addNormals(mesh, meshWithNormals);
meshWithNormals.decimate(0.99);*/
MeshDecimator<PositionMaterial> decimator(&mesh);
SurfaceMesh<PositionMaterial> decimatedMesh;
MeshDecimator<PositionMaterial> decimator(&mesh, &decimatedMesh);
decimator.execute();
cout << "D: " << t.elapsed();
SurfaceMesh<PositionMaterialNormal> meshWithNormals;
addNormals(mesh, meshWithNormals);
addNormals(decimatedMesh, meshWithNormals);
//Pass the surface to the OpenGL window
openGLWidget.setSurfaceMeshToRender(meshWithNormals);

View File

@ -126,7 +126,8 @@ void OpenGLWidget::setVolume(PolyVox::Volume<MaterialDensityPair44>* volData)
//mesh->decimate(0.999f);
MeshDecimator<PositionMaterialNormal> decimator(mesh.get());
polyvox_shared_ptr< SurfaceMesh<PositionMaterialNormal> > decimatedMesh(new SurfaceMesh<PositionMaterialNormal>);
MeshDecimator<PositionMaterialNormal> decimator(mesh.get(), decimatedMesh.get());
decimator.execute();
//mesh->generateAveragedFaceNormals(true);
@ -143,12 +144,12 @@ void OpenGLWidget::setVolume(PolyVox::Volume<MaterialDensityPair44>* volData)
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_bUseOpenGLVertexBufferObjects)
{
OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get()));
OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(decimatedMesh.get()));
m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh));
}
//else
//{
m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh));
m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, decimatedMesh));
//}
//delete meshCurrent;
}
@ -216,8 +217,8 @@ void OpenGLWidget::paintGL()
//Moves the camera back so we can see the volume
glTranslatef(0.0f, 0.0f, -m_volData->getDiagonalLength());
glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f);
glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f);
glRotatef(10, 1.0f, 0.0f, 0.0f);
glRotatef(20, 0.0f, 1.0f, 0.0f);
//Centre the volume on the origin
glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-g_uVolumeSideLength/2);