diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 51f2e485..c482abdf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -318,6 +318,8 @@ namespace PolyVox typename Controller::DensityType m_tThreshold; }; + // We don't provide a default MeshType here. If the user doesn't want to provide a MeshType then it probably makes + // more sense to use the other variaent of this function where the mesh is a return value rather than a parameter. template< typename VolumeType, typename MeshType, typename Controller = DefaultMarchingCubesController > void extractMarchingCubesMesh(VolumeType* volData, Region region, MeshType* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller()) { diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 081f6cfc..4a4e95bc 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -100,14 +100,13 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) voxel.setMaterial(valueToWrite); } -// Runs the surface extractor for a given type. template -Mesh > testForType(void) //I think we could avoid specifying this return type by using auto/decltype? +SimpleVolume* createAndFillVolume(void) { const int32_t uVolumeSideLength = 32; //Create empty volume - SimpleVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1))); + SimpleVolume* volData = new SimpleVolume(Region(Vector3DInt32(0, 0, 0), Vector3DInt32(uVolumeSideLength - 1, uVolumeSideLength - 1, uVolumeSideLength - 1))); for (int32_t z = 0; z < uVolumeSideLength; z++) { @@ -120,15 +119,25 @@ Mesh > testForType(void) //I think we could avoid writeDensityValueToVoxel(x + y + z, voxelValue); //Two different materials in two halves of the volume writeMaterialValueToVoxel(z > uVolumeSideLength / 2 ? 42 : 79, voxelValue); - volData.setVoxelAt(x, y, z, voxelValue); + volData->setVoxelAt(x, y, z, voxelValue); } } } + return volData; +} + +// Runs the surface extractor for a given type. +template +Mesh > testForType(void) //I think we could avoid specifying this return type by using auto/decltype? +{ + //Create empty volume + SimpleVolume* volData = createAndFillVolume(); + DefaultMarchingCubesController controller; controller.setThreshold(50); - auto result = extractMarchingCubesMesh(&volData, volData.getEnclosingRegion(), WrapModes::Border, VoxelType(), controller); + auto result = extractMarchingCubesMesh(volData, volData->getEnclosingRegion(), WrapModes::Border, VoxelType(), controller); return result; } @@ -223,6 +232,13 @@ void TestSurfaceExtractor::testExecute() QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].data, fExpectedData);*/ + + auto uintVol = createAndFillVolume(); + auto uintMesh = extractMarchingCubesMesh(uintVol, uintVol->getEnclosingRegion()); + QCOMPARE(uintMesh.getNoOfVertices(), uExpectedVertices); + QCOMPARE(uintMesh.getNoOfIndices(), uExpectedIndices); + //QCOMPARE(uintMesh.getVertices()[uMaterialToCheck].data, static_cast(fExpectedData)); + std::cout << uintMesh.getVertices()[uMaterialToCheck].data << std::endl; } QTEST_MAIN(TestSurfaceExtractor)