diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index f709d9b2..10f7c7f6 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -89,7 +89,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume* volDat //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent); polyvox_shared_ptr< SurfaceMesh > mesh(new SurfaceMesh); - SurfaceExtractor surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get()); + SurfaceExtractor< LargeVolume > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get()); surfaceExtractor.execute(); polyvox_shared_ptr< SurfaceMesh > decimatedMesh(new SurfaceMesh); diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 0de7d324..bf32a5ce 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -287,7 +287,7 @@ int main(int argc, char *argv[]) //Extract the surface SurfaceMesh mesh; //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); - SurfaceExtractor surfaceExtractor(&volData, reg, &mesh); + SurfaceExtractor< LargeVolume > surfaceExtractor(&volData, reg, &mesh); //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, reg, &mesh); surfaceExtractor.execute(); std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl; diff --git a/examples/SmoothLOD/main.cpp b/examples/SmoothLOD/main.cpp index be423a76..4a5c1481 100644 --- a/examples/SmoothLOD/main.cpp +++ b/examples/SmoothLOD/main.cpp @@ -98,13 +98,13 @@ int main(int argc, char *argv[]) //Extract the surface SurfaceMesh meshLowLOD; - SurfaceExtractor surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD); + SurfaceExtractor< RawVolume > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD); surfaceExtractor.execute(); meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f); //Extract the surface SurfaceMesh meshHighLOD; - SurfaceExtractor surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD); + SurfaceExtractor< SimpleVolume > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD); surfaceExtractorHigh.execute(); meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0)); diff --git a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h index 8bca21ff..e3f08d22 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h @@ -63,7 +63,7 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// // CubicSurfaceExtractor //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> class CubicSurfaceExtractor; + template< typename VolumeType> class CubicSurfaceExtractor; //////////////////////////////////////////////////////////////////////////////// // Density @@ -129,7 +129,7 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// // SurfaceExtractor //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> class SurfaceExtractor; + template class SurfaceExtractor; //////////////////////////////////////////////////////////////////////////////// // SurfaceMesh diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h index ceddf628..e628fea6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h @@ -48,11 +48,11 @@ namespace PolyVox return 1; } - template< template class VolumeType, typename VoxelType> + template< typename VolumeType> class SurfaceExtractor { public: - SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, typename VoxelTypeTraits::DensityType tThreshold = (VoxelTypeTraits::minDensity() + VoxelTypeTraits::maxDensity()) / 2); + SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, typename VoxelTypeTraits::DensityType tThreshold = (VoxelTypeTraits::minDensity() + VoxelTypeTraits::maxDensity()) / 2); void execute(); @@ -75,7 +75,7 @@ namespace PolyVox // NOTE: These two functions are in the .h file rather than the .inl due to an apparent bug in VC2010. //See http://stackoverflow.com/questions/1484885/strange-vc-compile-error-c2244 for details. //////////////////////////////////////////////////////////////////////////////// - Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter) + Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter) { //FIXME - Should actually use DensityType here, both in principle and because the maths may be //faster (and to reduce casts). So it would be good to add a way to get DensityType from a voxel. @@ -97,7 +97,7 @@ namespace PolyVox ); } - Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter) + Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter) { static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, { {3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } }; @@ -194,8 +194,8 @@ namespace PolyVox const Array2DInt32& m_pCurrentVertexIndicesY); //The volume data and a sampler to access it. - VolumeType* m_volData; - typename VolumeType::Sampler m_sampVolume; + VolumeType* m_volData; + typename VolumeType::Sampler m_sampVolume; //Holds a position in volume space. int32_t iXVolSpace; @@ -223,7 +223,7 @@ namespace PolyVox Region m_regSliceCurrent; //Our threshold value - typename VoxelTypeTraits::DensityType m_tThreshold; + typename VoxelTypeTraits::DensityType m_tThreshold; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index e4c975bd..b4562b81 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -23,8 +23,8 @@ freely, subject to the following restrictions: namespace PolyVox { - template< template class VolumeType, typename VoxelType> - SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, typename VoxelTypeTraits::DensityType tThreshold) + template + SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, typename VoxelTypeTraits::DensityType tThreshold) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -36,8 +36,8 @@ namespace PolyVox m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); } - template< template class VolumeType, typename VoxelType> - void SurfaceExtractor::execute() + template + void SurfaceExtractor::execute() { m_meshCurrent->clear(); @@ -125,9 +125,9 @@ namespace PolyVox m_meshCurrent->m_vecLodRecords.push_back(lodRecord); } - template< template class VolumeType, typename VoxelType> + template template - uint32_t SurfaceExtractor::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) + uint32_t SurfaceExtractor::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) { m_uNoOfOccupiedCells = 0; @@ -191,20 +191,20 @@ namespace PolyVox return m_uNoOfOccupiedCells; } - template< template class VolumeType, typename VoxelType> + template template - void SurfaceExtractor::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) + void SurfaceExtractor::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) { uint8_t iCubeIndex = 0; - VoxelType v000; - VoxelType v100; - VoxelType v010; - VoxelType v110; - VoxelType v001; - VoxelType v101; - VoxelType v011; - VoxelType v111; + VolumeType::VoxelType v000; + VolumeType::VoxelType v100; + VolumeType::VoxelType v010; + VolumeType::VoxelType v110; + VolumeType::VoxelType v001; + VolumeType::VoxelType v101; + VolumeType::VoxelType v011; + VolumeType::VoxelType v111; if(isPrevZAvail) { @@ -391,8 +391,8 @@ namespace PolyVox } } - template< template class VolumeType, typename VoxelType> - void SurfaceExtractor::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask, + template + void SurfaceExtractor::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask, Array2DInt32& m_pCurrentVertexIndicesX, Array2DInt32& m_pCurrentVertexIndicesY, Array2DInt32& m_pCurrentVertexIndicesZ) @@ -423,14 +423,14 @@ namespace PolyVox m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); - const VoxelType v000 = m_sampVolume.getVoxel(); + const VolumeType::VoxelType v000 = m_sampVolume.getVoxel(); const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume); /* Find the vertices where the surface intersects the cube */ if (edgeTable[iCubeIndex] & 1) { m_sampVolume.movePositiveX(); - const VoxelType v100 = m_sampVolume.getVoxel(); + const VolumeType::VoxelType v100 = m_sampVolume.getVoxel(); const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume); float fInterp = static_cast(m_tThreshold - convertToDensity(v000)) / static_cast(convertToDensity(v100) - convertToDensity(v000)); @@ -456,7 +456,7 @@ namespace PolyVox if (edgeTable[iCubeIndex] & 8) { m_sampVolume.movePositiveY(); - const VoxelType v010 = m_sampVolume.getVoxel(); + const VolumeType::VoxelType v010 = m_sampVolume.getVoxel(); const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume); float fInterp = static_cast(m_tThreshold - convertToDensity(v000)) / static_cast(convertToDensity(v010) - convertToDensity(v000)); @@ -482,7 +482,7 @@ namespace PolyVox if (edgeTable[iCubeIndex] & 256) { m_sampVolume.movePositiveZ(); - const VoxelType v001 = m_sampVolume.getVoxel(); + const VolumeType::VoxelType v001 = m_sampVolume.getVoxel(); const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume); float fInterp = static_cast(m_tThreshold - convertToDensity(v000)) / static_cast(convertToDensity(v001) - convertToDensity(v000)); @@ -509,8 +509,8 @@ namespace PolyVox } } - template< template class VolumeType, typename VoxelType> - void SurfaceExtractor::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask, + template + void SurfaceExtractor::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask, const Array2DInt32& m_pPreviousVertexIndicesX, const Array2DInt32& m_pPreviousVertexIndicesY, const Array2DInt32& m_pPreviousVertexIndicesZ, diff --git a/library/PolyVoxCore/source/SimpleInterface.cpp b/library/PolyVoxCore/source/SimpleInterface.cpp index 10aa9390..be28427f 100644 --- a/library/PolyVoxCore/source/SimpleInterface.cpp +++ b/library/PolyVoxCore/source/SimpleInterface.cpp @@ -37,7 +37,7 @@ namespace PolyVox void extractSmoothMesh(Volume& volume, const Region& region, Mesh& resultMesh) { - SurfaceExtractor surfaceExtractor(&volume, region, &resultMesh); + SurfaceExtractor< SimpleVolume > surfaceExtractor(&volume, region, &resultMesh); surfaceExtractor.execute(); } } diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 2f633d76..e412d515 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -92,7 +92,7 @@ void testForType(SurfaceMesh& result) } } - SurfaceExtractor extractor(&volData, volData.getEnclosingRegion(), &result, 50); + SurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, 50); extractor.execute(); }