From 97e6b5677820e871350644e85746aba18d214c7b Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 28 Nov 2011 16:43:40 +0000 Subject: [PATCH 1/6] Fixed some compiler warnings. Removed m_mapUsedMaterials as it didn't seem to be used. --- examples/OpenGL/OpenGLImmediateModeSupport.cpp | 2 +- .../OpenGL/OpenGLVertexBufferObjectSupport.cpp | 2 +- .../include/PolyVoxCore/ConstVolumeProxy.h | 9 +++++++++ .../CubicSurfaceExtractorWithNormals.inl | 18 +++++++++--------- .../include/PolyVoxCore/SurfaceMesh.h | 5 ----- .../include/PolyVoxCore/SurfaceMesh.inl | 6 ------ 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/examples/OpenGL/OpenGLImmediateModeSupport.cpp b/examples/OpenGL/OpenGLImmediateModeSupport.cpp index 3e09b21b..c891008d 100644 --- a/examples/OpenGL/OpenGLImmediateModeSupport.cpp +++ b/examples/OpenGL/OpenGLImmediateModeSupport.cpp @@ -49,7 +49,7 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh& mes - uint8_t material = vertex.getMaterial() + 0.5; + uint8_t material = static_cast(vertex.getMaterial() + 0.5); OpenGLColour colour = convertMaterialIDToColour(material); diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp index a2f9d7e9..8dfb3351 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp @@ -83,7 +83,7 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh(vertex.getMaterial() + 0.5); OpenGLColour colour = convertMaterialIDToColour(material); diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h index bde93f4d..c8e33588 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h @@ -64,6 +64,15 @@ namespace PolyVox :m_pVolume(pVolume) ,m_regValid(regValid) { + //Should never get here as it's a private constructor + assert(false); + } + + //Private assignment operator, so client code can't abuse this class. + ConstVolumeProxy& operator=(const ConstVolumeProxy& rhs) throw() + { + //Should never get here as it's a private assignment operator + assert(false); } const LargeVolume& m_pVolume; diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index 1cd99ea4..c448cbba 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -44,16 +44,16 @@ namespace PolyVox for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++) { // these are always positive anyway - uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); - uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); - uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ(); + float regX = static_cast(x - m_regSizeInVoxels.getLowerCorner().getX()); + float regY = static_cast(y - m_regSizeInVoxels.getLowerCorner().getY()); + float regZ = static_cast(z - m_regSizeInVoxels.getLowerCorner().getZ()); int currentVoxel = m_volData->getVoxelAt(x,y,z).getDensity() >= VoxelType::getThreshold(); int plusXVoxel = m_volData->getVoxelAt(x+1,y,z).getDensity() >= VoxelType::getThreshold(); if(currentVoxel > plusXVoxel) { - uint32_t material = m_volData->getVoxelAt(x,y,z).getMaterial(); + float material = static_cast(m_volData->getVoxelAt(x,y,z).getMaterial()); uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), material)); @@ -65,7 +65,7 @@ namespace PolyVox } if(currentVoxel < plusXVoxel) { - int material = m_volData->getVoxelAt(x+1,y,z).getMaterial(); + float material = static_cast(m_volData->getVoxelAt(x+1,y,z).getMaterial()); uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), material)); @@ -79,7 +79,7 @@ namespace PolyVox int plusYVoxel = m_volData->getVoxelAt(x,y+1,z).getDensity() >= VoxelType::getThreshold(); if(currentVoxel > plusYVoxel) { - int material = m_volData->getVoxelAt(x,y,z).getMaterial(); + float material = static_cast(m_volData->getVoxelAt(x,y,z).getMaterial()); uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), material)); @@ -91,7 +91,7 @@ namespace PolyVox } if(currentVoxel < plusYVoxel) { - int material = m_volData->getVoxelAt(x,y+1,z).getMaterial(); + float material = static_cast(m_volData->getVoxelAt(x,y+1,z).getMaterial()); uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), material)); @@ -105,7 +105,7 @@ namespace PolyVox int plusZVoxel = m_volData->getVoxelAt(x,y,z+1).getDensity() >= VoxelType::getThreshold(); if(currentVoxel > plusZVoxel) { - int material = m_volData->getVoxelAt(x,y,z).getMaterial(); + float material = static_cast(m_volData->getVoxelAt(x,y,z).getMaterial()); uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), material)); @@ -117,7 +117,7 @@ namespace PolyVox } if(currentVoxel < plusZVoxel) { - int material = m_volData->getVoxelAt(x,y,z+1).getMaterial(); + float material = static_cast(m_volData->getVoxelAt(x,y,z+1).getMaterial()); uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), material)); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), material)); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h index c0833d5a..bd1e93b5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h @@ -93,11 +93,6 @@ namespace PolyVox std::vector m_vecVertices; std::vector m_vecLodRecords; - - //The set of materials which are in this mesh. Only those materials - //which cover a whole triangle are counted. Materials which only - //exist on a material boundary do not count. - std::set m_mapUsedMaterials; }; template diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl index 83fc97ab..f21ad6b0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl @@ -103,11 +103,6 @@ namespace PolyVox m_vecTriangleIndices.push_back(index0); m_vecTriangleIndices.push_back(index1); m_vecTriangleIndices.push_back(index2); - - if((m_vecVertices[index0].material == m_vecVertices[index1].material) && (m_vecVertices[index0].material == m_vecVertices[index2].material)) - { - m_mapUsedMaterials.insert(m_vecVertices[index0].material); - } } template @@ -131,7 +126,6 @@ namespace PolyVox m_vecVertices.clear(); m_vecTriangleIndices.clear(); m_vecLodRecords.clear(); - m_mapUsedMaterials.clear(); } template From b972a2ceaf790d9b625f6f5d1e0a696f4f4d6eef Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 30 Nov 2011 22:50:52 +0000 Subject: [PATCH 2/6] Exposed DensityType and MaterialType on voxels. --- .../PolyVoxCore/include/PolyVoxCore/Density.h | 15 ++++++++--- .../include/PolyVoxCore/Material.h | 19 +++++++++----- .../include/PolyVoxCore/MaterialDensityPair.h | 25 ++++++++++++------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 82aab7b4..308310bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -39,14 +39,21 @@ namespace PolyVox /// funtion is used to determine what material should be assigned to the resulting mesh. /// /// This class meets these requirements, although it only actually stores a density value. - /// For the getMaterial() function it just returens a constant value of '1'. + /// For the getMaterial() function it just returns a constant value of '1'. /// /// \sa Material, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// - template + template class Density { public: + //We expose DensityType and MaterialType in this way so that, when code is + //templatised on voxel type, it can determine the underlying storage type + //using code such as 'VoxelType::DensityType value = voxel.getDensity()' + //or 'VoxelType::MaterialType value = voxel.getMaterial()'. + typedef Type DensityType; + typedef uint8_t MaterialType; + Density() : m_uDensity(0) {} Density(DensityType uDensity) : m_uDensity(uDensity) {} @@ -61,10 +68,10 @@ namespace PolyVox } DensityType getDensity() const throw() { return m_uDensity; } - uint32_t getMaterial() const throw() { return 1; } + MaterialType getMaterial() const throw() { return 1; } void setDensity(DensityType uDensity) { m_uDensity = uDensity; } - void setMaterial(uint32_t uMaterial) { assert(false); } //Cannot set material on voxel of type Density + void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density static DensityType getMaxDensity() throw() { return (std::numeric_limits::max)(); } static DensityType getMinDensity() throw() { return (std::numeric_limits::min)(); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 09d978e9..390dfd71 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -43,10 +43,17 @@ namespace PolyVox /// /// \sa Density, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// - template + template class Material { public: + //We expose DensityType and MaterialType in this way so that, when code is + //templatised on voxel type, it can determine the underlying storage type + //using code such as 'VoxelType::DensityType value = voxel.getDensity()' + //or 'VoxelType::MaterialType value = voxel.getMaterial()'. + typedef uint8_t DensityType; + typedef Type MaterialType; + Material() : m_uMaterial(0) {} Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {} @@ -60,7 +67,7 @@ namespace PolyVox return !(*this == rhs); } - uint32_t getDensity() const throw() + DensityType getDensity() const throw() { //We don't actually have a density, so make one up based on the material. if(m_uMaterial == 0) @@ -75,12 +82,12 @@ namespace PolyVox MaterialType getMaterial() const throw() { return m_uMaterial; } - void setDensity(uint32_t /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material + void setDensity(DensityType /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } - static uint32_t getMaxDensity() throw() { return 2; } - static uint32_t getMinDensity() throw() { return 0; } - static uint32_t getThreshold() throw() { return 1; } + static DensityType getMaxDensity() throw() { return 2; } + static DensityType getMinDensity() throw() { return 0; } + static DensityType getThreshold() throw() { return 1; } private: MaterialType m_uMaterial; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 1bb3a31f..663eded5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -46,6 +46,13 @@ namespace PolyVox class MaterialDensityPair { public: + //We expose DensityType and MaterialType in this way so that, when code is + //templatised on voxel type, it can determine the underlying storage type + //using code such as 'VoxelType::DensityType value = voxel.getDensity()' + //or 'VoxelType::MaterialType value = voxel.getMaterial()'. + typedef Type DensityType; + typedef Type MaterialType; + MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {} MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {} @@ -59,19 +66,19 @@ namespace PolyVox return !(*this == rhs); } - Type getDensity() const throw() { return m_uDensity; } - Type getMaterial() const throw() { return m_uMaterial; } + DensityType getDensity() const throw() { return m_uDensity; } + MaterialType getMaterial() const throw() { return m_uMaterial; } - void setDensity(Type uDensity) { m_uDensity = uDensity; } - void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } + void setDensity(DensityType uDensity) { m_uDensity = uDensity; } + void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } - static Type getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } - static Type getMinDensity() throw() { return 0; } - static Type getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);} + static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } + static DensityType getMinDensity() throw() { return 0; } + static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);} private: - Type m_uMaterial : NoOfMaterialBits; - Type m_uDensity : NoOfDensityBits; + MaterialType m_uMaterial : NoOfMaterialBits; + DensityType m_uDensity : NoOfDensityBits; }; typedef MaterialDensityPair MaterialDensityPair44; From d5d6319087191a60bce090747d0c4b20e634f328 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 3 Dec 2011 09:43:27 +0000 Subject: [PATCH 3/6] Fixes to behavour of LowPassFilter. --- .../include/PolyVoxCore/LowPassFilter.inl | 50 ++++++++++--------- tests/TestLowPassFilter.cpp | 26 ++++++++-- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 9e6bc66d..c5ad68b6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -118,14 +118,18 @@ namespace PolyVox template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> void LowPassFilter::executeSAT() { - const int border = m_uKernelSize - 1; + const uint32_t border = (m_uKernelSize - 1) / 2; - Vector3DInt32 satLowerCorner = m_regSrc.getLowerCorner() - Vector3DInt32(border+1, border+1, border+1); + Vector3DInt32 satLowerCorner = m_regSrc.getLowerCorner() - Vector3DInt32(border, border, border); Vector3DInt32 satUpperCorner = m_regSrc.getUpperCorner() + Vector3DInt32(border, border, border); - RawVolume satVolume(Region(satLowerCorner, satUpperCorner)); + //Use floats for the SAT volume to ensure it works with negative + //densities and with both integral and floating point input volumes. + RawVolume satVolume(Region(satLowerCorner, satUpperCorner)); //Clear to zeros (necessary?) + //FIXME - use Volume::fill() method. Implemented in base class as below + //but with optimised implementations in subclasses? for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) @@ -137,9 +141,9 @@ namespace PolyVox } } - RawVolume::Sampler satVolumeIter(&satVolume); + RawVolume::Sampler satVolumeIter(&satVolume); - IteratorController::Sampler> satIterCont; + IteratorController::Sampler> satIterCont; satIterCont.m_regValid = Region(satLowerCorner, satUpperCorner); satIterCont.m_Iter = &satVolumeIter; satIterCont.reset(); @@ -153,9 +157,9 @@ namespace PolyVox do { - uint32_t previousSum = satVolumeIter.peekVoxel1nx0py0pz(); + float previousSum = satVolumeIter.peekVoxel1nx0py0pz(); - uint32_t currentVal = srcVolumeIter.getVoxel().getDensity(); + float currentVal = static_cast(srcVolumeIter.getVoxel().getDensity()); satVolumeIter.setVoxel(previousSum + currentVal); @@ -184,8 +188,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - uint32_t previousSum = satVolume.getVoxelAt(x,y-1,z); - uint32_t currentSum = satVolume.getVoxelAt(x,y,z); + float previousSum = satVolume.getVoxelAt(x,y-1,z); + float currentSum = satVolume.getVoxelAt(x,y,z); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -198,8 +202,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - uint32_t previousSum = satVolume.getVoxelAt(x,y,z-1); - uint32_t currentSum = satVolume.getVoxelAt(x,y,z); + float previousSum = satVolume.getVoxelAt(x,y,z-1); + float currentSum = satVolume.getVoxelAt(x,y,z); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -227,24 +231,24 @@ namespace PolyVox int32_t satUpperY = iSrcY + border; int32_t satUpperZ = iSrcZ + border; - int32_t a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ); - int32_t b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ); - int32_t c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ); - int32_t d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ); - int32_t e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ); - int32_t f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ); - int32_t g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ); - int32_t h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); + float a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ); + float b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ); + float c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ); + float d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ); + float e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ); + float f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ); + float g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ); + float h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); - int32_t sum = h+c-d-g-f-a+b+e; + float sum = h+c-d-g-f-a+b+e; - int32_t sideLength = border * 2 + 1; + uint32_t sideLength = border * 2 + 1; - int32_t average = sum / (sideLength*sideLength*sideLength); + float average = sum / (static_cast(sideLength*sideLength*sideLength)); VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ); - voxel.setDensity(average); + voxel.setDensity(static_cast(average)); m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, voxel); diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp index f4129253..474e5021 100644 --- a/tests/TestLowPassFilter.cpp +++ b/tests/TestLowPassFilter.cpp @@ -33,7 +33,7 @@ using namespace PolyVox; void TestLowPassFilter::testExecute() { - const int32_t g_uVolumeSideLength = 16; + const int32_t g_uVolumeSideLength = 8; Region reg(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)); @@ -60,11 +60,27 @@ void TestLowPassFilter::testExecute() LowPassFilter pass1(&volData, reg, &resultVolume, reg, 5); - pass1.executeSAT(); + pass1.execute(); - std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(1,2,3).getDensity()) << std::endl; // 7 - std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(10,6,7).getDensity()) << std::endl; // 17 - std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(15,2,12).getDensity()) << std::endl; // 4 + std::cout << "Input volume:" << std::endl; + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(0,0,0).getDensity()) << std::endl; // 32 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(1,1,1).getDensity()) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(2,2,2).getDensity()) << std::endl; // 3 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(3,3,3).getDensity()) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(4,4,4).getDensity()) << std::endl; // 32 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(5,5,5).getDensity()) << std::endl; // 0 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(6,6,6).getDensity()) << std::endl; // 32 + std::cout << "Voxel = " << static_cast(volData.getVoxelAt(7,7,7).getDensity()) << std::endl; // 0 + + std::cout << std::endl << "Output volume:" << std::endl; + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(0,0,0).getDensity()) << std::endl; // 4 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(1,1,1).getDensity()) << std::endl; // 21 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(2,2,2).getDensity()) << std::endl; // 10 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(3,3,3).getDensity()) << std::endl; // 21 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(4,4,4).getDensity()) << std::endl; // 10 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(5,5,5).getDensity()) << std::endl; // 21 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(6,6,6).getDensity()) << std::endl; // 10 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(7,7,7).getDensity()) << std::endl; // 4 } QTEST_MAIN(TestLowPassFilter) From 7b126a97f7222b6234bfb447dbee737a28dec2ed Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 9 Dec 2011 17:27:52 +0100 Subject: [PATCH 4/6] GCC compile fix. --- library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index c5ad68b6..e5c4c261 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -248,7 +248,7 @@ namespace PolyVox VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ); - voxel.setDensity(static_cast(average)); + voxel.setDensity(static_cast(average)); m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, voxel); From 906300acb3a8f0618e422ea656b7ff254818e6d6 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 11 Dec 2011 15:26:48 +0000 Subject: [PATCH 5/6] Fix for bug with material ORing creating a new material. http://www.volumesoffun.com/phpBB3/viewtopic.php?f=15&t=297 --- .../include/PolyVoxCore/SurfaceExtractor.inl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index 1f449cd6..456be614 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -442,7 +442,10 @@ namespace PolyVox Vector3DFloat v3dNormal = (n100*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); - const uint32_t uMaterial = v000.getMaterial() | v100.getMaterial(); //Because one of these is 0, the or operation takes the max. + //Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of + //material IDs does not make sense). We take the largest, so that if we are working on a material-only + //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. + const uint32_t uMaterial = (std::max)(v000.getMaterial(), v100.getMaterial()); PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); @@ -465,7 +468,10 @@ namespace PolyVox Vector3DFloat v3dNormal = (n010*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); - const uint32_t uMaterial = v000.getMaterial() | v010.getMaterial(); //Because one of these is 0, the or operation takes the max. + //Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of + //material IDs does not make sense). We take the largest, so that if we are working on a material-only + //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. + const uint32_t uMaterial = (std::max)(v000.getMaterial(), v010.getMaterial()); PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); @@ -488,7 +494,10 @@ namespace PolyVox Vector3DFloat v3dNormal = (n001*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); - const uint32_t uMaterial = v000.getMaterial() | v001.getMaterial(); //Because one of these is 0, the or operation takes the max. + //Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of + //material IDs does not make sense). We take the largest, so that if we are working on a material-only + //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. + const uint32_t uMaterial = (std::max)(v000.getMaterial(), v001.getMaterial()); PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); From 2e4bf674e8d12795cd4c2187eafa3a4a375049a1 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 11 Dec 2011 16:27:59 +0000 Subject: [PATCH 6/6] Removed incorrect asserts. --- library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h index c8e33588..699edd43 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h @@ -64,15 +64,11 @@ namespace PolyVox :m_pVolume(pVolume) ,m_regValid(regValid) { - //Should never get here as it's a private constructor - assert(false); } //Private assignment operator, so client code can't abuse this class. ConstVolumeProxy& operator=(const ConstVolumeProxy& rhs) throw() { - //Should never get here as it's a private assignment operator - assert(false); } const LargeVolume& m_pVolume;