From 3a171e698b0433e2731b2aeb359562dff310c1bd Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 30 Apr 2011 23:51:04 +0100 Subject: [PATCH] Modified SurfaceExtractor to use template template parameters. --- examples/Basic/main.cpp | 2 +- examples/OpenGL/OpenGLWidget.cpp | 2 +- examples/OpenGL/main.cpp | 4 +- examples/Paging/main.cpp | 2 +- library/PolyVoxCore/include/Filters.h | 5 +- library/PolyVoxCore/include/Filters.inl | 4 +- .../PolyVoxCore/include/GradientEstimators.h | 29 ++-- .../include/GradientEstimators.inl | 20 +-- .../include/PolyVoxForwardDeclarations.h | 4 +- .../include/SimpleVolumeSampler.inl | 2 +- .../PolyVoxCore/include/SurfaceExtractor.h | 119 ++++++++++++++- .../PolyVoxCore/include/SurfaceExtractor.inl | 135 +++--------------- library/PolyVoxCore/include/VoxelFilters.h | 3 +- .../PolyVoxCore/source/GradientEstimators.cpp | 8 +- library/PolyVoxCore/source/VoxelFilters.cpp | 3 +- 15 files changed, 174 insertions(+), 168 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 9c76efa4..0e883216 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -91,4 +91,4 @@ int main(int argc, char *argv[]) //Run the message pump. return app.exec(); -} +} diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 1c8496bd..afc312ea 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 surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get()); surfaceExtractor.execute(); polyvox_shared_ptr< SurfaceMesh > decimatedMesh(new SurfaceMesh); diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 68c1c708..f39af0f3 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -101,8 +101,8 @@ int main(int argc, char *argv[]) createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity()); //Smooth part of the volume - smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127))); - smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127))); + smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127))); + smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127))); QApplication app(argc, argv); diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 8accfa19..bef35756 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 surfaceExtractor(&volData, reg, &mesh); //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, reg, &mesh); surfaceExtractor.execute(); std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl; diff --git a/library/PolyVoxCore/include/Filters.h b/library/PolyVoxCore/include/Filters.h index e10ac579..308dc367 100644 --- a/library/PolyVoxCore/include/Filters.h +++ b/library/PolyVoxCore/include/Filters.h @@ -26,12 +26,11 @@ freely, subject to the following restrictions: #include "Array.h" #include "Region.h" -#include "LargeVolume.h" namespace PolyVox { - template - void smoothRegion(LargeVolume& volData, const Region& regionToSmooth); + template< template class VolumeType, typename VoxelType> + void smoothRegion(VolumeType& volData, const Region& regionToSmooth); }//namespace PolyVox #include "Filters.inl" diff --git a/library/PolyVoxCore/include/Filters.inl b/library/PolyVoxCore/include/Filters.inl index b21be87b..9aca992d 100644 --- a/library/PolyVoxCore/include/Filters.inl +++ b/library/PolyVoxCore/include/Filters.inl @@ -2,8 +2,8 @@ namespace PolyVox { - template - void smoothRegion(LargeVolume& volData, const Region& regionToSmooth) + template< template class VolumeType, typename VoxelType> + void smoothRegion(VolumeType& volData, const Region& regionToSmooth) { Region croppedRegion = regionToSmooth; diff --git a/library/PolyVoxCore/include/GradientEstimators.h b/library/PolyVoxCore/include/GradientEstimators.h index 41aeb10b..e341c72a 100644 --- a/library/PolyVoxCore/include/GradientEstimators.h +++ b/library/PolyVoxCore/include/GradientEstimators.h @@ -26,10 +26,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_GradientEstimators_H__ #define __PolyVox_GradientEstimators_H__ -#include "LargeVolume.h" - #include +#include "Vector.h" + namespace PolyVox { enum NormalGenerationMethod @@ -41,22 +41,23 @@ namespace PolyVox SOBEL_SMOOTHED /// - Vector3DFloat computeCentralDifferenceGradient(const typename LargeVolume::Sampler& volIter); + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter); - template - Vector3DFloat computeSmoothCentralDifferenceGradient(typename LargeVolume::Sampler& volIter); + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType::Sampler& volIter); - template - Vector3DFloat computeDecimatedCentralDifferenceGradient(typename LargeVolume::Sampler& volIter); + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeDecimatedCentralDifferenceGradient(typename VolumeType::Sampler& volIter); - template - Vector3DFloat computeSobelGradient(const typename LargeVolume::Sampler& volIter); - template - Vector3DFloat computeSmoothSobelGradient(typename LargeVolume::Sampler& volIter); + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeSobelGradient(const typename VolumeType::Sampler& volIter); - POLYVOX_API void computeNormalsForVertices(LargeVolume* volumeData, SurfaceMesh& mesh, NormalGenerationMethod normalGenerationMethod); - POLYVOX_API Vector3DFloat computeNormal(LargeVolume* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod); + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeSmoothSobelGradient(typename VolumeType::Sampler& volIter); + + //POLYVOX_API void computeNormalsForVertices(VolumeType* volumeData, SurfaceMesh& mesh, NormalGenerationMethod normalGenerationMethod); + //POLYVOX_API Vector3DFloat computeNormal(VolumeType* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod); } #include "GradientEstimators.inl" diff --git a/library/PolyVoxCore/include/GradientEstimators.inl b/library/PolyVoxCore/include/GradientEstimators.inl index de687269..5ff36aa4 100644 --- a/library/PolyVoxCore/include/GradientEstimators.inl +++ b/library/PolyVoxCore/include/GradientEstimators.inl @@ -27,8 +27,8 @@ freely, subject to the following restrictions: namespace PolyVox { - template - Vector3DFloat computeCentralDifferenceGradient(const typename LargeVolume::Sampler& volIter) + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter) { //FIXME - bitwise way of doing this? VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0; @@ -48,8 +48,8 @@ namespace PolyVox ); } - template - Vector3DFloat computeDecimatedCentralDifferenceGradient(const typename LargeVolume::Sampler& volIter) + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeDecimatedCentralDifferenceGradient(const typename VolumeType::Sampler& volIter) { const int32_t x = volIter.getPosX(); const int32_t y = volIter.getPosY(); @@ -73,8 +73,8 @@ namespace PolyVox ); } - template - Vector3DFloat computeSmoothCentralDifferenceGradient(typename LargeVolume::Sampler& volIter) + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeSmoothCentralDifferenceGradient(typename VolumeType::Sampler& volIter) { int32_t initialX = volIter.getPosX(); int32_t initialY = volIter.getPosY(); @@ -104,8 +104,8 @@ namespace PolyVox ); } - template - Vector3DFloat computeSobelGradient(const typename LargeVolume::Sampler& volIter) + template< template class VolumeType, typename VoxelType> + 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} } }; @@ -187,8 +187,8 @@ namespace PolyVox return Vector3DFloat(static_cast(-xGrad),static_cast(-yGrad),static_cast(-zGrad)); } - template - Vector3DFloat computeSmoothSobelGradient(typename LargeVolume::Sampler& volIter) + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeSmoothSobelGradient(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} } }; diff --git a/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h index 8d0bc5aa..8d1ce04f 100644 --- a/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h @@ -84,8 +84,8 @@ namespace PolyVox class Region; class PositionMaterial; class PositionMaterialNormal; - template class CubicSurfaceExtractor; - template class SurfaceExtractor; + template< template class VolumeType, typename VoxelType> class CubicSurfaceExtractor; + template< template class VolumeType, typename VoxelType> class SurfaceExtractor; //---------- Vector ---------- template class Vector; diff --git a/library/PolyVoxCore/include/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/SimpleVolumeSampler.inl index 4db26ea5..2f479a91 100644 --- a/library/PolyVoxCore/include/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/SimpleVolumeSampler.inl @@ -155,7 +155,7 @@ namespace PolyVox if(mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) { - Block* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); + Block* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock; } diff --git a/library/PolyVoxCore/include/SurfaceExtractor.h b/library/PolyVoxCore/include/SurfaceExtractor.h index 86fa4018..e3334866 100644 --- a/library/PolyVoxCore/include/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/SurfaceExtractor.h @@ -31,11 +31,11 @@ freely, subject to the following restrictions: namespace PolyVox { - template + template< template class VolumeType, typename VoxelType> class SurfaceExtractor { public: - SurfaceExtractor(LargeVolume* volData, Region region, SurfaceMesh* result); + SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result); void execute(); @@ -54,8 +54,115 @@ namespace PolyVox Array2DInt32& m_pCurrentVertexIndicesY, Array2DInt32& m_pCurrentVertexIndicesZ); - Vector3DFloat computeCentralDifferenceGradient(const typename LargeVolume::Sampler& volIter); - Vector3DFloat computeSobelGradient(const typename LargeVolume::Sampler& volIter); + //////////////////////////////////////////////////////////////////////////////// + // 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. + //////////////////////////////////////////////////////////////////////////////// + template< template class VolumeType, typename VoxelType> + Vector3DFloat computeCentralDifferenceGradient(const typename VolumeType::Sampler& volIter) + { + uint8_t voxel1nx = volIter.peekVoxel1nx0py0pz().getDensity(); + uint8_t voxel1px = volIter.peekVoxel1px0py0pz().getDensity(); + + uint8_t voxel1ny = volIter.peekVoxel0px1ny0pz().getDensity(); + uint8_t voxel1py = volIter.peekVoxel0px1py0pz().getDensity(); + + uint8_t voxel1nz = volIter.peekVoxel0px0py1nz().getDensity(); + uint8_t voxel1pz = volIter.peekVoxel0px0py1pz().getDensity(); + + return Vector3DFloat + ( + static_cast(voxel1nx) - static_cast(voxel1px), + static_cast(voxel1ny) - static_cast(voxel1py), + static_cast(voxel1nz) - static_cast(voxel1pz) + ); + } + + template< template class VolumeType, typename VoxelType> + 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} } }; + + const uint8_t pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz().getDensity(); + const uint8_t pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz().getDensity(); + const uint8_t pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz().getDensity(); + const uint8_t pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz().getDensity(); + const uint8_t pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz().getDensity(); + const uint8_t pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz().getDensity(); + const uint8_t pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz().getDensity(); + const uint8_t pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz().getDensity(); + const uint8_t pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz().getDensity(); + + const uint8_t pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz().getDensity(); + const uint8_t pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz().getDensity(); + const uint8_t pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz().getDensity(); + const uint8_t pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz().getDensity(); + //const uint8_t pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz().getDensity(); + const uint8_t pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz().getDensity(); + const uint8_t pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz().getDensity(); + const uint8_t pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz().getDensity(); + const uint8_t pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz().getDensity(); + + const uint8_t pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz().getDensity(); + const uint8_t pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz().getDensity(); + const uint8_t pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz().getDensity(); + const uint8_t pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz().getDensity(); + const uint8_t pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz().getDensity(); + const uint8_t pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz().getDensity(); + const uint8_t pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz().getDensity(); + const uint8_t pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz().getDensity(); + const uint8_t pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz().getDensity(); + + const int xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - + weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * + pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz - + weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] * + pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz - + weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] * + pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz + + weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] * + pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz + + weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] * + pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz + + weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] * + pVoxel1px1py1pz); + + const int yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - + weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * + pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz + + weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] * + pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz - + weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] * + pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz + + weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] * + pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz - + weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] * + pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz + + weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] * + pVoxel1px1py1pz); + + const int zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz + + weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] * + pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz - + weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] * + pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz + + weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] * + pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz - + weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] * + pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz + + weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] * + pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz - + weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] * + pVoxel1px1py1pz); + + //Note: The above actually give gradients going from low density to high density. + //For our normals we want the the other way around, so we switch the components as we return them. + return Vector3DFloat(static_cast(-xGrad),static_cast(-yGrad),static_cast(-zGrad)); + } + //////////////////////////////////////////////////////////////////////////////// + // End of compiler bug workaroumd. + //////////////////////////////////////////////////////////////////////////////// //Use the cell bitmasks to generate all the indices needed for that slice void generateIndicesForSlice(const Array2DUint8& pPreviousBitmask, @@ -67,8 +174,8 @@ namespace PolyVox const Array2DInt32& m_pCurrentVertexIndicesZ); //The volume data and a sampler to access it. - LargeVolume* m_volData; - typename LargeVolume::Sampler m_sampVolume; + VolumeType* m_volData; + typename VolumeType::Sampler m_sampVolume; //Holds a position in volume space. int32_t iXVolSpace; diff --git a/library/PolyVoxCore/include/SurfaceExtractor.inl b/library/PolyVoxCore/include/SurfaceExtractor.inl index 6c3f6087..610f0bfe 100644 --- a/library/PolyVoxCore/include/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/SurfaceExtractor.inl @@ -29,8 +29,8 @@ freely, subject to the following restrictions: namespace PolyVox { - template - SurfaceExtractor::SurfaceExtractor(LargeVolume* volData, Region region, SurfaceMesh* result) + template< template class VolumeType, typename VoxelType> + SurfaceExtractor::SurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result) :m_volData(volData) ,m_sampVolume(volData) ,m_regSizeInVoxels(region) @@ -43,8 +43,8 @@ namespace PolyVox m_meshCurrent->clear(); } - template - void SurfaceExtractor::execute() + template< template class VolumeType, typename VoxelType> + void SurfaceExtractor::execute() { uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 1; uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 1; @@ -130,9 +130,9 @@ namespace PolyVox m_meshCurrent->m_vecLodRecords.push_back(lodRecord); } - template + template< template class VolumeType, typename VoxelType> template - uint32_t SurfaceExtractor::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) + uint32_t SurfaceExtractor::computeBitmaskForSlice(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) { m_uNoOfOccupiedCells = 0; @@ -196,9 +196,9 @@ namespace PolyVox return m_uNoOfOccupiedCells; } - template + template< template class VolumeType, typename VoxelType> template - void SurfaceExtractor::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) + void SurfaceExtractor::computeBitmaskForCell(const Array2DUint8& pPreviousBitmask, Array2DUint8& pCurrentBitmask) { uint8_t iCubeIndex = 0; @@ -396,8 +396,8 @@ namespace PolyVox } } - template - void SurfaceExtractor::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask, + template< template class VolumeType, typename VoxelType> + void SurfaceExtractor::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask, Array2DInt32& m_pCurrentVertexIndicesX, Array2DInt32& m_pCurrentVertexIndicesY, Array2DInt32& m_pCurrentVertexIndicesZ) @@ -429,14 +429,14 @@ namespace PolyVox m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); const VoxelType v000 = m_sampVolume.getVoxel(); - const Vector3DFloat n000 = computeCentralDifferenceGradient(m_sampVolume); + 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 Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume); + const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume); //float fInterp = static_cast(v100.getDensity() - VoxelType::getMinDensity()) / static_cast(VoxelType::getMaxDensity() - VoxelType::getMinDensity()); float fInterp = static_cast(VoxelType::getThreshold() - v000.getDensity()) / static_cast(v100.getDensity() - v000.getDensity()); @@ -460,7 +460,7 @@ namespace PolyVox { m_sampVolume.movePositiveY(); const VoxelType v010 = m_sampVolume.getVoxel(); - const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume); + const Vector3DFloat n010 = computeCentralDifferenceGradient(m_sampVolume); float fInterp = static_cast(VoxelType::getThreshold() - v000.getDensity()) / static_cast(v010.getDensity() - v000.getDensity()); //fInterp = 0.5f; @@ -483,7 +483,7 @@ namespace PolyVox { m_sampVolume.movePositiveZ(); const VoxelType v001 = m_sampVolume.getVoxel(); - const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume); + const Vector3DFloat n001 = computeCentralDifferenceGradient(m_sampVolume); float fInterp = static_cast(VoxelType::getThreshold() - v000.getDensity()) / static_cast(v001.getDensity() - v000.getDensity()); //fInterp = 0.5f; @@ -506,111 +506,8 @@ namespace PolyVox } } - template - Vector3DFloat SurfaceExtractor::computeCentralDifferenceGradient(const typename LargeVolume::Sampler& volIter) - { - uint8_t voxel1nx = volIter.peekVoxel1nx0py0pz().getDensity(); - uint8_t voxel1px = volIter.peekVoxel1px0py0pz().getDensity(); - - uint8_t voxel1ny = volIter.peekVoxel0px1ny0pz().getDensity(); - uint8_t voxel1py = volIter.peekVoxel0px1py0pz().getDensity(); - - uint8_t voxel1nz = volIter.peekVoxel0px0py1nz().getDensity(); - uint8_t voxel1pz = volIter.peekVoxel0px0py1pz().getDensity(); - - return Vector3DFloat - ( - static_cast(voxel1nx) - static_cast(voxel1px), - static_cast(voxel1ny) - static_cast(voxel1py), - static_cast(voxel1nz) - static_cast(voxel1pz) - ); - } - - template - Vector3DFloat SurfaceExtractor::computeSobelGradient(const typename LargeVolume::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} } }; - - const uint8_t pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz().getDensity(); - const uint8_t pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz().getDensity(); - const uint8_t pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz().getDensity(); - const uint8_t pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz().getDensity(); - const uint8_t pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz().getDensity(); - const uint8_t pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz().getDensity(); - const uint8_t pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz().getDensity(); - const uint8_t pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz().getDensity(); - const uint8_t pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz().getDensity(); - - const uint8_t pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz().getDensity(); - const uint8_t pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz().getDensity(); - const uint8_t pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz().getDensity(); - const uint8_t pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz().getDensity(); - //const uint8_t pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz().getDensity(); - const uint8_t pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz().getDensity(); - const uint8_t pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz().getDensity(); - const uint8_t pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz().getDensity(); - const uint8_t pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz().getDensity(); - - const uint8_t pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz().getDensity(); - const uint8_t pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz().getDensity(); - const uint8_t pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz().getDensity(); - const uint8_t pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz().getDensity(); - const uint8_t pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz().getDensity(); - const uint8_t pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz().getDensity(); - const uint8_t pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz().getDensity(); - const uint8_t pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz().getDensity(); - const uint8_t pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz().getDensity(); - - const int xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - - weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * - pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz - - weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] * - pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz - - weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] * - pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz + - weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] * - pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz + - weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] * - pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz + - weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] * - pVoxel1px1py1pz); - - const int yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz - - weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] * - pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz + - weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] * - pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz - - weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] * - pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz + - weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] * - pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz - - weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] * - pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz + - weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] * - pVoxel1px1py1pz); - - const int zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz + - weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] * - pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz - - weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] * - pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz + - weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] * - pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz - - weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] * - pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz + - weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] * - pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz - - weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] * - pVoxel1px1py1pz); - - //Note: The above actually give gradients going from low density to high density. - //For our normals we want the the other way around, so we switch the components as we return them. - return Vector3DFloat(static_cast(-xGrad),static_cast(-yGrad),static_cast(-zGrad)); - } - - template - void SurfaceExtractor::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask, + template< template class VolumeType, typename VoxelType> + void SurfaceExtractor::generateIndicesForSlice(const Array2DUint8& pPreviousBitmask, const Array2DInt32& m_pPreviousVertexIndicesX, const Array2DInt32& m_pPreviousVertexIndicesY, const Array2DInt32& m_pPreviousVertexIndicesZ, diff --git a/library/PolyVoxCore/include/VoxelFilters.h b/library/PolyVoxCore/include/VoxelFilters.h index ffedc89b..70d9a943 100644 --- a/library/PolyVoxCore/include/VoxelFilters.h +++ b/library/PolyVoxCore/include/VoxelFilters.h @@ -31,7 +31,8 @@ freely, subject to the following restrictions: namespace PolyVox { - float computeSmoothedVoxel(LargeVolume::Sampler& volIter); + template< template class VolumeType> + float computeSmoothedVoxel(typename VolumeType::Sampler& volIter); } #endif \ No newline at end of file diff --git a/library/PolyVoxCore/source/GradientEstimators.cpp b/library/PolyVoxCore/source/GradientEstimators.cpp index b33ffb50..eef1244e 100644 --- a/library/PolyVoxCore/source/GradientEstimators.cpp +++ b/library/PolyVoxCore/source/GradientEstimators.cpp @@ -32,7 +32,7 @@ using namespace std; namespace PolyVox { - void computeNormalsForVertices(LargeVolume* volumeData, SurfaceMesh& mesh, NormalGenerationMethod normalGenerationMethod) + /*void computeNormalsForVertices(LargeVolume* volumeData, SurfaceMesh& mesh, NormalGenerationMethod normalGenerationMethod) { std::vector& vecVertices = mesh.getRawVertexData(); std::vector::iterator iterSurfaceVertex = vecVertices.begin(); @@ -61,9 +61,9 @@ namespace PolyVox } //(lowerCornerInside && upperCornerInside) ++iterSurfaceVertex; } - } + }*/ - Vector3DFloat computeNormal(LargeVolume* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod) + /*Vector3DFloat computeNormal(LargeVolume* volumeData, const Vector3DFloat& v3dPos, NormalGenerationMethod normalGenerationMethod) { Vector3DFloat v3dGradient; //To store the result @@ -147,5 +147,5 @@ namespace PolyVox } } return v3dGradient; - } + }*/ } diff --git a/library/PolyVoxCore/source/VoxelFilters.cpp b/library/PolyVoxCore/source/VoxelFilters.cpp index e6dd8505..844f7377 100644 --- a/library/PolyVoxCore/source/VoxelFilters.cpp +++ b/library/PolyVoxCore/source/VoxelFilters.cpp @@ -25,7 +25,8 @@ freely, subject to the following restrictions: namespace PolyVox { - float computeSmoothedVoxel(LargeVolume::Sampler& volIter) + template< template class VolumeType> + float computeSmoothedVoxel(typename VolumeType::Sampler& volIter) { assert(volIter.getPosX() >= 1); assert(volIter.getPosY() >= 1);