Merge branch 'develop' into feature/vertex-refactor
Conflicts: examples/Basic/main.cpp examples/Paging/main.cpp examples/SmoothLOD/main.cpp library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h tests/TestCubicSurfaceExtractor.cpp tests/TestSurfaceExtractor.cpp tests/TestVolumeSubclass.cpp
This commit is contained in:
commit
f2ba500c4c
@ -75,17 +75,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
//Create an empty volume and then place a sphere in it
|
||||
SimpleVolume<uint8_t> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
|
||||
createSphereInVolume(volData, 30);
|
||||
|
||||
//A mesh object to hold the result of surface extraction
|
||||
SurfaceMesh<CubicVertex<uint8_t> > mesh;
|
||||
|
||||
//Create a surface extractor. Comment out one of the following two lines to decide which type gets created.
|
||||
CubicSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
//MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
|
||||
//Execute the surface extractor.
|
||||
surfaceExtractor.execute();
|
||||
createSphereInVolume(volData, 30);
|
||||
|
||||
// Extract the surface for the specified region of the volume. Uncomment the line for the kind of surface extraction you want to see.
|
||||
auto mesh = extractCubicSurface(&volData, volData.getEnclosingRegion());
|
||||
//auto mesh = extractMarchingCubesSurface(&volData, volData.getEnclosingRegion());
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
||||
|
@ -185,12 +185,8 @@ int main(int argc, char *argv[])
|
||||
std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl;
|
||||
std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl;
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<CubicVertex<MaterialDensityPair44> > mesh;
|
||||
CubicSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
|
||||
//MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
|
||||
//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
|
||||
surfaceExtractor.execute();
|
||||
//Extract the surface
|
||||
auto mesh = extractCubicSurface(&volData, reg);
|
||||
std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
|
@ -89,16 +89,12 @@ int main(int argc, char *argv[])
|
||||
VolumeResampler< SimpleVolume<uint8_t>, RawVolume<uint8_t> > volumeResampler(&volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 63, 63)), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||
volumeResampler.execute();
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<MarchingCubesVertex<uint8_t> > meshLowLOD;
|
||||
MarchingCubesSurfaceExtractor< RawVolume<uint8_t> > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
|
||||
surfaceExtractor.execute();
|
||||
//Extract the surface
|
||||
auto meshLowLOD = extractMarchingCubesSurface(&volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||
meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f);
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<MarchingCubesVertex<uint8_t> > meshHighLOD;
|
||||
MarchingCubesSurfaceExtractor< SimpleVolume<uint8_t> > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
|
||||
surfaceExtractorHigh.execute();
|
||||
auto meshHighLOD = extractMarchingCubesSurface(&volData, PolyVox::Region(Vector3DInt32(30, 0, 0), Vector3DInt32(63, 63, 63)));
|
||||
meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0));
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
|
@ -157,6 +157,28 @@ namespace PolyVox
|
||||
WrapMode m_eWrapMode;
|
||||
typename VolumeType::VoxelType m_tBorderValue;
|
||||
};
|
||||
|
||||
template<typename VolumeType, typename IsQuadNeeded>
|
||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicSurface(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||
{
|
||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > result;
|
||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded);
|
||||
extractor.execute();
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename VolumeType>
|
||||
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
|
||||
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
|
||||
#if defined(_MSC_VER)
|
||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicSurface(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true)
|
||||
#else
|
||||
SurfaceMesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicSurface(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true)
|
||||
#endif
|
||||
{
|
||||
DefaultIsQuadNeeded<typename VolumeType::VoxelType> isQuadNeeded;
|
||||
return extractCubicSurface<VolumeType, DefaultIsQuadNeeded<typename VolumeType::VoxelType> >(volData, region, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
#include "PolyVoxCore/CubicSurfaceExtractor.inl"
|
||||
|
@ -210,6 +210,28 @@ namespace PolyVox
|
||||
//Our threshold value
|
||||
typename Controller::DensityType m_tThreshold;
|
||||
};
|
||||
|
||||
template< typename VolumeType, typename Controller>
|
||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesSurface(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller)
|
||||
{
|
||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > result;
|
||||
MarchingCubesSurfaceExtractor<VolumeType, Controller> extractor(volData, region, &result, eWrapMode, tBorderValue, controller);
|
||||
extractor.execute();
|
||||
return result;
|
||||
}
|
||||
|
||||
template< typename VolumeType>
|
||||
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
|
||||
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
|
||||
#if defined(_MSC_VER)
|
||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesSurface(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType())
|
||||
#else
|
||||
SurfaceMesh<MarchingCubesVertex<typename VolumeType::VoxelType> > extractMarchingCubesSurface(VolumeType* volData, Region region, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType())
|
||||
#endif
|
||||
{
|
||||
DefaultMarchingCubesController<typename VolumeType::VoxelType> controller;
|
||||
return extractMarchingCubesSurface(volData, region, eWrapMode, tBorderValue, controller);
|
||||
}
|
||||
}
|
||||
|
||||
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.inl"
|
||||
|
@ -106,10 +106,9 @@ uint32_t testForType(void)
|
||||
{
|
||||
for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength)
|
||||
{
|
||||
SurfaceMesh<CubicVertex<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();
|
||||
|
||||
auto result = extractCubicSurface(&volData, regionToExtract);
|
||||
|
||||
uTotalVertices += result.getNoOfVertices();
|
||||
uTotalIndices += result.getNoOfIndices();
|
||||
|
@ -102,7 +102,7 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel)
|
||||
|
||||
// Runs the surface extractor for a given type.
|
||||
template <typename VoxelType>
|
||||
void testForType(SurfaceMesh<MarchingCubesVertex<VoxelType> >& result)
|
||||
SurfaceMesh<MarchingCubesVertex<VoxelType> > testForType(void) //I think we could avoid specifying this return type by using auto/decltype?
|
||||
{
|
||||
const int32_t uVolumeSideLength = 32;
|
||||
|
||||
@ -127,8 +127,10 @@ void testForType(SurfaceMesh<MarchingCubesVertex<VoxelType> >& result)
|
||||
|
||||
DefaultMarchingCubesController<VoxelType> controller;
|
||||
controller.setThreshold(50);
|
||||
MarchingCubesSurfaceExtractor< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, VoxelType(), controller);
|
||||
extractor.execute();
|
||||
|
||||
auto result = extractMarchingCubesSurface(&volData, volData.getEnclosingRegion(), WrapModes::Border, VoxelType(), controller);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void testCustomController(SurfaceMesh<MarchingCubesVertex<float> >& result)
|
||||
@ -163,74 +165,65 @@ void TestSurfaceExtractor::testExecute()
|
||||
const static float fExpectedMaterial = 42.0f;
|
||||
const static float fNoMaterial = 1.0f;
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<int8_t> > int8Mesh;
|
||||
SurfaceMesh<MarchingCubesVertex<int8_t> > mesh;
|
||||
//Run the test for various voxel types.
|
||||
QBENCHMARK {
|
||||
testForType<int8_t>(int8Mesh);
|
||||
mesh = testForType<int8_t>();
|
||||
}
|
||||
QCOMPARE(int8Mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(int8Mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(int8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int8_t>(fNoMaterial));
|
||||
QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int8_t>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<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));
|
||||
auto mesh1 = testForType<uint8_t>();
|
||||
QCOMPARE(mesh1.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh1.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh1.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<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));
|
||||
auto mesh2 = testForType<int16_t>();
|
||||
QCOMPARE(mesh2.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh2.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh2.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int16_t>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<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));
|
||||
auto mesh3 = testForType<uint16_t>();
|
||||
QCOMPARE(mesh3.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh3.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh3.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint16_t>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<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));
|
||||
auto mesh4 = testForType<int32_t>();
|
||||
QCOMPARE(mesh4.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh4.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh4.getVertices()[uMaterialToCheck].getMaterial(), static_cast<int32_t>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<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));
|
||||
auto mesh5 = testForType<uint32_t>();
|
||||
QCOMPARE(mesh5.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh5.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh5.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint32_t>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<float> > floatMesh;
|
||||
testForType<float>(floatMesh);
|
||||
QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
auto mesh6 = testForType<float>();
|
||||
QCOMPARE(mesh6.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh6.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh6.getVertices()[uMaterialToCheck].getMaterial(), static_cast<float>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<double> > doubleMesh;
|
||||
testForType<double>(doubleMesh);
|
||||
QCOMPARE(doubleMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(doubleMesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(doubleMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<double>(fNoMaterial));
|
||||
auto mesh7 = testForType<double>();
|
||||
QCOMPARE(mesh7.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh7.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh7.getVertices()[uMaterialToCheck].getMaterial(), static_cast<double>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<Density8> > densityMesh;
|
||||
testForType<Density8>(densityMesh);
|
||||
QCOMPARE(densityMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(densityMesh.getNoOfIndices(), uExpectedIndices);
|
||||
//QCOMPARE(densityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
|
||||
auto mesh8 = testForType<Density8>();
|
||||
QCOMPARE(mesh8.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh8.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(mesh8.getVertices()[uMaterialToCheck].getMaterial(), static_cast<Density8>(fNoMaterial));
|
||||
|
||||
SurfaceMesh<MarchingCubesVertex<MaterialDensityPair88> > materialDensityMesh;
|
||||
testForType<MaterialDensityPair88>(materialDensityMesh);
|
||||
QCOMPARE(materialDensityMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(materialDensityMesh.getNoOfIndices(), uExpectedIndices);
|
||||
//QCOMPARE(materialDensityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast<uint8_t>(fNoMaterial));
|
||||
auto mesh9 = testForType<MaterialDensityPair88>();
|
||||
QCOMPARE(mesh9.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(mesh9.getNoOfIndices(), uExpectedIndices);
|
||||
//QCOMPARE(mesh9.getVertices()[uMaterialToCheck].getMaterial(), fExpectedMaterial);
|
||||
|
||||
//Test whether the CustomSurfaceExtractor works.
|
||||
testCustomController(floatMesh);
|
||||
/*testCustomController(floatMesh);
|
||||
QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices);
|
||||
QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices);
|
||||
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);
|
||||
QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);*/
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestSurfaceExtractor)
|
||||
|
@ -183,10 +183,8 @@ void TestVolumeSubclass::testExtractSurface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SurfaceMesh<CubicVertex<Material8> > result;
|
||||
CubicSurfaceExtractor< VolumeSubclass<Material8> > cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result);
|
||||
cubicSurfaceExtractor.execute();
|
||||
|
||||
auto result = extractCubicSurface(&volumeSubclass, volumeSubclass.getEnclosingRegion());
|
||||
|
||||
QCOMPARE(result.getNoOfVertices(), static_cast<uint32_t>(8));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user