This commit templatizes the vertex classes on voxel types. This was the main change which was made for Cubiquity and it's very messy at the moment. However, this will improve when we make more use of 'auto' to hide the template madness.

This commit is contained in:
David Williams
2014-05-07 23:47:18 +02:00
parent 4c2aea3db1
commit b0a8ca8a64
29 changed files with 898 additions and 882 deletions

View File

@ -106,7 +106,7 @@ uint32_t testForType(void)
{
for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength)
{
SurfaceMesh<PositionMaterialNormal> result;
SurfaceMesh<PositionMaterialNormal<VoxelType> > result;
Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1);
CubicSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, regionToExtract, &result);
extractor.execute();

View File

@ -102,7 +102,7 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel)
// Runs the surface extractor for a given type.
template <typename VoxelType>
void testForType(SurfaceMesh<PositionMaterialNormal>& result)
void testForType(SurfaceMesh<PositionMaterialNormal<VoxelType> >& result)
{
const int32_t uVolumeSideLength = 32;
@ -131,7 +131,7 @@ void testForType(SurfaceMesh<PositionMaterialNormal>& result)
extractor.execute();
}
void testCustomController(SurfaceMesh<PositionMaterialNormal>& result)
void testCustomController(SurfaceMesh<PositionMaterialNormal<float> >& result)
{
const int32_t uVolumeSideLength = 32;
@ -163,66 +163,74 @@ void TestSurfaceExtractor::testExecute()
const static float fExpectedMaterial = 42.0f;
const static float fNoMaterial = 1.0f;
SurfaceMesh<PositionMaterialNormal> mesh;
SurfaceMesh<PositionMaterialNormal<int8_t> > int8Mesh;
//Run the test for various voxel types.
QBENCHMARK {
testForType<int8_t>(mesh);
testForType<int8_t>(int8Mesh);
}
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
QCOMPARE(int8Mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(int8Mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(int8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int8_t>(fNoMaterial));
testForType<uint8_t>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<uint8_t> > uint8Mesh;
testForType<uint8_t>(uint8Mesh);
QCOMPARE(uint8Mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(uint8Mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(uint8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
testForType<int16_t>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<int16_t> > int16Mesh;
testForType<int16_t>(int16Mesh);
QCOMPARE(int16Mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(int16Mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(int16Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int16_t>(fNoMaterial));
testForType<uint16_t>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<uint16_t> > uint16Mesh;
testForType<uint16_t>(uint16Mesh);
QCOMPARE(uint16Mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(uint16Mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(uint16Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint16_t>(fNoMaterial));
testForType<int32_t>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<int32_t> > int32Mesh;
testForType<int32_t>(int32Mesh);
QCOMPARE(int32Mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(int32Mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(int32Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int32_t>(fNoMaterial));
testForType<uint32_t>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<uint32_t> > uint32Mesh;
testForType<uint32_t>(uint32Mesh);
QCOMPARE(uint32Mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(uint32Mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(uint32Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint32_t>(fNoMaterial));
testForType<float>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<float> > floatMesh;
testForType<float>(floatMesh);
QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
testForType<double>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<double> > doubleMesh;
testForType<double>(doubleMesh);
QCOMPARE(doubleMesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(doubleMesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(doubleMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<double>(fNoMaterial));
testForType<Density8>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
SurfaceMesh<PositionMaterialNormal<Density8> > densityMesh;
testForType<Density8>(densityMesh);
QCOMPARE(densityMesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(densityMesh.getNoOfIndices(), uExpectedIndices);
//QCOMPARE(densityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
testForType<MaterialDensityPair88>(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fExpectedMaterial);
SurfaceMesh<PositionMaterialNormal<MaterialDensityPair88> > materialDensityMesh;
testForType<MaterialDensityPair88>(materialDensityMesh);
QCOMPARE(materialDensityMesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(materialDensityMesh.getNoOfIndices(), uExpectedIndices);
//QCOMPARE(materialDensityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
//Test whether the CustomSurfaceExtractor works.
testCustomController(mesh);
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
testCustomController(floatMesh);
QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices);
QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices);
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
}
QTEST_MAIN(TestSurfaceExtractor)

View File

@ -184,7 +184,7 @@ void TestVolumeSubclass::testExtractSurface()
}
}
SurfaceMesh<PositionMaterialNormal> result;
SurfaceMesh<PositionMaterialNormal<Material8> > result;
CubicSurfaceExtractor< VolumeSubclass<Material8> > cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result);
cubicSurfaceExtractor.execute();