More work on surface extraction tests.

This commit is contained in:
David Williams 2014-08-12 15:53:30 +02:00
parent e2f43ebc5d
commit ccc9a3c158
3 changed files with 18 additions and 17 deletions

View File

@ -90,8 +90,8 @@ namespace PolyVox
// floats into two bytes and store them in a single uint16_t
// Move from range [-1.0f, 1.0f] to [0.0f, 255.0f]
px = (px + 1.0) * 127.5f;
py = (py + 1.0) * 127.5f;
px = (px + 1.0f) * 127.5f;
py = (py + 1.0f) * 127.5f;
// Convert to uints
uint16_t resultX = static_cast<uint16_t>(px + 0.5f);
@ -300,7 +300,7 @@ namespace PolyVox
uint32_t m_uNoOfOccupiedCells;
//The surface patch we are currently filling.
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> >* m_meshCurrent;
MeshType* m_meshCurrent;
//Information about the region we are currently processing
Region m_regSizeInVoxels;
@ -327,10 +327,10 @@ namespace PolyVox
extractor.execute();
}
template< typename VolumeType, typename Controller = DefaultMarchingCubesController<typename VolumeType::VoxelType>, typename IndexType = DefaultIndexType >
template< typename VolumeType, typename Controller = DefaultMarchingCubesController<typename VolumeType::VoxelType> >
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesMesh(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller())
{
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType>, IndexType > result;
Mesh<MarchingCubesVertex<typename VolumeType::VoxelType>, DefaultIndexType > result;
extractMarchingCubesMesh(volData, region, eWrapMode, tBorderValue, controller, &result);
return result;
}

View File

@ -81,13 +81,13 @@ namespace PolyVox
{
Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decodedMesh;
for (auto ct = 0; ct < encodedMesh.getNoOfVertices(); ct++)
for (MeshType::IndexType ct = 0; ct < encodedMesh.getNoOfVertices(); ct++)
{
decodedMesh.addVertex(decodeVertex(encodedMesh.getVertex(ct)));
}
POLYVOX_ASSERT(encodedMesh.getNoOfIndices() % 3 == 0, "The number of indices must always be a multiple of three.");
for (auto ct = 0; ct < encodedMesh.getNoOfIndices(); ct += 3)
for (uint32_t ct = 0; ct < encodedMesh.getNoOfIndices(); ct += 3)
{
decodedMesh.addTriangle(encodedMesh.getIndex(ct), encodedMesh.getIndex(ct + 1), encodedMesh.getIndex(ct + 2));
}

View File

@ -251,22 +251,23 @@ void TestSurfaceExtractor::testExecute()
auto uintVol = createAndFillVolume<uint8_t>();
auto uintMesh = extractMarchingCubesMesh(uintVol, uintVol->getEnclosingRegion());
QCOMPARE(uintMesh.getNoOfVertices(), 12096u); // Verifies size of mesh
QCOMPARE(uintMesh.getNoOfIndices(), 35157u); // Verifies size of mesh
QCOMPARE(uintMesh.getIndex(100), uint32_t(44)); // Verifies that we have 32-bit index buffer
QCOMPARE(uintMesh.getNoOfVertices(), uint32_t(12096)); // Verifies size of mesh and that we have 32-bit indices
QCOMPARE(uintMesh.getNoOfIndices(), uint32_t(35157)); // Verifies size of mesh
QCOMPARE(uintMesh.getIndex(100), uint32_t(44)); // Verifies that we have 32-bit indices
auto floatVol = createAndFillVolume<float>();
CustomMarchingCubesController floatCustomController;
auto floatMesh = extractMarchingCubesMesh(floatVol, floatVol->getEnclosingRegion(), WrapModes::Border, float(0), floatCustomController);
QCOMPARE(floatMesh.getNoOfVertices(), 16113u); // Verifies size of mesh
QCOMPARE(floatMesh.getNoOfIndices(), 22053u); // Verifies size of mesh
QCOMPARE(floatMesh.getIndex(100), uint32_t(26)); // Verifies that we have 32-bit index buffer
QCOMPARE(floatMesh.getNoOfVertices(), uint32_t(16113)); // Verifies size of mesh and that we have 32-bit indices
QCOMPARE(floatMesh.getNoOfIndices(), uint32_t(22053)); // Verifies size of mesh
QCOMPARE(floatMesh.getIndex(100), uint32_t(26)); // Verifies that we have 32-bit indices
auto intVol = createAndFillVolume<int8_t>();
auto intMesh = extractMarchingCubesMesh(intVol, intVol->getEnclosingRegion(), WrapModes::Border, int8_t(0), DefaultMarchingCubesController<int8_t>());
QCOMPARE(intMesh.getNoOfVertices(), 11718u); // Verifies size of mesh
QCOMPARE(intMesh.getNoOfIndices(), 34041u); // Verifies size of mesh
QCOMPARE(intMesh.getIndex(100), uint32_t(29)); // Verifies that we have 32-bit index buffer
Mesh< MarchingCubesVertex< int8_t >, uint16_t > intMesh;
extractMarchingCubesMesh(intVol, intVol->getEnclosingRegion(), WrapModes::Border, int8_t(0), DefaultMarchingCubesController<int8_t>(), &intMesh);
QCOMPARE(intMesh.getNoOfVertices(), uint16_t(11718)); // Verifies size of mesh and that we have 16-bit indices
QCOMPARE(intMesh.getNoOfIndices(), uint32_t(34041)); // Verifies size of mesh
QCOMPARE(intMesh.getIndex(100), uint16_t(29)); // Verifies that we have 16-bit indices
}
QTEST_MAIN(TestSurfaceExtractor)