From db13224bbaaca064930ad9cbe55940e9f6e81f4a Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 6 Jan 2011 21:54:07 +0000 Subject: [PATCH] Reverted some accidental commits from testing the MeshDecimator. --- examples/Basic/OpenGLWidget.cpp | 15 ++-- examples/Basic/main.cpp | 115 ++----------------------------- examples/OpenGL/OpenGLWidget.cpp | 15 ++-- 3 files changed, 17 insertions(+), 128 deletions(-) diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index a1d5f9c9..9732bd1b 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -52,19 +52,14 @@ void OpenGLWidget::initializeGL() glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); - //Enable smooth lighting - //glEnable(GL_LIGHTING); - //glEnable(GL_LIGHT0); + //Anable smooth lighting + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); glShadeModel(GL_SMOOTH); //We'll be rendering with index/vertex arrays glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); } void OpenGLWidget::resizeGL(int w, int h) @@ -75,7 +70,7 @@ void OpenGLWidget::resizeGL(int w, int h) //Set up the projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); - float frustumSize = 16.0f; //Half the volume size + float frustumSize = 32.0f; //Half the volume size float aspect = static_cast(width()) / static_cast(height()); glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 1.0, 1000); } @@ -91,7 +86,7 @@ void OpenGLWidget::paintGL() glTranslatef(0.0f,0.0f,-100.0f); //Centre volume and move back glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f); glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f); - glTranslatef(-16.0f,-16.0f,-16.0f); //Centre volume and move back + glTranslatef(-32.0f,-32.0f,-32.0f); //Centre volume and move back //Bind the index buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index a7d04005..51dd24e4 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -24,15 +24,11 @@ freely, subject to the following restrictions: #include "OpenGLWidget.h" #include "MaterialDensityPair.h" -#include "CubicSurfaceExtractor.h" #include "CubicSurfaceExtractorWithNormals.h" #include "SurfaceMesh.h" #include "Volume.h" -#include "MeshDecimator.h" - #include -#include //Use the PolyVox namespace using namespace PolyVox; @@ -40,9 +36,7 @@ using namespace PolyVox; void createSphereInVolume(Volume& 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, 1); + Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); //This three-level for loop iterates over every voxel in the volume for (int z = 0; z < volData.getWidth(); z++) @@ -61,16 +55,14 @@ void createSphereInVolume(Volume& volData, float fRadius) { //Our new density value uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); - uint8_t uMaterial = 3; //Get the old voxel MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); //Modify the density voxel.setDensity(uDensity); - voxel.setMaterial(uMaterial); - //Write the voxel value into the volume + //Wrte the voxel value into the volume volData.setVoxelAt(x, y, z, voxel); } } @@ -78,28 +70,6 @@ void createSphereInVolume(Volume& volData, float fRadius) } } -void addNormals(const PolyVox::SurfaceMesh& inputMesh, PolyVox::SurfaceMesh& outputMesh) -{ - outputMesh.m_Region = inputMesh.m_Region; - - outputMesh.m_vecTriangleIndices.clear(); - for(int ct = 0; ct < inputMesh.m_vecTriangleIndices.size(); ++ct) - { - outputMesh.m_vecTriangleIndices.push_back(inputMesh.m_vecTriangleIndices[ct]); - } - - outputMesh.m_vecVertices.clear(); - for(int ct = 0; ct < inputMesh.m_vecVertices.size(); ++ct) - { - PositionMaterialNormal vertex; - vertex.position = inputMesh.m_vecVertices[ct].position; - vertex.material = inputMesh.m_vecVertices[ct].material; - outputMesh.m_vecVertices.push_back(vertex); - } - - outputMesh.generateAveragedFaceNormals(true, true); -} - int main(int argc, char *argv[]) { //Create and show the Qt OpenGL window @@ -108,87 +78,16 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - Volume volData(32, 32, 32, 32); - //createSphereInVolume(volData, 30); - - //This three-level for loop iterates over every voxel in the volume - /*for (int z = 8; z < 24; z++) - { - for (int y = 8; y < 24; y++) - { - for (int x = 8; x < 16; x++) - { - //Our new density value - uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); - - //Get the old voxel - MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); - - //Modify the density - voxel.setDensity(uDensity); - voxel.setMaterial(3); - - //Write the voxel value into the volume - volData.setVoxelAt(x, y, z, voxel); - } - } - } - - for (int z = 8; z < 24; z++) - { - for (int y = 8; y < 24; y++) - { - for (int x = 16; x < 24; x++) - { - //Our new density value - uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); - - //Get the old voxel - MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); - - //Modify the density - voxel.setDensity(uDensity); - voxel.setMaterial(5); - - //Write the voxel value into the volume - volData.setVoxelAt(x, y, z, voxel); - } - } - }*/ - - createSphereInVolume(volData, 24); + Volume volData(64, 64, 64); + createSphereInVolume(volData, 30); //Extract the surface - PolyVox::Region region(Vector3DInt16(-1,-1,-1), Vector3DInt16(32,32,32)); - SurfaceMesh mesh; - //CubicSurfaceExtractor surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); - - QTime t; - t.start(); - - CubicSurfaceExtractor surfaceExtractor(&volData, region, &mesh); + SurfaceMesh mesh; + CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); surfaceExtractor.execute(); - cout << "E: " << t.elapsed(); - t.restart(); - - /*SurfaceMesh meshWithNormals; - addNormals(mesh, meshWithNormals); - - meshWithNormals.decimate(0.99);*/ - - SurfaceMesh decimatedMesh; - MeshDecimator decimator(&mesh, &decimatedMesh); - decimator.execute(); - - cout << "D: " << t.elapsed(); - - SurfaceMesh meshWithNormals; - addNormals(decimatedMesh, meshWithNormals); - //Pass the surface to the OpenGL window - openGLWidget.setSurfaceMeshToRender(meshWithNormals); - //openGLWidget.setSurfaceMeshToRender(mesh); + openGLWidget.setSurfaceMeshToRender(mesh); //Run the message pump. return app.exec(); diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index f37fdaba..82c283c8 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -28,7 +28,6 @@ freely, subject to the following restrictions: #include "GradientEstimators.h" #include "MaterialDensityPair.h" #include "SurfaceExtractor.h" -#include "MeshDecimator.h" #include "Mesh.h" @@ -126,10 +125,6 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) //mesh->decimate(0.999f); - polyvox_shared_ptr< SurfaceMesh > decimatedMesh(new SurfaceMesh); - MeshDecimator decimator(mesh.get(), decimatedMesh.get()); - decimator.execute(); - //mesh->generateAveragedFaceNormals(true); //////////////////////////////////////////////////////////////////////////////// @@ -144,12 +139,12 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); if(m_bUseOpenGLVertexBufferObjects) { - OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(decimatedMesh.get())); + OpenGLSurfaceMesh openGLSurfaceMesh = BuildOpenGLSurfaceMesh(*(mesh.get())); m_mapOpenGLSurfaceMeshes.insert(make_pair(v3dRegPos, openGLSurfaceMesh)); } //else //{ - m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, decimatedMesh)); + m_mapSurfaceMeshes.insert(make_pair(v3dRegPos, mesh)); //} //delete meshCurrent; } @@ -188,7 +183,7 @@ void OpenGLWidget::initializeGL() glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_LIGHT0); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glShadeModel(GL_SMOOTH); } @@ -217,8 +212,8 @@ void OpenGLWidget::paintGL() //Moves the camera back so we can see the volume glTranslatef(0.0f, 0.0f, -m_volData->getDiagonalLength()); - glRotatef(10, 1.0f, 0.0f, 0.0f); - glRotatef(20, 0.0f, 1.0f, 0.0f); + glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f); + glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f); //Centre the volume on the origin glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-g_uVolumeSideLength/2);