Updated the CubicSurfaceExtractor test to make it a bit more performance intensive, Cubiquity is showing a need for some improvements here. Also added a performance improvement to the CubicsurfaceExtractor.

This commit is contained in:
Daviw Williams 2013-02-08 15:05:45 +01:00
parent c5023ff623
commit 7e08ed7aec
2 changed files with 42 additions and 16 deletions

View File

@ -79,12 +79,12 @@ namespace PolyVox
{ {
uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY();
volumeSampler.setPosition(m_regSizeInVoxels.getLowerCorner().getX(),y,z);
for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX(); x++) for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX(); x++)
{ {
uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX();
volumeSampler.setPosition(x,y,z);
uint32_t material; //Filled in by callback uint32_t material; //Filled in by callback
typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel(); typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel();
typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz(); typename VolumeType::VoxelType negXVoxel = volumeSampler.peekVoxel1nx0py0pz();
@ -153,6 +153,8 @@ namespace PolyVox
m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1)); m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1));
} }
volumeSampler.movePositiveX();
} }
} }

View File

@ -27,7 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Material.h" #include "PolyVoxCore/Material.h"
#include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/SimpleVolume.h" #include "PolyVoxCore/SimpleVolume.h"
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVoxCore/CubicSurfaceExtractor.h"
#include <QtTest> #include <QtTest>
@ -70,13 +70,14 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel)
// Runs the surface extractor for a given type. // Runs the surface extractor for a given type.
template <typename VoxelType> template <typename VoxelType>
void testForType(SurfaceMesh<PositionMaterialNormal>& result) uint32_t testForType(void)
{ {
const int32_t uVolumeSideLength = 32; const int32_t uVolumeSideLength = 256;
//Create empty volume //Create empty volume
SimpleVolume<VoxelType> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1))); SimpleVolume<VoxelType> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1)), 128);
//Fill the volume with data
for (int32_t z = 0; z < uVolumeSideLength; z++) for (int32_t z = 0; z < uVolumeSideLength; z++)
{ {
for (int32_t y = 0; y < uVolumeSideLength; y++) for (int32_t y = 0; y < uVolumeSideLength; y++)
@ -94,20 +95,43 @@ void testForType(SurfaceMesh<PositionMaterialNormal>& result)
} }
} }
CubicSurfaceExtractorWithNormals< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result); uint32_t uTotalVertices = 0;
uint32_t uTotalIndices = 0;
//Run the surface extractor a number of times over differnt regions of the volume.
const int32_t uRegionSideLength = 64;
for (int32_t z = 0; z < uVolumeSideLength; z += uRegionSideLength)
{
for (int32_t y = 0; y < uVolumeSideLength; y += uRegionSideLength)
{
for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength)
{
SurfaceMesh<PositionMaterial> result;
Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1);
CubicSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, regionToExtract, &result);
extractor.execute(); extractor.execute();
uTotalVertices += result.getNoOfVertices();
uTotalIndices += result.getNoOfIndices();
}
}
}
// Just some value which is representative of the work we've done. It doesn't
// matter what it is, just that it should be the same every time we run the test.
return uTotalVertices + uTotalIndices;
} }
void TestCubicSurfaceExtractor::testExecute() void TestCubicSurfaceExtractor::testExecute()
{ {
const static uint32_t uExpectedVertices = 6624; /*const static uint32_t uExpectedVertices = 6624;
const static uint32_t uExpectedIndices = 9936; const static uint32_t uExpectedIndices = 9936;
const static uint32_t uMaterialToCheck = 3000; const static uint32_t uMaterialToCheck = 3000;
const static float fExpectedMaterial = 42.0f; const static float fExpectedMaterial = 42.0f;
const static uint32_t uIndexToCheck = 2000; const static uint32_t uIndexToCheck = 2000;
const static uint32_t uExpectedIndex = 1334; const static uint32_t uExpectedIndex = 1334;
SurfaceMesh<PositionMaterialNormal> mesh; SurfaceMesh<PositionMaterialNormal> mesh;*/
/*testForType<int8_t>(mesh); /*testForType<int8_t>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
@ -154,13 +178,13 @@ void TestCubicSurfaceExtractor::testExecute()
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);*/ QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);*/
const static uint32_t uExpectedSumOfVerticesAndIndices = 704668;
//const static uint32_t uExpectedSumOfVerticesAndIndices = 2792332;
uint32_t result = 0;
QBENCHMARK { QBENCHMARK {
testForType<MaterialDensityPair88>(mesh); result = testForType<MaterialDensityPair88>();
} }
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(result, uExpectedSumOfVerticesAndIndices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fExpectedMaterial);
QCOMPARE(mesh.getIndices()[uIndexToCheck], uExpectedIndex);
} }
QTEST_MAIN(TestCubicSurfaceExtractor) QTEST_MAIN(TestCubicSurfaceExtractor)