From 617834bed44257b6f203fbaeba2a035775c1e528 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 17 May 2013 14:32:20 +0200 Subject: [PATCH 01/64] Made getVoxel() bounds checking optional, based on a function parameter. --- .../include/PolyVoxCore/BaseVolume.h | 4 ++-- .../include/PolyVoxCore/BaseVolume.inl | 4 ++-- .../include/PolyVoxCore/LargeVolume.h | 4 ++-- .../include/PolyVoxCore/LargeVolume.inl | 17 ++++++++++++----- .../PolyVoxCore/include/PolyVoxCore/RawVolume.h | 4 ++-- .../include/PolyVoxCore/RawVolume.inl | 17 ++++++++++++----- .../include/PolyVoxCore/SimpleVolume.h | 4 ++-- .../include/PolyVoxCore/SimpleVolume.inl | 17 ++++++++++++----- 8 files changed, 46 insertions(+), 25 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 04d70756..4eeb5c62 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -147,9 +147,9 @@ namespace PolyVox /// Gets the length of the diagonal in voxels float getDiagonalLength(void) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 2103726d..b4237b18 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -160,7 +160,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/) const + VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, bool /*bPerformBoundsChecks*/) const { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); return VoxelType(); @@ -171,7 +171,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/) const + VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, bool /*bPerformBoundsChecks*/) const { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); return VoxelType(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 2be3f87d..ca4a8bb4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -266,9 +266,9 @@ namespace PolyVox ~LargeVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 76d4049a..0f2826b6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -122,10 +122,17 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); + // If bounds checking is enabled then we validate the + // bounds, and throw an exception if they are violated. + if(bPerformBoundsChecks) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + } const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; @@ -145,9 +152,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos) const + VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index e4549e1f..f50087a7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -116,9 +116,9 @@ namespace PolyVox ~RawVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index c6face08..668ad929 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -80,10 +80,17 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); + // If bounds checking is enabled then we validate the + // bounds, and throw an exception if they are violated. + if(bPerformBoundsChecks) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + } const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); @@ -103,9 +110,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos) const + VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 8ce2083e..7b4b11b0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -155,9 +155,9 @@ namespace PolyVox ~SimpleVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 573f3c83..13fdfae9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -80,10 +80,17 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); + // If bounds checking is enabled then we validate the + // bounds, and throw an exception if they are violated. + if(bPerformBoundsChecks) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + } const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; @@ -103,9 +110,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos) const + VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks); } //////////////////////////////////////////////////////////////////////////////// From 4765390ef6e9715327eb3c2d1030c1957c1b162d Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 17 May 2013 14:51:14 +0200 Subject: [PATCH 02/64] Replaced bool parameter with 'BoundsCheck' parameter for a nicer API. --- .../PolyVoxCore/include/PolyVoxCore/BaseVolume.h | 14 ++++++++++++-- .../PolyVoxCore/include/PolyVoxCore/BaseVolume.inl | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/LargeVolume.h | 4 ++-- .../include/PolyVoxCore/LargeVolume.inl | 8 ++++---- .../PolyVoxCore/include/PolyVoxCore/RawVolume.h | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 8 ++++---- .../PolyVoxCore/include/PolyVoxCore/SimpleVolume.h | 4 ++-- .../include/PolyVoxCore/SimpleVolume.inl | 8 ++++---- 8 files changed, 32 insertions(+), 22 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 4eeb5c62..6965fb0e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -36,6 +36,16 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// More details to come... //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + namespace BoundsChecks + { + enum BoundsCheck + { + None = 0, + Full = 1 + }; + } + typedef BoundsChecks::BoundsCheck BoundsCheck; + namespace WrapModes { enum WrapMode @@ -147,9 +157,9 @@ namespace PolyVox /// Gets the length of the diagonal in voxels float getDiagonalLength(void) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index b4237b18..0b24643a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -160,7 +160,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, bool /*bPerformBoundsChecks*/) const + VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, BoundsCheck /*eBoundsCheck*/) const { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); return VoxelType(); @@ -171,7 +171,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, bool /*bPerformBoundsChecks*/) const + VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, BoundsCheck /*eBoundsCheck*/) const { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); return VoxelType(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index ca4a8bb4..6dd7afab 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -266,9 +266,9 @@ namespace PolyVox ~LargeVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 0f2826b6..178218b7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -122,11 +122,11 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const + VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck) const { // If bounds checking is enabled then we validate the // bounds, and throw an exception if they are violated. - if(bPerformBoundsChecks) + if(eBoundsCheck == BoundsChecks::Full) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -152,9 +152,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const + VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index f50087a7..2a85248a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -116,9 +116,9 @@ namespace PolyVox ~RawVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 668ad929..2867ca92 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -80,11 +80,11 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck) const { // If bounds checking is enabled then we validate the // bounds, and throw an exception if they are violated. - if(bPerformBoundsChecks) + if(eBoundsCheck == BoundsChecks::Full) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -110,9 +110,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const + VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 7b4b11b0..3ddd628a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -155,9 +155,9 @@ namespace PolyVox ~SimpleVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks = true) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 13fdfae9..256b26b9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -80,11 +80,11 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, bool bPerformBoundsChecks) const + VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck) const { // If bounds checking is enabled then we validate the // bounds, and throw an exception if they are violated. - if(bPerformBoundsChecks) + if(eBoundsCheck == BoundsChecks::Full) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -110,9 +110,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, bool bPerformBoundsChecks) const + VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), bPerformBoundsChecks); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck); } //////////////////////////////////////////////////////////////////////////////// From fa8e7c390fd3adf3b0f6e156eebe7537b50ffbc4 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 17 May 2013 15:52:18 +0200 Subject: [PATCH 03/64] replaced 'getVoxelWithWrapping()' with regular 'getVoxel()', as they can be differentiated by their parameters. --- .../include/PolyVoxCore/BaseVolume.h | 4 +- .../include/PolyVoxCore/BaseVolume.inl | 4 +- .../CubicSurfaceExtractorWithNormals.inl | 12 ++--- .../include/PolyVoxCore/LargeVolume.h | 4 +- .../include/PolyVoxCore/LargeVolume.inl | 6 +-- .../PolyVoxCore/LargeVolumeSampler.inl | 54 +++++++++---------- .../include/PolyVoxCore/RawVolume.h | 4 +- .../include/PolyVoxCore/RawVolume.inl | 6 +-- .../include/PolyVoxCore/RawVolumeSampler.inl | 54 +++++++++---------- .../include/PolyVoxCore/SimpleVolume.h | 4 +- .../include/PolyVoxCore/SimpleVolume.inl | 6 +-- .../PolyVoxCore/SimpleVolumeSampler.inl | 54 +++++++++---------- tests/testvolume.cpp | 4 +- 13 files changed, 108 insertions(+), 108 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 6965fb0e..d188f8ac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -165,9 +165,9 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 0b24643a..dfe0fbb7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -208,7 +208,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxelWithWrapping(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const + VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); return VoxelType(); @@ -219,7 +219,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxelWithWrapping(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const + VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); return VoxelType(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index dca5f911..3956858c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -53,7 +53,7 @@ namespace PolyVox uint32_t material = 0; - if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x+1,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(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), static_cast(material))); @@ -63,7 +63,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v2,v1); m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(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), static_cast(material))); @@ -74,7 +74,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v3,v2); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y+1,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(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), static_cast(material))); @@ -84,7 +84,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v1,v2); m_meshCurrent->addTriangleCubic(v1,v3,v2); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(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), static_cast(material))); @@ -95,7 +95,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z+1,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(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), static_cast(material))); @@ -105,7 +105,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v2,v1); m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxel(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxel(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(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), static_cast(material))); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 6dd7afab..9d4acba4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -274,9 +274,9 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the number of blocks for which uncompressed data is stored void setMaxNumberOfUncompressedBlocks(uint32_t uMaxNumberOfUncompressedBlocks); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 178218b7..1b5bdb15 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -203,7 +203,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const + VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const { switch(eWrapMode) { @@ -247,9 +247,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const + VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const { - return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 9c05bc9d..11e916e2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -286,7 +286,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -296,7 +296,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -306,7 +306,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -316,7 +316,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -326,7 +326,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -336,7 +336,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -346,7 +346,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -356,7 +356,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -366,7 +366,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } ////////////////////////////////////////////////////////////////////////// @@ -378,7 +378,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -388,7 +388,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -398,7 +398,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -408,7 +408,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -418,7 +418,7 @@ namespace PolyVox { return *mCurrentVoxel; } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -428,7 +428,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -438,7 +438,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -448,7 +448,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -458,7 +458,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } ////////////////////////////////////////////////////////////////////////// @@ -470,7 +470,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -480,7 +480,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -490,7 +490,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -500,7 +500,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -510,7 +510,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -520,7 +520,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -530,7 +530,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -540,7 +540,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -550,7 +550,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 2a85248a..165b6ba4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -124,9 +124,9 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 2867ca92..f09e76de 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -161,7 +161,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const { switch(eWrapMode) { @@ -205,9 +205,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const + VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const { - return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 3124e4c8..08ce94e8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -229,7 +229,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -239,7 +239,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->getWidth()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -249,7 +249,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -259,7 +259,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -269,7 +269,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -279,7 +279,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -289,7 +289,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -299,7 +299,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->getWidth()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -309,7 +309,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } ////////////////////////////////////////////////////////////////////////// @@ -321,7 +321,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -331,7 +331,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->getWidth()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -341,7 +341,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -351,7 +351,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -361,7 +361,7 @@ namespace PolyVox { return *mCurrentVoxel; } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -371,7 +371,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -381,7 +381,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -391,7 +391,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->getWidth()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -401,7 +401,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } ////////////////////////////////////////////////////////////////////////// @@ -413,7 +413,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -423,7 +423,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->getWidth()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -433,7 +433,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -443,7 +443,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -453,7 +453,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -463,7 +463,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -473,7 +473,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -483,7 +483,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->getWidth()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -493,7 +493,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->getWidth() + this->mVolume->getWidth() * this->mVolume->getHeight()); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 3ddd628a..0abd3b30 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -163,9 +163,9 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Border, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 256b26b9..5a9c8f00 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -161,7 +161,7 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxelWithWrapping(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const + VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const { switch(eWrapMode) { @@ -205,9 +205,9 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxelWithWrapping(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const + VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const { - return getVoxelWithWrapping(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 117651a4..477eb2da 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -305,7 +305,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -315,7 +315,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -325,7 +325,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -335,7 +335,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -345,7 +345,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -355,7 +355,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -365,7 +365,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -375,7 +375,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -385,7 +385,7 @@ namespace PolyVox { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } ////////////////////////////////////////////////////////////////////////// @@ -397,7 +397,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -407,7 +407,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -417,7 +417,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -427,7 +427,7 @@ namespace PolyVox { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -437,7 +437,7 @@ namespace PolyVox { return *mCurrentVoxel; } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -447,7 +447,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -457,7 +457,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -467,7 +467,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -477,7 +477,7 @@ namespace PolyVox { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } ////////////////////////////////////////////////////////////////////////// @@ -489,7 +489,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -499,7 +499,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -509,7 +509,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -519,7 +519,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -529,7 +529,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -539,7 +539,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } template @@ -549,7 +549,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1,this->m_eWrapMode, this->m_tBorder); } template @@ -559,7 +559,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume,this->m_eWrapMode, this->m_tBorder); } template @@ -569,7 +569,7 @@ namespace PolyVox { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return this->mVolume->getVoxelWithWrapping(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); + return this->mVolume->getVoxel(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1,this->m_eWrapMode, this->m_tBorder); } } diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 2bd15cbd..dd000a88 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -76,7 +76,7 @@ int32_t testDirectAccessWithWrappingForwards(const VolumeType* volume, int lowXO } else { - result = cantorTupleFunction(result, volume->getVoxelWithWrapping(x + innerX, y + innerY, z + innerZ, WrapModes::Border, 3)); + result = cantorTupleFunction(result, volume->getVoxel(x + innerX, y + innerY, z + innerZ, WrapModes::Border, 3)); } } } @@ -189,7 +189,7 @@ int32_t testDirectAccessWithWrappingBackwards(const VolumeType* volume, int lowX } else { - result = cantorTupleFunction(result, volume->getVoxelWithWrapping(x + innerX, y + innerY, z + innerZ, WrapModes::Border, 3)); + result = cantorTupleFunction(result, volume->getVoxel(x + innerX, y + innerY, z + innerZ, WrapModes::Border, 3)); } } } From ea4d6d31683c22fc351a1922a44363b6ec33e465 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 17 May 2013 16:36:04 +0200 Subject: [PATCH 04/64] Added setVoxel() functions to replace setVoxelAt() functions in the same way that getVoxel() replaces getVoxelAt(). --- .../include/PolyVoxCore/BaseVolume.h | 4 ++ .../include/PolyVoxCore/BaseVolume.inl | 26 +++++++++++ .../include/PolyVoxCore/LargeVolume.h | 4 ++ .../include/PolyVoxCore/LargeVolume.inl | 44 +++++++++++++++++++ .../include/PolyVoxCore/RawVolume.h | 4 ++ .../include/PolyVoxCore/RawVolume.inl | 44 +++++++++++++++++++ .../include/PolyVoxCore/SimpleVolume.h | 4 ++ .../include/PolyVoxCore/SimpleVolume.inl | 44 +++++++++++++++++++ 8 files changed, 174 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index d188f8ac..30c34584 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -172,6 +172,10 @@ namespace PolyVox /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); /// Sets the voxel at the position given by x,y,z coordinates + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + /// Sets the voxel at the position given by a 3D vector + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index dfe0fbb7..87dfc1fe 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -234,6 +234,32 @@ namespace PolyVox m_tBorderValue = tBorder; } + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos the \c x position of the voxel + /// \param uYPos the \c y position of the voxel + /// \param uZPos the \c z position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void BaseVolume::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) + { + POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos the 3D position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void BaseVolume::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) + { + POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); + return false; + } + //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 9d4acba4..0ce3bfc7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -283,6 +283,10 @@ namespace PolyVox /// Sets the number of blocks which can be in memory before the paging system starts unloading them void setMaxNumberOfBlocksInMemory(uint32_t uMaxNumberOfBlocksInMemory); /// Sets the voxel at the position given by x,y,z coordinates + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + /// Sets the voxel at the position given by a 3D vector + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 1b5bdb15..9f2c4119 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -280,6 +280,50 @@ namespace PolyVox m_uMaxNumberOfBlocksInMemory = uMaxNumberOfBlocksInMemory; } + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos the \c x position of the voxel + /// \param uYPos the \c y position of the voxel + /// \param uZPos the \c z position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void LargeVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) + { + // If bounds checking is enabled then we validate the + // bounds, and throw an exception if they are violated. + if(eBoundsCheck == BoundsChecks::Full) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + } + + const int32_t blockX = uXPos >> m_uBlockSideLengthPower; + const int32_t blockY = uYPos >> m_uBlockSideLengthPower; + const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; + + const uint16_t xOffset = static_cast(uXPos - (blockX << m_uBlockSideLengthPower)); + const uint16_t yOffset = static_cast(uYPos - (blockY << m_uBlockSideLengthPower)); + const uint16_t zOffset = static_cast(uZPos - (blockZ << m_uBlockSideLengthPower)); + + Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); + + pUncompressedBlock->setVoxelAt(xOffset,yOffset,zOffset, tValue); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos the 3D position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void LargeVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) + { + setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); + } + //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 165b6ba4..95a770b9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -128,6 +128,10 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; + /// Sets the voxel at the position given by x,y,z coordinates + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + /// Sets the voxel at the position given by a 3D vector + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index f09e76de..b7029dcf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -210,6 +210,50 @@ namespace PolyVox return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos the \c x position of the voxel + /// \param uYPos the \c y position of the voxel + /// \param uZPos the \c z position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void RawVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) + { + // If bounds checking is enabled then we validate the + // bounds, and throw an exception if they are violated. + if(eBoundsCheck == BoundsChecks::Full) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + } + + const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); + int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); + int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); + int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); + + m_pData + [ + iLocalXPos + + iLocalYPos * this->getWidth() + + iLocalZPos * this->getWidth() * this->getHeight() + ] = tValue; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos the 3D position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void RawVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) + { + setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); + } + //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 0abd3b30..2bd0a366 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -167,6 +167,10 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; + /// Sets the voxel at the position given by x,y,z coordinates + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + /// Sets the voxel at the position given by a 3D vector + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 5a9c8f00..7403dc74 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -210,6 +210,50 @@ namespace PolyVox return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos the \c x position of the voxel + /// \param uYPos the \c y position of the voxel + /// \param uZPos the \c z position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void SimpleVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) + { + // If bounds checking is enabled then we validate the + // bounds, and throw an exception if they are violated. + if(eBoundsCheck == BoundsChecks::Full) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + } + + const int32_t blockX = uXPos >> m_uBlockSideLengthPower; + const int32_t blockY = uYPos >> m_uBlockSideLengthPower; + const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; + + const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower); + const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower); + const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower); + + typename SimpleVolume::Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); + + pUncompressedBlock->setVoxelAt(xOffset,yOffset,zOffset, tValue); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos the 3D position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + void SimpleVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) + { + setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); + } + //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel From efd487845093b535e69e1fba1a5ddb83b781aa8d Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 17 May 2013 16:44:32 +0200 Subject: [PATCH 05/64] Updated documentation. --- .../PolyVoxCore/include/PolyVoxCore/BaseVolume.inl | 14 ++++++++++++-- .../include/PolyVoxCore/LargeVolume.inl | 14 ++++++++++++-- .../PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 14 ++++++++++++-- .../include/PolyVoxCore/SimpleVolume.inl | 14 ++++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 87dfc1fe..c9fc1fcb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -181,6 +181,9 @@ namespace PolyVox /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -192,6 +195,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos The 3D position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -239,7 +245,9 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void BaseVolume::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) @@ -251,7 +259,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void BaseVolume::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 9f2c4119..7ecd5192 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -119,6 +119,9 @@ namespace PolyVox /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -149,6 +152,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos The 3D position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -285,7 +291,9 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void LargeVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) @@ -316,7 +324,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void LargeVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index b7029dcf..42b618a0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -77,6 +77,9 @@ namespace PolyVox /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -108,6 +111,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos The 3D position of the voxel /// \return The voxel value + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const @@ -215,7 +221,9 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void RawVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) @@ -246,7 +254,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void RawVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 7403dc74..71e8e902 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -77,6 +77,9 @@ namespace PolyVox /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -107,6 +110,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos The 3D position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -215,7 +221,9 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void SimpleVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) @@ -246,7 +254,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \return whether the requested position is inside the volume + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template void SimpleVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) From a56005478d7f400302e8ab43b54da74b14793959 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Mon, 27 May 2013 12:59:19 +0200 Subject: [PATCH 06/64] Fix for Linux compile error. --- library/PolyVoxCore/source/Impl/ErrorHandling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp index baeae6be..18653a6b 100644 --- a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp +++ b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp @@ -32,7 +32,7 @@ namespace PolyVox { // Passing zero to the stream constructor guarentees it will discard all input. See // here http://stackoverflow.com/a/8244052 and here http://stackoverflow.com/a/6240980 - static std::ostream s_NullStream = std::ostream(0); + static std::ostream s_NullStream(0); return &s_NullStream; } From 869f5f6c49a44dec7c9cb0fc90a67f46a21e58c2 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Mon, 27 May 2013 14:01:55 +0200 Subject: [PATCH 07/64] Added function to check whether one region is inside of another. --- .../PolyVoxCore/include/PolyVoxCore/Region.h | 3 +++ library/PolyVoxCore/source/Region.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 55c51ee4..655b3bce 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -149,6 +149,9 @@ namespace PolyVox /// Tests whether the given position is contained in the 'z' range of this Region. bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const; + /// Tests whether the given Region is contained in this Region. + bool containsRegion(const Region& reg, uint8_t boundary = 0) const; + /// Enlarges the Region so that it contains the specified position. void accumulate(int32_t iX, int32_t iY, int32_t iZ); /// Enlarges the Region so that it contains the specified position. diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 3db2edd6..444a1770 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -301,6 +301,23 @@ namespace PolyVox && (pos >= m_iLowerZ + boundary); } + /** + * The boundary value can be used to ensure a region is only considered to be inside + * another Region if it is that far in in all directions. Also, the test is inclusive such + * that a region is considered to be inside of itself. + * \param reg The region to test. + * \param boundary The desired boundary value. + */ + bool Region::containsRegion(const Region& reg, uint8_t boundary) const + { + return (reg.m_iUpperX <= m_iUpperX - boundary) + && (reg.m_iUpperY <= m_iUpperY - boundary) + && (reg.m_iUpperZ <= m_iUpperZ - boundary) + && (reg.m_iLowerX >= m_iLowerX + boundary) + && (reg.m_iLowerY >= m_iLowerY + boundary) + && (reg.m_iLowerZ >= m_iLowerZ + boundary); + } + /** * After calling this functions, the extents of this Region are given by the intersection * of this Region and the one it was cropped to. From 0c7002a1cef8b153b779327d0343204717f3428a Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Mon, 27 May 2013 14:24:52 +0200 Subject: [PATCH 08/64] Avoided double bounds check. --- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 3c857875..0bc880ef 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -224,14 +224,14 @@ namespace PolyVox uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos); + return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. //No need to break as we've returned } case WrapModes::Border: { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxel(uXPos, uYPos, uZPos); + return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. } else { diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 2f421724..39e51690 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -182,14 +182,14 @@ namespace PolyVox uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos); + return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. //No need to break as we've returned } case WrapModes::Border: { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxel(uXPos, uYPos, uZPos); + return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. } else { diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index faac1268..b17bf517 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -182,14 +182,14 @@ namespace PolyVox uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos); + return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. //No need to break as we've returned } case WrapModes::Border: { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxel(uXPos, uYPos, uZPos); + return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. } else { From de8c69456fe1d4994ee9ff79b91b688335386129 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Mon, 27 May 2013 15:09:43 +0200 Subject: [PATCH 09/64] Added macro to throw an exception but not log it. Useful in some high-performance scenarios. --- .../include/PolyVoxCore/BaseVolumeSampler.inl | 4 ++-- .../include/PolyVoxCore/Impl/ErrorHandling.h | 13 +++++++++++++ .../PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 4 ++-- .../include/PolyVoxCore/SimpleVolume.inl | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index 1e67a020..aabf0287 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -374,8 +374,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 847ae008..5080f7db 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -258,6 +258,12 @@ namespace PolyVox #define POLYVOX_THROW(type, message) \ PolyVox::logError() << (message); \ throw type((message)) + + // Some fast functions (getVoxel(), etc) use exceptions for error handling but don't want the overhead of logging. + // This overhead is present even if no exception is thrown, probably because the presence of the logging code prevents + // some inlining. Therefore we provide this macro which doesn't log for such specialised circumstances. + #define POLYVOX_THROW_DONT_LOG(type, message) \ + throw type((message)) #else namespace PolyVox { @@ -271,6 +277,13 @@ namespace PolyVox PolyVox::logError() << (message); \ type except = (type)((message)); \ getThrowHandler()((except), __FILE__, __LINE__) + + // Some fast functions (getVoxel(), etc) use exceptions for error handling but don't want the overhead of logging. + // This overhead is present even if no exception is thrown, probably because the presence of the logging code prevents + // some inlining. Therefore we provide this macro which doesn't log for such specialised circumstances. + #define POLYVOX_THROW_DONT_LOG(type, message) \ + type except = (type)((message)); \ + getThrowHandler()((except), __FILE__, __LINE__) #endif namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 0bc880ef..a0c778f6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -241,8 +241,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 39e51690..5614650d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -199,8 +199,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index b17bf517..7f5ff9d6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -199,8 +199,8 @@ namespace PolyVox } default: { - //Should never happen - POLYVOX_THROW(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. We don't log because this hurts performance (preventing inlining?). + POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); } } } From 073c415a3885f5ad774f2ad9176138740482639d Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 29 May 2013 16:07:27 +0200 Subject: [PATCH 10/64] Work on new getVoxel() functions. --- .../include/PolyVoxCore/BaseVolume.h | 2 + .../include/PolyVoxCore/BaseVolumeSampler.inl | 5 +- .../include/PolyVoxCore/LargeVolume.inl | 5 +- .../include/PolyVoxCore/RawVolume.h | 9 ++ .../include/PolyVoxCore/RawVolume.inl | 82 ++++++++++++++----- .../include/PolyVoxCore/SimpleVolume.inl | 5 +- 6 files changed, 82 insertions(+), 26 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 30c34584..e055778e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -45,6 +45,8 @@ namespace PolyVox }; } typedef BoundsChecks::BoundsCheck BoundsCheck; + + template struct BoundsCheckType{}; namespace WrapModes { diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index aabf0287..8301315e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -374,8 +374,9 @@ namespace PolyVox } default: { - //Should never happen. We don't log because this hurts performance (preventing inlining?). - POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). + POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); + return VoxelType(); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index a0c778f6..741ee1c2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -241,8 +241,9 @@ namespace PolyVox } default: { - //Should never happen. We don't log because this hurts performance (preventing inlining?). - POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). + POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); + return VoxelType(); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 95a770b9..d1b821ad 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -115,6 +115,10 @@ namespace PolyVox /// Destructor ~RawVolume(); + /// Gets a voxel at the position given by x,y,z coordinates + template + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; /// Gets a voxel at the position given by a 3D vector @@ -150,6 +154,11 @@ namespace PolyVox private: void initialise(const Region& regValidRegion); + template + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const; + //The block data VoxelType* m_pData; }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 5614650d..a81799ae 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -73,6 +73,23 @@ namespace PolyVox POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons."); } + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to + /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing + /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + template + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + { + // Simply call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + } + //////////////////////////////////////////////////////////////////////////////// /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel @@ -89,23 +106,14 @@ namespace PolyVox // bounds, and throw an exception if they are violated. if(eBoundsCheck == BoundsChecks::Full) { - if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) - { - POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); - } + // Call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + } + else + { + // Call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); } - - const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); - int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); - int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); - int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); - - return m_pData - [ - iLocalXPos + - iLocalYPos * this->getWidth() + - iLocalZPos * this->getWidth() * this->getHeight() - ]; } //////////////////////////////////////////////////////////////////////////////// @@ -182,14 +190,14 @@ namespace PolyVox uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. + return getVoxel(uXPos, uYPos, uZPos); // No bounds checks as we've just validated the position. //No need to break as we've returned } case WrapModes::Border: { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. + return getVoxel(uXPos, uYPos, uZPos); // No bounds checks as we've just validated the position. } else { @@ -199,8 +207,9 @@ namespace PolyVox } default: { - //Should never happen. We don't log because this hurts performance (preventing inlining?). - POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). + POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); + return VoxelType(); } } } @@ -346,5 +355,38 @@ namespace PolyVox return this->getWidth() * this->getHeight() * this->getDepth() * sizeof(VoxelType); } + template + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const + { + POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); + } + + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + + return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + } + + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const + { + const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); + int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); + int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); + int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); + + return m_pData + [ + iLocalXPos + + iLocalYPos * this->getWidth() + + iLocalZPos * this->getWidth() * this->getHeight() + ]; + } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 7f5ff9d6..4dc5af0a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -199,8 +199,9 @@ namespace PolyVox } default: { - //Should never happen. We don't log because this hurts performance (preventing inlining?). - POLYVOX_THROW_DONT_LOG(std::invalid_argument, "Wrap mode parameter has an unrecognised value."); + //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). + POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); + return VoxelType(); } } } From 2b03e84f83934668db1f809d20e826930d1e97dc Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 6 Jun 2013 16:07:47 +0200 Subject: [PATCH 11/64] Combining BoundsChecks and WrapMode into a single enum. --- .../include/PolyVoxCore/BaseVolume.h | 6 +- .../include/PolyVoxCore/Impl/Config.h | 2 +- .../include/PolyVoxCore/LowPassFilter.inl | 24 ++++---- .../include/PolyVoxCore/RawVolume.h | 14 +++-- .../include/PolyVoxCore/RawVolume.inl | 59 +++++++++++++++---- 5 files changed, 74 insertions(+), 31 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index e055778e..a87b92a5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -41,11 +41,15 @@ namespace PolyVox enum BoundsCheck { None = 0, - Full = 1 + Full = 1, + ClampPos = 2, + BorderPos = 3 }; } typedef BoundsChecks::BoundsCheck BoundsCheck; + // Required for a trick to implement specialization of template member + // functions in template classes. See http://stackoverflow.com/a/4951057 template struct BoundsCheckType{}; namespace WrapModes diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h index e97e27af..b852d165 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Config_H__ #define __PolyVox_Config_H__ -#define POLYVOX_ASSERTS_ENABLED +//#define POLYVOX_ASSERTS_ENABLED #define POLYVOX_THROW_ENABLED #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 4d942519..79329a7f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -192,8 +192,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - AccumulationType previousSum = static_cast(satVolume.getVoxelAt(x,y-1,z)); - AccumulationType currentSum = static_cast(satVolume.getVoxelAt(x,y,z)); + AccumulationType previousSum = static_cast(satVolume.getVoxel(x,y-1,z, BoundsChecks::BorderPos)); + AccumulationType currentSum = static_cast(satVolume.getVoxel(x,y,z, BoundsChecks::BorderPos)); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -206,8 +206,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - AccumulationType previousSum = static_cast(satVolume.getVoxelAt(x,y,z-1)); - AccumulationType currentSum = static_cast(satVolume.getVoxelAt(x,y,z)); + AccumulationType previousSum = static_cast(satVolume.getVoxel(x,y,z-1, BoundsChecks::BorderPos)); + AccumulationType currentSum = static_cast(satVolume.getVoxel(x,y,z, BoundsChecks::BorderPos)); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -234,14 +234,14 @@ namespace PolyVox int32_t satUpperY = iSrcY + border; int32_t satUpperZ = iSrcZ + border; - AccumulationType a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ); - AccumulationType b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ); - AccumulationType c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ); - AccumulationType d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ); - AccumulationType e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ); - AccumulationType f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ); - AccumulationType g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ); - AccumulationType h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); + AccumulationType a = satVolume.getVoxel(satLowerX,satLowerY,satLowerZ, BoundsChecks::BorderPos); + AccumulationType b = satVolume.getVoxel(satUpperX,satLowerY,satLowerZ, BoundsChecks::BorderPos); + AccumulationType c = satVolume.getVoxel(satLowerX,satUpperY,satLowerZ, BoundsChecks::BorderPos); + AccumulationType d = satVolume.getVoxel(satUpperX,satUpperY,satLowerZ, BoundsChecks::BorderPos); + AccumulationType e = satVolume.getVoxel(satLowerX,satLowerY,satUpperZ, BoundsChecks::BorderPos); + AccumulationType f = satVolume.getVoxel(satUpperX,satLowerY,satUpperZ, BoundsChecks::BorderPos); + AccumulationType g = satVolume.getVoxel(satLowerX,satUpperY,satUpperZ, BoundsChecks::BorderPos); + AccumulationType h = satVolume.getVoxel(satUpperX,satUpperY,satUpperZ, BoundsChecks::BorderPos); AccumulationType sum = h+c-d-g-f-a+b+e; uint32_t sideLength = border * 2 + 1; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index d1b821ad..14091c92 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -117,12 +117,12 @@ namespace PolyVox /// Gets a voxel at the position given by x,y,z coordinates template - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector @@ -155,9 +155,11 @@ namespace PolyVox void initialise(const Region& regValidRegion); template - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; //The block data VoxelType* m_pData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index a81799ae..fa323173 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -84,10 +84,10 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// template template - VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const { // Simply call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); } //////////////////////////////////////////////////////////////////////////////// @@ -100,19 +100,29 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck) const + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck, VoxelType tBorder) const { // If bounds checking is enabled then we validate the // bounds, and throw an exception if they are violated. if(eBoundsCheck == BoundsChecks::Full) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + } + else if(eBoundsCheck == BoundsChecks::None) + { + // Call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + } + else if(eBoundsCheck == BoundsChecks::ClampPos) + { + // Call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); } else { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); } } @@ -124,9 +134,9 @@ namespace PolyVox /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const + VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck, VoxelType tBorder) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck, tBorder); } //////////////////////////////////////////////////////////////////////////////// @@ -357,24 +367,24 @@ namespace PolyVox template template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const { POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheckType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const { const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); @@ -388,5 +398,32 @@ namespace PolyVox iLocalZPos * this->getWidth() * this->getHeight() ]; } + + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const + { + //Perform clamping + uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); + uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); + uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); + uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); + uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); + uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); + + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + } + + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const + { + if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) + { + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); // No bounds checks as we've just validated the position. + } + else + { + return tBorder; //FIXME - Should return border value. + } + } } From 6bc379f0df7670607127fc2b51c919379983931c Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 6 Jun 2013 16:26:55 +0200 Subject: [PATCH 12/64] More work combining WrapMode and BoundsCheck --- .../include/PolyVoxCore/BaseVolume.h | 10 +- .../include/PolyVoxCore/LowPassFilter.inl | 24 ++--- .../include/PolyVoxCore/RawVolume.h | 22 ++--- .../include/PolyVoxCore/RawVolume.inl | 92 +++++++++---------- 4 files changed, 77 insertions(+), 71 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index a87b92a5..5bc112a6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -56,12 +56,18 @@ namespace PolyVox { enum WrapMode { - Clamp = 0, - Border = 1 + None = 0, + Clamp = 1, + Border = 2, + DontCheck = 3 }; } typedef WrapModes::WrapMode WrapMode; + // Required for a trick to implement specialization of template member + // functions in template classes. See http://stackoverflow.com/a/4951057 + template struct WrapModeType{}; + template class BaseVolume { diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 79329a7f..22e476a9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -192,8 +192,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - AccumulationType previousSum = static_cast(satVolume.getVoxel(x,y-1,z, BoundsChecks::BorderPos)); - AccumulationType currentSum = static_cast(satVolume.getVoxel(x,y,z, BoundsChecks::BorderPos)); + AccumulationType previousSum = static_cast(satVolume.getVoxel(x,y-1,z, WrapModes::Border)); + AccumulationType currentSum = static_cast(satVolume.getVoxel(x,y,z, WrapModes::Border)); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -206,8 +206,8 @@ namespace PolyVox { for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) { - AccumulationType previousSum = static_cast(satVolume.getVoxel(x,y,z-1, BoundsChecks::BorderPos)); - AccumulationType currentSum = static_cast(satVolume.getVoxel(x,y,z, BoundsChecks::BorderPos)); + AccumulationType previousSum = static_cast(satVolume.getVoxel(x,y,z-1, WrapModes::Border)); + AccumulationType currentSum = static_cast(satVolume.getVoxel(x,y,z, WrapModes::Border)); satVolume.setVoxelAt(x,y,z,previousSum + currentSum); } @@ -234,14 +234,14 @@ namespace PolyVox int32_t satUpperY = iSrcY + border; int32_t satUpperZ = iSrcZ + border; - AccumulationType a = satVolume.getVoxel(satLowerX,satLowerY,satLowerZ, BoundsChecks::BorderPos); - AccumulationType b = satVolume.getVoxel(satUpperX,satLowerY,satLowerZ, BoundsChecks::BorderPos); - AccumulationType c = satVolume.getVoxel(satLowerX,satUpperY,satLowerZ, BoundsChecks::BorderPos); - AccumulationType d = satVolume.getVoxel(satUpperX,satUpperY,satLowerZ, BoundsChecks::BorderPos); - AccumulationType e = satVolume.getVoxel(satLowerX,satLowerY,satUpperZ, BoundsChecks::BorderPos); - AccumulationType f = satVolume.getVoxel(satUpperX,satLowerY,satUpperZ, BoundsChecks::BorderPos); - AccumulationType g = satVolume.getVoxel(satLowerX,satUpperY,satUpperZ, BoundsChecks::BorderPos); - AccumulationType h = satVolume.getVoxel(satUpperX,satUpperY,satUpperZ, BoundsChecks::BorderPos); + AccumulationType a = satVolume.getVoxel(satLowerX,satLowerY,satLowerZ, WrapModes::Border); + AccumulationType b = satVolume.getVoxel(satUpperX,satLowerY,satLowerZ, WrapModes::Border); + AccumulationType c = satVolume.getVoxel(satLowerX,satUpperY,satLowerZ, WrapModes::Border); + AccumulationType d = satVolume.getVoxel(satUpperX,satUpperY,satLowerZ, WrapModes::Border); + AccumulationType e = satVolume.getVoxel(satLowerX,satLowerY,satUpperZ, WrapModes::Border); + AccumulationType f = satVolume.getVoxel(satUpperX,satLowerY,satUpperZ, WrapModes::Border); + AccumulationType g = satVolume.getVoxel(satLowerX,satUpperY,satUpperZ, WrapModes::Border); + AccumulationType h = satVolume.getVoxel(satUpperX,satUpperY,satUpperZ, WrapModes::Border); AccumulationType sum = h+c-d-g-f-a+b+e; uint32_t sideLength = border * 2 + 1; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 14091c92..9da7c5d1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -116,21 +116,21 @@ namespace PolyVox ~RawVolume(); /// Gets a voxel at the position given by x,y,z coordinates - template + template VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; + //VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; + //VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the voxel at the position given by x,y,z coordinates void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); @@ -154,12 +154,12 @@ namespace PolyVox private: void initialise(const Region& regValidRegion); - template - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const; + template + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; //The block data VoxelType* m_pData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index fa323173..5397732f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -83,11 +83,11 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - template + template VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const { // Simply call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); } //////////////////////////////////////////////////////////////////////////////// @@ -100,29 +100,29 @@ namespace PolyVox /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck, VoxelType tBorder) const + VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const { // If bounds checking is enabled then we validate the // bounds, and throw an exception if they are violated. - if(eBoundsCheck == BoundsChecks::Full) + if(eWrapMode == WrapModes::None) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); } - else if(eBoundsCheck == BoundsChecks::None) + else if(eWrapMode == WrapModes::Clamp) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); } - else if(eBoundsCheck == BoundsChecks::ClampPos) + else if(eWrapMode == WrapModes::Border) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); } else { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); } } @@ -134,9 +134,9 @@ namespace PolyVox /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template - VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck, VoxelType tBorder) const + VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck, tBorder); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } //////////////////////////////////////////////////////////////////////////////// @@ -184,7 +184,7 @@ namespace PolyVox /// \param uZPos The \c z position of the voxel /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// - template + /*template VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const { switch(eWrapMode) @@ -232,7 +232,7 @@ namespace PolyVox VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const { return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); - } + }*/ //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel @@ -366,25 +366,52 @@ namespace PolyVox } template - template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const { POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + { + //Perform clamping + uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); + uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); + uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); + uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); + uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); + uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); + + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + } + + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + { + if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) + { + return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); // No bounds checks as we've just validated the position. + } + else + { + return tBorder; //FIXME - Should return border value. + } + } + + template + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const { const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); @@ -398,32 +425,5 @@ namespace PolyVox iLocalZPos * this->getWidth() * this->getHeight() ]; } - - template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const - { - //Perform clamping - uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); - uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); - uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); - uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); - uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); - uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); - } - - template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, BoundsCheckType) const - { - if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) - { - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, BoundsCheckType()); // No bounds checks as we've just validated the position. - } - else - { - return tBorder; //FIXME - Should return border value. - } - } } From 745f24eab83cfc6910b0dadcab4403222f5b3151 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 6 Jun 2013 16:39:49 +0200 Subject: [PATCH 13/64] More work on wrap modes. --- .../include/PolyVoxCore/RawVolume.h | 10 +++---- .../include/PolyVoxCore/RawVolume.inl | 28 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 9da7c5d1..6c4c7605 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -155,11 +155,11 @@ namespace PolyVox void initialise(const Region& regValidRegion); template - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; //The block data VoxelType* m_pData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 5397732f..cc381832 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -87,7 +87,7 @@ namespace PolyVox VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const { // Simply call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } //////////////////////////////////////////////////////////////////////////////// @@ -107,22 +107,22 @@ namespace PolyVox if(eWrapMode == WrapModes::None) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } else if(eWrapMode == WrapModes::Clamp) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } else if(eWrapMode == WrapModes::Border) { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } else { // Call through to the real implementation - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } } @@ -367,24 +367,24 @@ namespace PolyVox template template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { - POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); + POLYVOX_ASSERT(false, "This function is not implemented and should never be called!"); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { //Perform clamping uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); @@ -394,15 +394,15 @@ namespace PolyVox uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxelImpl(uXPos, uYPos, uZPos, tBorder, WrapModeType()); // No bounds checks as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No bounds checks as we've just validated the position. } else { @@ -411,7 +411,7 @@ namespace PolyVox } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder, WrapModeType) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); From 900b693e25141afcacbbfc9ebef18778fb556a5a Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Jun 2013 15:43:35 +0200 Subject: [PATCH 14/64] More work combining BoundsCheck with WrapMode. --- .../include/PolyVoxCore/RawVolume.h | 9 +- .../include/PolyVoxCore/RawVolume.inl | 127 ++++++------------ 2 files changed, 48 insertions(+), 88 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 6c4c7605..2ad80cb5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -118,19 +118,19 @@ namespace PolyVox /// Gets a voxel at the position given by x,y,z coordinates template VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by a 3D vector + template + VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; - /// Gets a voxel at the position given by x,y,z coordinates - //VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; - /// Gets a voxel at the position given by a 3D vector - //VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the voxel at the position given by x,y,z coordinates void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); @@ -154,6 +154,7 @@ namespace PolyVox private: void initialise(const Region& regValidRegion); + // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 template VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index cc381832..364b0d32 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -74,12 +74,13 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -91,47 +92,60 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + template + VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder) const + { + // Simply call through to the real implementation + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder); + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const { - // If bounds checking is enabled then we validate the - // bounds, and throw an exception if they are violated. - if(eWrapMode == WrapModes::None) + switch(eWrapMode) { - // Call through to the real implementation + case WrapModes::None: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); - } - else if(eWrapMode == WrapModes::Clamp) - { - // Call through to the real implementation + case WrapModes::Clamp: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); - } - else if(eWrapMode == WrapModes::Border) - { - // Call through to the real implementation + case WrapModes::Border: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); - } - else - { - // Call through to the real implementation + case WrapModes::DontCheck: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + default: + // Should never happen + POLYVOX_ASSERT(false, "Invalid wrap mode"); + return VoxelType(); } } //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. /// \param v3dPos The 3D position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const @@ -178,62 +192,6 @@ namespace PolyVox return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - //////////////////////////////////////////////////////////////////////////////// - /// \param uXPos The \c x position of the voxel - /// \param uYPos The \c y position of the voxel - /// \param uZPos The \c z position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - /*template - VoxelType RawVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const - { - switch(eWrapMode) - { - case WrapModes::Clamp: - { - //Perform clamping - uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); - uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); - uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); - uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); - uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); - uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - - //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos); // No bounds checks as we've just validated the position. - //No need to break as we've returned - } - case WrapModes::Border: - { - if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) - { - return getVoxel(uXPos, uYPos, uZPos); // No bounds checks as we've just validated the position. - } - else - { - return tBorder; - } - //No need to break as we've returned - } - default: - { - //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). - POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); - return VoxelType(); - } - } - } - - //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType RawVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const - { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); - }*/ - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel @@ -369,6 +327,7 @@ namespace PolyVox template VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { + // This function should never be called because one of the specialisations should always match. POLYVOX_ASSERT(false, "This function is not implemented and should never be called!"); } @@ -380,7 +339,7 @@ namespace PolyVox POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No bounds checks as we've just validated the position. } template @@ -394,7 +353,7 @@ namespace PolyVox uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No bounds checks as we've just validated the position. } template @@ -406,7 +365,7 @@ namespace PolyVox } else { - return tBorder; //FIXME - Should return border value. + return tBorder; } } From 8ed5edf85fea7742be7591f2920ebcd4eb4496fa Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Jun 2013 15:47:21 +0200 Subject: [PATCH 15/64] Documentation fix. --- library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 364b0d32..2dea1f15 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -339,7 +339,7 @@ namespace PolyVox POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No bounds checks as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -353,7 +353,7 @@ namespace PolyVox uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No bounds checks as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -361,7 +361,7 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No bounds checks as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } else { From 3d82b9643f7ad498536096d000ce5a67fc3b69f9 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Jun 2013 15:58:24 +0200 Subject: [PATCH 16/64] Applied BoundsCheck and WrapMode merging changes to SimpleVolume. --- .../include/PolyVoxCore/SimpleVolume.h | 24 +- .../include/PolyVoxCore/SimpleVolume.inl | 211 ++++++++++-------- 2 files changed, 142 insertions(+), 93 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 2bd0a366..5503f64b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -155,17 +155,21 @@ namespace PolyVox ~SimpleVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + template + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + template + VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; + + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by a 3D vector + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; - /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; - /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the voxel at the position given by x,y,z coordinates void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); @@ -189,6 +193,14 @@ namespace PolyVox private: void initialise(const Region& regValidRegion, uint16_t uBlockSideLength); + // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 + template + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; //The block data diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 4dc5af0a..93ef557d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -74,51 +74,83 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck) const + template + VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const { - // If bounds checking is enabled then we validate the - // bounds, and throw an exception if they are violated. - if(eBoundsCheck == BoundsChecks::Full) - { - if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) - { - POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); - } - } - - const int32_t blockX = uXPos >> m_uBlockSideLengthPower; - const int32_t blockY = uYPos >> m_uBlockSideLengthPower; - const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; - - const uint16_t xOffset = static_cast(uXPos - (blockX << m_uBlockSideLengthPower)); - const uint16_t yOffset = static_cast(uYPos - (blockY << m_uBlockSideLengthPower)); - const uint16_t zOffset = static_cast(uZPos - (blockZ << m_uBlockSideLengthPower)); - - typename SimpleVolume::Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); - - return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); + // Simply call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const + template + VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck); + // Simply call through to the real implementation + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder); + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const + { + switch(eWrapMode) + { + case WrapModes::None: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Clamp: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Border: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::DontCheck: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + default: + // Should never happen + POLYVOX_ASSERT(false, "Invalid wrap mode"); + return VoxelType(); + } + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param v3dPos The 3D position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const + { + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } //////////////////////////////////////////////////////////////////////////////// @@ -160,62 +192,6 @@ namespace PolyVox return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - //////////////////////////////////////////////////////////////////////////////// - /// \param uXPos The \c x position of the voxel - /// \param uYPos The \c y position of the voxel - /// \param uZPos The \c z position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType SimpleVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const - { - switch(eWrapMode) - { - case WrapModes::Clamp: - { - //Perform clamping - uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); - uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); - uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); - uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); - uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); - uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - - //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. - //No need to break as we've returned - } - case WrapModes::Border: - { - if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) - { - return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. - } - else - { - return tBorder; - } - //No need to break as we've returned - } - default: - { - //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). - POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); - return VoxelType(); - } - } - } - - //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType SimpleVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const - { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel @@ -398,5 +374,66 @@ namespace PolyVox return uSizeInBytes; } + template + template + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + // This function should never be called because one of the specialisations should always match. + POLYVOX_ASSERT(false, "This function is not implemented and should never be called!"); + } + + template + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + } + + template + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + //Perform clamping + uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); + uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); + uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); + uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); + uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); + uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); + + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + } + + template + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) + { + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + } + else + { + return tBorder; + } + } + + template + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + const int32_t blockX = uXPos >> m_uBlockSideLengthPower; + const int32_t blockY = uYPos >> m_uBlockSideLengthPower; + const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; + + const uint16_t xOffset = static_cast(uXPos - (blockX << m_uBlockSideLengthPower)); + const uint16_t yOffset = static_cast(uYPos - (blockY << m_uBlockSideLengthPower)); + const uint16_t zOffset = static_cast(uZPos - (blockZ << m_uBlockSideLengthPower)); + + typename SimpleVolume::Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); + + return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); + } } From 292b21dcdf9368104feb4266a95f477e4ad8f76c Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Jun 2013 16:13:11 +0200 Subject: [PATCH 17/64] Added merging of BoundsCheck and WrapMode changes into LargeVolume. --- .../include/PolyVoxCore/LargeVolume.h | 24 +- .../include/PolyVoxCore/LargeVolume.inl | 211 ++++++++++-------- 2 files changed, 142 insertions(+), 93 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 0ce3bfc7..3250e6c0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -266,17 +266,21 @@ namespace PolyVox ~LargeVolume(); /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + template + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + template + VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; + + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by a 3D vector + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; - /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; - /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the number of blocks for which uncompressed data is stored void setMaxNumberOfUncompressedBlocks(uint32_t uMaxNumberOfUncompressedBlocks); @@ -330,6 +334,14 @@ namespace PolyVox }; void initialise(const Region& regValidRegion, uint16_t uBlockSideLength); + // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 + template + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + /// gets called when a new region is allocated and needs to be filled /// NOTE: accessing ANY voxels outside this region during the process of this function /// is absolutely unsafe diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 741ee1c2..9f0bd3dc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -116,51 +116,83 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck) const + template + VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const { - // If bounds checking is enabled then we validate the - // bounds, and throw an exception if they are violated. - if(eBoundsCheck == BoundsChecks::Full) - { - if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) - { - POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); - } - } - - const int32_t blockX = uXPos >> m_uBlockSideLengthPower; - const int32_t blockY = uYPos >> m_uBlockSideLengthPower; - const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; - - const uint16_t xOffset = static_cast(uXPos - (blockX << m_uBlockSideLengthPower)); - const uint16_t yOffset = static_cast(uYPos - (blockY << m_uBlockSideLengthPower)); - const uint16_t zOffset = static_cast(uZPos - (blockZ << m_uBlockSideLengthPower)); - - Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); - - return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); + // Simply call through to the real implementation + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); } //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck) const + template + VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder) const { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eBoundsCheck); + // Simply call through to the real implementation + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder); + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const + { + switch(eWrapMode) + { + case WrapModes::None: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Clamp: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Border: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::DontCheck: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + default: + // Should never happen + POLYVOX_ASSERT(false, "Invalid wrap mode"); + return VoxelType(); + } + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param v3dPos The 3D position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const + { + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } //////////////////////////////////////////////////////////////////////////////// @@ -202,62 +234,6 @@ namespace PolyVox return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - //////////////////////////////////////////////////////////////////////////////// - /// \param uXPos The \c x position of the voxel - /// \param uYPos The \c y position of the voxel - /// \param uZPos The \c z position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType LargeVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const - { - switch(eWrapMode) - { - case WrapModes::Clamp: - { - //Perform clamping - uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); - uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); - uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); - uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); - uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); - uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - - //Get the voxel value - return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. - //No need to break as we've returned - } - case WrapModes::Border: - { - if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) - { - return getVoxel(uXPos, uYPos, uZPos, BoundsChecks::None); // No bounds checks as we've just validated the position. - } - else - { - return tBorder; - } - //No need to break as we've returned - } - default: - { - //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). - POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); - return VoxelType(); - } - } - } - - //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType LargeVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const - { - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); - } - //////////////////////////////////////////////////////////////////////////////// /// Increasing the size of the block cache will increase memory but may improve performance. /// You may want to set this to a large value (e.g. 1024) when you are first loading your @@ -767,5 +743,66 @@ namespace PolyVox return uSizeInBytes; } + template + template + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + // This function should never be called because one of the specialisations should always match. + POLYVOX_ASSERT(false, "This function is not implemented and should never be called!"); + } + + template + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + } + + template + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + //Perform clamping + uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); + uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); + uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); + uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); + uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); + uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); + + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + } + + template + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) + { + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + } + else + { + return tBorder; + } + } + + template + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + { + const int32_t blockX = uXPos >> m_uBlockSideLengthPower; + const int32_t blockY = uYPos >> m_uBlockSideLengthPower; + const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; + + const uint16_t xOffset = static_cast(uXPos - (blockX << m_uBlockSideLengthPower)); + const uint16_t yOffset = static_cast(uYPos - (blockY << m_uBlockSideLengthPower)); + const uint16_t zOffset = static_cast(uZPos - (blockZ << m_uBlockSideLengthPower)); + + Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); + + return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); + } } From d98856b2761af5527f03182c2a5f763366f32425 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Jun 2013 16:49:06 +0200 Subject: [PATCH 18/64] setVoxel for RawVolume now takes WrapMode instead of bounds check. --- .../include/PolyVoxCore/RawVolume.h | 4 ++-- .../include/PolyVoxCore/RawVolume.inl | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 2ad80cb5..04287b56 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -133,9 +133,9 @@ namespace PolyVox VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 2dea1f15..21be2e4f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -197,16 +197,19 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data. //////////////////////////////////////////////////////////////////////////////// template - void RawVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) + void RawVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - // If bounds checking is enabled then we validate the - // bounds, and throw an exception if they are violated. - if(eBoundsCheck == BoundsChecks::Full) + if((eWrapMode != None) && (eWrapMode != DontCheck)) + { + POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); + } + + // This validation is skipped if the wrap mode is 'DontCheck' + if(eWrapMode == WrapModes::None) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -230,12 +233,11 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data. //////////////////////////////////////////////////////////////////////////////// template - void RawVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) + void RawVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode) { setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); } From 1f2b7e474246ac0e88dfd24eec7b035d792cae13 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 7 Jun 2013 16:57:45 +0200 Subject: [PATCH 19/64] Added modified setVoxel functions to SimpleVolume and LargeVolume. --- .../include/PolyVoxCore/LargeVolume.h | 4 ++-- .../include/PolyVoxCore/LargeVolume.inl | 24 ++++++++++--------- .../include/PolyVoxCore/SimpleVolume.h | 4 ++-- .../include/PolyVoxCore/SimpleVolume.inl | 24 ++++++++++--------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 3250e6c0..e169d9b8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -287,9 +287,9 @@ namespace PolyVox /// Sets the number of blocks which can be in memory before the paging system starts unloading them void setMaxNumberOfBlocksInMemory(uint32_t uMaxNumberOfBlocksInMemory); /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 9f0bd3dc..c8f3e0f6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -267,16 +267,19 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data. //////////////////////////////////////////////////////////////////////////////// template - void LargeVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) + void LargeVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - // If bounds checking is enabled then we validate the - // bounds, and throw an exception if they are violated. - if(eBoundsCheck == BoundsChecks::Full) + if((eWrapMode != None) && (eWrapMode != DontCheck)) + { + POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); + } + + // This validation is skipped if the wrap mode is 'DontCheck' + if(eWrapMode == WrapModes::None) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -300,12 +303,11 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data. //////////////////////////////////////////////////////////////////////////////// template - void LargeVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) + void LargeVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode) { setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 5503f64b..427d1e41 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -172,9 +172,9 @@ namespace PolyVox VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 93ef557d..f8bd979a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -197,16 +197,19 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data. //////////////////////////////////////////////////////////////////////////////// template - void SimpleVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck) + void SimpleVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - // If bounds checking is enabled then we validate the - // bounds, and throw an exception if they are violated. - if(eBoundsCheck == BoundsChecks::Full) + if((eWrapMode != None) && (eWrapMode != DontCheck)) + { + POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); + } + + // This validation is skipped if the wrap mode is 'DontCheck' + if(eWrapMode == WrapModes::None) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -230,12 +233,11 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// This must be set to 'None' or 'DontCheck'. Other wrap modes cannot be used when writing to volume data. //////////////////////////////////////////////////////////////////////////////// template - void SimpleVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck) + void SimpleVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode) { setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); } From 60d6658e1af1b45bf919931845af4fc62996d632 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 13:38:36 +0200 Subject: [PATCH 20/64] Changed a couple of 'getVoxelAt()' to 'getVoxel()'. --- examples/Paging/main.cpp | 2 +- library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl | 6 +++--- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index b4e60974..20a272c6 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -184,7 +184,7 @@ void createSphereInVolume(LargeVolume& volData, Vector3DF uint8_t uDensity = MaterialDensityPair44::getMaxDensity(); //Get the old voxel - MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); + MaterialDensityPair44 voxel = volData.getVoxel(x,y,z); //Modify the density voxel.setDensity(uDensity); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 67932672..1f7b71d5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -52,8 +52,8 @@ namespace PolyVox Block(uint16_t uSideLength = 0); uint16_t getSideLength(void) const; - VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; - VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const; + VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; + VoxelType getVoxel(const Vector3DUint16& v3dPos) const; void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index bb95f584..61c9baac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -58,7 +58,7 @@ namespace PolyVox } template - VoxelType Block::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const + VoxelType Block::getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const { // This is internal code not directly called by the user. For efficiency we assert rather than throwing. POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); @@ -75,9 +75,9 @@ namespace PolyVox } template - VoxelType Block::getVoxelAt(const Vector3DUint16& v3dPos) const + VoxelType Block::getVoxel(const Vector3DUint16& v3dPos) const { - return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index c8f3e0f6..abf3e4ed 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -216,7 +216,7 @@ namespace PolyVox Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); - return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); + return pUncompressedBlock->getVoxel(xOffset,yOffset,zOffset); } else { @@ -804,7 +804,7 @@ namespace PolyVox Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); - return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset); + return pUncompressedBlock->getVoxel(xOffset,yOffset,zOffset); } } From 7276b872c42cc7672cc020b50d76f3b03eb44647 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:03:34 +0200 Subject: [PATCH 21/64] More work replacing getVoxelAt with getVoxel. --- .../include/PolyVoxCore/BaseVolume.h | 17 ++-- .../include/PolyVoxCore/BaseVolume.inl | 78 ++++++++++++------- .../include/PolyVoxCore/BaseVolumeSampler.inl | 46 ++++------- tests/TestVolumeSubclass.cpp | 78 +++++++++++++++++++ 4 files changed, 152 insertions(+), 67 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 5bc112a6..13a04c76 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -168,18 +168,23 @@ namespace PolyVox int32_t getShortestSideLength(void) const; /// Gets the length of the diagonal in voxels float getDiagonalLength(void) const; + /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + template + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, BoundsCheck eBoundsCheck = BoundsChecks::Full) const; + template + VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; + + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by a 3D vector + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; - /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; - /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder = VoxelType()) const; /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index c9fc1fcb..6de44062 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -154,26 +154,70 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, BoundsCheck /*eBoundsCheck*/) const + template + VoxelType BaseVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder) const { - POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); + POLYVOX_ASSERT(false, "You should never call the base class version of this function."); return VoxelType(); } //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel + /// This version of the function requires the wrap mode to be specified as a + /// template parameter, which can provide better performance. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \tparam eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, BoundsCheck /*eBoundsCheck*/) const + template + VoxelType BaseVolume::getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder) const { - POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); + POLYVOX_ASSERT(false, "You should never call the base class version of this function."); + return VoxelType(); + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType BaseVolume::getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode, VoxelType tBorder) const + { + POLYVOX_ASSERT(false, "You should never call the base class version of this function."); + return VoxelType(); + } + + //////////////////////////////////////////////////////////////////////////////// + /// This version of the function is provided so that the wrap mode does not need + /// to be specified as a template parameter, as it may be confusing to some users. + /// \param v3dPos The 3D position of the voxel + /// \param eWrapMode Specifies the behaviour when the requested position is outside of the volume. + /// \param tBorder The border value to use if the wrap mode is set to 'Border'. + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType BaseVolume::getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode, VoxelType tBorder) const + { + POLYVOX_ASSERT(false, "You should never call the base class version of this function."); return VoxelType(); } @@ -207,30 +251,6 @@ namespace PolyVox return VoxelType(); } - //////////////////////////////////////////////////////////////////////////////// - /// \param uXPos The \c x position of the voxel - /// \param uYPos The \c y position of the voxel - /// \param uZPos The \c z position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType BaseVolume::getVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const - { - POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); - return VoxelType(); - } - - //////////////////////////////////////////////////////////////////////////////// - /// \param v3dPos The 3D position of the voxel - /// \return The voxel value - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType BaseVolume::getVoxel(const Vector3DInt32& /*v3dPos*/, WrapMode /*eWrapMode*/, VoxelType /*tBorder*/) const - { - POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); - return VoxelType(); - } - //////////////////////////////////////////////////////////////////////////////// /// \param tBorder The value to use for voxels outside the volume. //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index 8301315e..eaf3b29d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -57,7 +57,7 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::getVoxel(void) const { - return mVolume->getVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume); + return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume); } template @@ -347,38 +347,20 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { - if(mVolume->getEnclosingRegion().containsPoint(uXPos, uYPos, uZPos)) + switch(m_eWrapMode) { - return mVolume->getVoxelAt(uXPos, uYPos, uZPos); - } - else - { - switch(m_eWrapMode) - { - case WrapModes::Clamp: - { - const Vector3DInt32& lowerCorner = mVolume->m_regValidRegion.getLowerCorner(); - const Vector3DInt32& upperCorner = mVolume->m_regValidRegion.getUpperCorner(); - - int32_t iClampedX = clamp(uXPos, lowerCorner.getX(), upperCorner.getX()); - int32_t iClampedY = clamp(uYPos, lowerCorner.getY(), upperCorner.getY()); - int32_t iClampedZ = clamp(uZPos, lowerCorner.getZ(), upperCorner.getZ()); - - return mVolume->getVoxelAt(iClampedX, iClampedY, iClampedZ); - //No need to break as we've returned - } - case WrapModes::Border: - { - return m_tBorder; - //No need to break as we've returned - } - default: - { - //Should never happen. However, this assert appears to hurt performance (logging prevents inlining?). - POLYVOX_ASSERT(false, "Wrap mode parameter has an unrecognised value."); - return VoxelType(); - } - } + case WrapModes::None: + return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + case WrapModes::Clamp: + return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + case WrapModes::Border: + return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + case WrapModes::DontCheck: + return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + default: + // Should never happen + POLYVOX_ASSERT(false, "Invalid wrap mode"); + return VoxelType(); } } } diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index e70afb92..275dd3b1 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -68,6 +68,84 @@ public: /// Destructor ~VolumeSubclass() {}; + /// Gets a voxel at the position given by x,y,z coordinates + template + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const + { + switch(eWrapMode) + { + case WrapModes::None: + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) + { + POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); + } + + return mVolumeData[uXPos][uYPos][uZPos]; + } + case WrapModes::Clamp: + { + //Perform clamping + uXPos = (std::max)(uXPos, this->m_regValidRegion.getLowerX()); + uYPos = (std::max)(uYPos, this->m_regValidRegion.getLowerY()); + uZPos = (std::max)(uZPos, this->m_regValidRegion.getLowerZ()); + uXPos = (std::min)(uXPos, this->m_regValidRegion.getUpperX()); + uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); + uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); + return mVolumeData[uXPos][uYPos][uZPos]; + } + case WrapModes::Border: + { + if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) + { + return mVolumeData[uXPos][uYPos][uZPos]; + } + else + { + return tBorder; + } + } + case WrapModes::DontCheck: + { + return mVolumeData[uXPos][uYPos][uZPos]; + } + } + } + + /// Gets a voxel at the position given by a 3D vector + template + VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const + { + // Simply call through to the real implementation + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder); + } + + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const + { + switch(eWrapMode) + { + case WrapModes::None: + return getVoxel(uXPos, uYPos, uZPos, WrapModes::None, tBorder); + case WrapModes::Clamp: + return getVoxel(uXPos, uYPos, uZPos, WrapModes::Clamp, tBorder); + case WrapModes::Border: + return getVoxel(uXPos, uYPos, uZPos, WrapModes::Border, tBorder); + case WrapModes::DontCheck: + return getVoxel(uXPos, uYPos, uZPos, WrapModes::DontCheck, tBorder); + default: + // Should never happen + POLYVOX_ASSERT(false, "Invalid wrap mode"); + return VoxelType(); + } + } + + /// Gets a voxel at the position given by a 3D vector + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const + { + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); + } + /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const { return 0; } /// Gets a voxel at the position given by x,y,z coordinates From 3a9b3934595a9883fa3c7776fad6dd4ad2d7c03d Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:10:14 +0200 Subject: [PATCH 22/64] Renamed getVoxelAt in volume samplers to avoid confusion with the version in volumes. --- .../include/PolyVoxCore/BaseVolume.h | 2 +- .../include/PolyVoxCore/BaseVolumeSampler.inl | 56 +++++++++---------- .../PolyVoxCore/LargeVolumeSampler.inl | 2 +- .../include/PolyVoxCore/RawVolumeSampler.inl | 2 +- .../PolyVoxCore/SimpleVolumeSampler.inl | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 13a04c76..2c675bee 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -131,7 +131,7 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1pz(void) const; protected: - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; DerivedVolumeType* mVolume; diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index eaf3b29d..6177aaf2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -154,63 +154,63 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume ); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx0py1nz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx0py0pz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume ); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx0py1pz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1py1nz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1py0pz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume ); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1nx1py1pz(void) const { - return getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1); } ////////////////////////////////////////////////////////////////////////// @@ -219,63 +219,63 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::peekVoxel0px1ny1nz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1ny0pz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume ); + return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1ny1pz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px0py1nz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px0py0pz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume ); + return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel0px0py1pz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1py1nz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1py0pz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume ); + return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel0px1py1pz(void) const { - return getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1); } ////////////////////////////////////////////////////////////////////////// @@ -284,68 +284,68 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::peekVoxel1px1ny1nz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1ny0pz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume ); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1ny1pz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px0py1nz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px0py0pz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume ); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1px0py1pz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1py1nz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1py0pz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume ); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume ); } template template VoxelType BaseVolume::Sampler::peekVoxel1px1py1pz(void) const { - return getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); + return getVoxelImpl(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); } template template - VoxelType BaseVolume::Sampler::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + VoxelType BaseVolume::Sampler::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { switch(m_eWrapMode) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 11e916e2..33acc503 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -88,7 +88,7 @@ namespace PolyVox } else { - return getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + return getVoxelImpl(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 08ce94e8..6de3f3df 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -51,7 +51,7 @@ namespace PolyVox } else { - return getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + return getVoxelImpl(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 477eb2da..a4892f26 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -94,7 +94,7 @@ namespace PolyVox } else { - return getVoxelAt(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); + return getVoxelImpl(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } From 45af7a4246dbd1c3963c60bcead6ece61ce282b3 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:11:45 +0200 Subject: [PATCH 23/64] Removed some getVoxelAt() calls in tests. --- tests/TestLowPassFilter.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp index 902c26d6..5af198b9 100644 --- a/tests/TestLowPassFilter.cpp +++ b/tests/TestLowPassFilter.cpp @@ -64,27 +64,27 @@ void TestLowPassFilter::testExecute() QBENCHMARK { lowPassfilter.execute(); } - QCOMPARE(resultVolume.getVoxelAt(0,0,0), Density8(4)); - QCOMPARE(resultVolume.getVoxelAt(1,1,1), Density8(21)); - QCOMPARE(resultVolume.getVoxelAt(2,2,2), Density8(10)); - QCOMPARE(resultVolume.getVoxelAt(3,3,3), Density8(21)); - QCOMPARE(resultVolume.getVoxelAt(4,4,4), Density8(10)); - QCOMPARE(resultVolume.getVoxelAt(5,5,5), Density8(21)); - QCOMPARE(resultVolume.getVoxelAt(6,6,6), Density8(10)); - QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(4)); + QCOMPARE(resultVolume.getVoxel(0,0,0), Density8(4)); + QCOMPARE(resultVolume.getVoxel(1,1,1), Density8(21)); + QCOMPARE(resultVolume.getVoxel(2,2,2), Density8(10)); + QCOMPARE(resultVolume.getVoxel(3,3,3), Density8(21)); + QCOMPARE(resultVolume.getVoxel(4,4,4), Density8(10)); + QCOMPARE(resultVolume.getVoxel(5,5,5), Density8(21)); + QCOMPARE(resultVolume.getVoxel(6,6,6), Density8(10)); + QCOMPARE(resultVolume.getVoxel(7,7,7), Density8(4)); //Test the SAT implmentation QBENCHMARK { lowPassfilter.executeSAT(); } - QCOMPARE(resultVolume.getVoxelAt(0,0,0), Density8(4)); - QCOMPARE(resultVolume.getVoxelAt(1,1,1), Density8(21)); - QCOMPARE(resultVolume.getVoxelAt(2,2,2), Density8(10)); - QCOMPARE(resultVolume.getVoxelAt(3,3,3), Density8(21)); - QCOMPARE(resultVolume.getVoxelAt(4,4,4), Density8(10)); - QCOMPARE(resultVolume.getVoxelAt(5,5,5), Density8(21)); - QCOMPARE(resultVolume.getVoxelAt(6,6,6), Density8(10)); - QCOMPARE(resultVolume.getVoxelAt(7,7,7), Density8(4)); + QCOMPARE(resultVolume.getVoxel(0,0,0), Density8(4)); + QCOMPARE(resultVolume.getVoxel(1,1,1), Density8(21)); + QCOMPARE(resultVolume.getVoxel(2,2,2), Density8(10)); + QCOMPARE(resultVolume.getVoxel(3,3,3), Density8(21)); + QCOMPARE(resultVolume.getVoxel(4,4,4), Density8(10)); + QCOMPARE(resultVolume.getVoxel(5,5,5), Density8(21)); + QCOMPARE(resultVolume.getVoxel(6,6,6), Density8(10)); + QCOMPARE(resultVolume.getVoxel(7,7,7), Density8(4)); } QTEST_MAIN(TestLowPassFilter) From efb6d12fc84624fcaf4a437858e4469b3e8acb42 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:22:21 +0200 Subject: [PATCH 24/64] Eliminated dome calls to getVoxelAt. --- tests/TestAStarPathfinder.cpp | 2 +- tests/TestVolumeSubclass.cpp | 23 ++++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/tests/TestAStarPathfinder.cpp b/tests/TestAStarPathfinder.cpp index 870b88e1..a061bd40 100644 --- a/tests/TestAStarPathfinder.cpp +++ b/tests/TestAStarPathfinder.cpp @@ -40,7 +40,7 @@ bool testVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos) return false; } - typename VolumeType::VoxelType voxel = volData->getVoxelAt(v3dPos); + typename VolumeType::VoxelType voxel = volData->getVoxel(v3dPos); if(voxel != 0) { return false; diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index 275dd3b1..c37e4702 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -109,6 +109,12 @@ public: { return mVolumeData[uXPos][uYPos][uZPos]; } + default: + { + // Should never happen + POLYVOX_ASSERT(false, "Invalid wrap mode"); + return VoxelType(); + } } } @@ -146,23 +152,6 @@ public: return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } - /// Gets the value used for voxels which are outside the volume - VoxelType getBorderValue(void) const { return 0; } - /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const - { - if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) - { - return mVolumeData[uXPos][uYPos][uZPos]; - } - else - { - return getBorderValue(); - } - } - /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const { return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder) { } /// Sets the voxel at the position given by x,y,z coordinates From 3249562d978e85d05e62ef613765bcc1faa43bc8 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:41:45 +0200 Subject: [PATCH 25/64] Removing more calls to getVoxelAt()... --- examples/SmoothLOD/main.cpp | 7 ------- .../include/PolyVoxCore/ConstVolumeProxy.h | 4 ++-- .../include/PolyVoxCore/GradientEstimators.inl | 12 ++++++------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/examples/SmoothLOD/main.cpp b/examples/SmoothLOD/main.cpp index fe2ccc3d..9b8f6f78 100644 --- a/examples/SmoothLOD/main.cpp +++ b/examples/SmoothLOD/main.cpp @@ -55,15 +55,8 @@ void createSphereInVolume(SimpleVolume& volData, float fRadius) if(fDistToCenter <= fRadius) { //Our new density value - //uint8_t uDensity = Density8::getmaxDensity()(); uint8_t uDensity = std::numeric_limits::max(); - //Get the old voxel - //uint8_t voxel = volData.getVoxelAt(x,y,z); - - //Modify the density - //voxel.setDensity(uDensity); - //Wrte the voxel value into the volume volData.setVoxelAt(x, y, z, uDensity); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h index 237a1c59..96573c2e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h @@ -39,14 +39,14 @@ namespace PolyVox { // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); - return m_pVolume.getVoxelAt(uXPos, uYPos, uZPos); + return m_pVolume.getVoxel(uXPos, uYPos, uZPos); } VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const { // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region"); - return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const diff --git a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl index cc401ad3..5add45bd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl @@ -52,14 +52,14 @@ namespace PolyVox const int32_t z = volIter.getPosition().getZ(); //FIXME - bitwise way of doing this? - typename VolumeType::VoxelType voxel1nx = volIter.getVoxelAt(x-2, y ,z ) > 0 ? 1: 0; - typename VolumeType::VoxelType voxel1px = volIter.getVoxelAt(x-2, y ,z ) > 0 ? 1: 0; + typename VolumeType::VoxelType voxel1nx = volIter.getVoxel(x-2, y ,z ) > 0 ? 1: 0; + typename VolumeType::VoxelType voxel1px = volIter.getVoxel(x-2, y ,z ) > 0 ? 1: 0; - typename VolumeType::VoxelType voxel1ny = volIter.getVoxelAt(x , y-2,z ) > 0 ? 1: 0; - typename VolumeType::VoxelType voxel1py = volIter.getVoxelAt(x , y-2,z ) > 0 ? 1: 0; + typename VolumeType::VoxelType voxel1ny = volIter.getVoxel(x , y-2,z ) > 0 ? 1: 0; + typename VolumeType::VoxelType voxel1py = volIter.getVoxel(x , y-2,z ) > 0 ? 1: 0; - typename VolumeType::VoxelType voxel1nz = volIter.getVoxelAt(x , y ,z-2) > 0 ? 1: 0; - typename VolumeType::VoxelType voxel1pz = volIter.getVoxelAt(x , y ,z-2) > 0 ? 1: 0; + typename VolumeType::VoxelType voxel1nz = volIter.getVoxel(x , y ,z-2) > 0 ? 1: 0; + typename VolumeType::VoxelType voxel1pz = volIter.getVoxel(x , y ,z-2) > 0 ? 1: 0; return Vector3DFloat ( From 27833ee03f58cd7ab2192a92ea58a4113c43978c Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:45:57 +0200 Subject: [PATCH 26/64] Fixed compiler warnings. --- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 2 +- library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 2 +- library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index abf3e4ed..b18e335a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -792,7 +792,7 @@ namespace PolyVox } template - VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const { const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 21be2e4f..c30439dd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -372,7 +372,7 @@ namespace PolyVox } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const { const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index f8bd979a..26474a6e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -423,7 +423,7 @@ namespace PolyVox } template - VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const { const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; From 2f62a7de8db622520ea9d464a3bcab05e179d1d6 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:51:06 +0200 Subject: [PATCH 27/64] Marked getVoxelAt functions as deprecated. --- library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/RawVolume.h | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 2c675bee..390a4a6c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -182,9 +182,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index e169d9b8..c61a1938 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -278,9 +278,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the number of blocks for which uncompressed data is stored void setMaxNumberOfUncompressedBlocks(uint32_t uMaxNumberOfUncompressedBlocks); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 04287b56..019359f0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -128,9 +128,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the voxel at the position given by x,y,z coordinates void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 427d1e41..d257123d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -167,9 +167,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; + POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the voxel at the position given by x,y,z coordinates void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); From 28f81a8ae144f74e0078e61eb388e47d96ee4d48 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 15:57:51 +0200 Subject: [PATCH 28/64] Replaced call to getVoxelAt with getVoxel. --- library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl index 745a00bc..5c52cd07 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl @@ -72,7 +72,7 @@ namespace PolyVox { for(int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++) { - const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxelAt(sx,sy,sz); + const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz); const typename DstVolumeType::VoxelType& tDstVoxel = static_cast(tSrcVoxel); m_pVolDst->setVoxelAt(dx,dy,dz,tDstVoxel); } From 0a4ffc23516fec8f6651277273283938853c49a4 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 12 Jun 2013 16:38:27 +0200 Subject: [PATCH 29/64] Linux compile fixes. --- library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl | 2 -- library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl | 4 ++-- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 6de44062..a28eac7f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -273,7 +273,6 @@ namespace PolyVox void BaseVolume::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); - return false; } //////////////////////////////////////////////////////////////////////////////// @@ -287,7 +286,6 @@ namespace PolyVox void BaseVolume::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); - return false; } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h index 96573c2e..792f086a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h @@ -46,7 +46,7 @@ namespace PolyVox { // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region"); - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h index b852d165..e97e27af 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Config_H__ #define __PolyVox_Config_H__ -//#define POLYVOX_ASSERTS_ENABLED +#define POLYVOX_ASSERTS_ENABLED #define POLYVOX_THROW_ENABLED #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index b18e335a..13e95372 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -273,7 +273,7 @@ namespace PolyVox template void LargeVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - if((eWrapMode != None) && (eWrapMode != DontCheck)) + if((eWrapMode != WrapModes::None) && (eWrapMode != WrapModes::DontCheck)) { POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); } @@ -309,7 +309,7 @@ namespace PolyVox template void LargeVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode) { - setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); + setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eWrapMode); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index c30439dd..3b87a4d3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -203,7 +203,7 @@ namespace PolyVox template void RawVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - if((eWrapMode != None) && (eWrapMode != DontCheck)) + if((eWrapMode != WrapModes::None) && (eWrapMode != WrapModes::DontCheck)) { POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); } @@ -239,7 +239,7 @@ namespace PolyVox template void RawVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode) { - setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); + setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eWrapMode); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 26474a6e..ce0ed3b9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -203,7 +203,7 @@ namespace PolyVox template void SimpleVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - if((eWrapMode != None) && (eWrapMode != DontCheck)) + if((eWrapMode != WrapModes::None) && (eWrapMode != WrapModes::DontCheck)) { POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); } @@ -239,7 +239,7 @@ namespace PolyVox template void SimpleVolume::setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode) { - setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eBoundsCheck); + setVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue, eWrapMode); } //////////////////////////////////////////////////////////////////////////////// From 62f273bd74b6cc776efceadd3545c3baaecd776a Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 12 Jun 2013 16:52:17 +0200 Subject: [PATCH 30/64] Small changes, hoping to help the Linux version compile. --- library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl | 2 +- tests/TestAStarPathfinder.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl index 5c52cd07..9ecb80e7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl @@ -72,7 +72,7 @@ namespace PolyVox { for(int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++) { - const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz); + const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz, WrapModes::DontCheck); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues. const typename DstVolumeType::VoxelType& tDstVoxel = static_cast(tSrcVoxel); m_pVolDst->setVoxelAt(dx,dy,dz,tDstVoxel); } diff --git a/tests/TestAStarPathfinder.cpp b/tests/TestAStarPathfinder.cpp index a061bd40..120aa7ac 100644 --- a/tests/TestAStarPathfinder.cpp +++ b/tests/TestAStarPathfinder.cpp @@ -40,7 +40,7 @@ bool testVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos) return false; } - typename VolumeType::VoxelType voxel = volData->getVoxel(v3dPos); + typename VolumeType::VoxelType voxel = volData->getVoxel(v3dPos, WrapModes::None); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues. if(voxel != 0) { return false; From 6e8030f4b5f52b91c42984a71021ff51ed5dedc4 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 13 Jun 2013 15:55:15 +0200 Subject: [PATCH 31/64] Changes to hopefully fix Linux compile problems. --- .../include/PolyVoxCore/BaseVolumeSampler.inl | 10 ++--- tests/TestVolumeSubclass.cpp | 44 +++++++------------ 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index 6177aaf2..fa8d4895 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -57,7 +57,7 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::getVoxel(void) const { - return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume); + return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume, WrapModes::None); // FIXME - Use templatised version instead but watch for Linux compile errors. } template @@ -350,13 +350,13 @@ namespace PolyVox switch(m_eWrapMode) { case WrapModes::None: - return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::None, m_tBorder); case WrapModes::Clamp: - return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Clamp, m_tBorder); case WrapModes::Border: - return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Border, m_tBorder); case WrapModes::DontCheck: - return mVolume->getVoxel(uXPos, uYPos, uZPos, m_tBorder); + return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::DontCheck, m_tBorder); default: // Should never happen POLYVOX_ASSERT(false, "Invalid wrap mode"); diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index c37e4702..704d8ced 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -71,6 +71,22 @@ public: /// Gets a voxel at the position given by x,y,z coordinates template VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tBorder = VoxelType()) const + { + // FIXME: This templatised version is implemented in terms of the not template version. This is strange + // from a peformance point of view but it's just because we were encountering some compile issues on GCC. + return getVoxel(uXPos, uYPos, uZPos, eWrapMode, tBorder); + } + + /// Gets a voxel at the position given by a 3D vector + template + VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const + { + // Simply call through to the real implementation + return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder); + } + + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const { switch(eWrapMode) { @@ -118,34 +134,6 @@ public: } } - /// Gets a voxel at the position given by a 3D vector - template - VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const - { - // Simply call through to the real implementation - return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tBorder); - } - - /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const - { - switch(eWrapMode) - { - case WrapModes::None: - return getVoxel(uXPos, uYPos, uZPos, WrapModes::None, tBorder); - case WrapModes::Clamp: - return getVoxel(uXPos, uYPos, uZPos, WrapModes::Clamp, tBorder); - case WrapModes::Border: - return getVoxel(uXPos, uYPos, uZPos, WrapModes::Border, tBorder); - case WrapModes::DontCheck: - return getVoxel(uXPos, uYPos, uZPos, WrapModes::DontCheck, tBorder); - default: - // Should never happen - POLYVOX_ASSERT(false, "Invalid wrap mode"); - return VoxelType(); - } - } - /// Gets a voxel at the position given by a 3D vector VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const { From dc7c7eb552cec24357828e697ee5f3e337a6401d Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 13 Jun 2013 16:27:46 +0200 Subject: [PATCH 32/64] Removed old BoundsCheck enum. --- .../include/PolyVoxCore/BaseVolume.h | 19 ++----------------- .../include/PolyVoxCore/BaseVolume.inl | 16 ++-------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 390a4a6c..315e19ec 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -36,21 +36,6 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// More details to come... //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - namespace BoundsChecks - { - enum BoundsCheck - { - None = 0, - Full = 1, - ClampPos = 2, - BorderPos = 3 - }; - } - typedef BoundsChecks::BoundsCheck BoundsCheck; - - // Required for a trick to implement specialization of template member - // functions in template classes. See http://stackoverflow.com/a/4951057 - template struct BoundsCheckType{}; namespace WrapModes { @@ -189,9 +174,9 @@ namespace PolyVox /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, BoundsCheck eBoundsCheck = BoundsChecks::Full); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index a28eac7f..a78804ec 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -225,9 +225,6 @@ namespace PolyVox /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel /// \param uZPos The \c z position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -239,9 +236,6 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos The 3D position of the voxel - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. /// \return The voxel value //////////////////////////////////////////////////////////////////////////////// template @@ -265,12 +259,9 @@ namespace PolyVox /// \param uYPos the \c y position of the voxel /// \param uZPos the \c z position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template - void BaseVolume::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) + void BaseVolume::setVoxel(int32_t /*uXPos*/, int32_t /*uYPos*/, int32_t /*uZPos*/, VoxelType /*tValue*/, WrapMode /*eWrapMode*/) { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); } @@ -278,12 +269,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dPos the 3D position of the voxel /// \param tValue the value to which the voxel will be set - /// \param eBoundsCheck Controls whether bounds checking is performed on voxel access. It's safest to - /// set this to BoundsChecks::Full (the default), but if you are certain that the voxel you are accessing - /// is inside the volume's enclosing region then you can skip this check to gain some performance. //////////////////////////////////////////////////////////////////////////////// template - void BaseVolume::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, BoundsCheck /*eBoundsCheck*/) + void BaseVolume::setVoxel(const Vector3DInt32& /*v3dPos*/, VoxelType /*tValue*/, WrapMode /*eWrapMode*/) { POLYVOX_THROW(not_implemented, "You should never call the base class version of this function."); } From 1e5585910780034f6bd4bd08c759f46fcd011148 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 13 Jun 2013 16:49:02 +0200 Subject: [PATCH 33/64] Renamed WrapMode::None (and others) to avoid conflict with Python reserved word 'None'. --- .../include/PolyVoxCore/BaseVolume.h | 12 +++++----- .../include/PolyVoxCore/BaseVolumeSampler.inl | 10 ++++----- .../include/PolyVoxCore/ConstVolumeProxy.h | 4 ++-- .../include/PolyVoxCore/LargeVolume.h | 12 +++++----- .../include/PolyVoxCore/LargeVolume.inl | 22 +++++++++---------- .../include/PolyVoxCore/RawVolume.h | 12 +++++----- .../include/PolyVoxCore/RawVolume.inl | 22 +++++++++---------- .../include/PolyVoxCore/SimpleVolume.h | 12 +++++----- .../include/PolyVoxCore/SimpleVolume.inl | 22 +++++++++---------- .../include/PolyVoxCore/VolumeResampler.inl | 2 +- tests/TestAStarPathfinder.cpp | 2 +- tests/TestVolumeSubclass.cpp | 8 +++---- 12 files changed, 70 insertions(+), 70 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index 315e19ec..eeb3c50d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -41,10 +41,10 @@ namespace PolyVox { enum WrapMode { - None = 0, + Validate = 0, Clamp = 1, Border = 2, - DontCheck = 3 + AssumeValid = 3 }; } typedef WrapModes::WrapMode WrapMode; @@ -162,9 +162,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; @@ -174,9 +174,9 @@ namespace PolyVox /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl index fa8d4895..fedf56f6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolumeSampler.inl @@ -57,7 +57,7 @@ namespace PolyVox template VoxelType BaseVolume::Sampler::getVoxel(void) const { - return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume, WrapModes::None); // FIXME - Use templatised version instead but watch for Linux compile errors. + return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume, WrapModes::Validate); // FIXME - Use templatised version instead but watch for Linux compile errors. } template @@ -349,14 +349,14 @@ namespace PolyVox { switch(m_eWrapMode) { - case WrapModes::None: - return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::None, m_tBorder); + case WrapModes::Validate: + return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Validate, m_tBorder); case WrapModes::Clamp: return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Clamp, m_tBorder); case WrapModes::Border: return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::Border, m_tBorder); - case WrapModes::DontCheck: - return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::DontCheck, m_tBorder); + case WrapModes::AssumeValid: + return mVolume->getVoxel(uXPos, uYPos, uZPos, WrapModes::AssumeValid, m_tBorder); default: // Should never happen POLYVOX_ASSERT(false, "Invalid wrap mode"); diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h index 792f086a..751377ec 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h @@ -39,14 +39,14 @@ namespace PolyVox { // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); - return m_pVolume.getVoxel(uXPos, uYPos, uZPos); + return m_pVolume.getVoxel(uXPos, uYPos, uZPos); } VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const { // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region"); - return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index c61a1938..a7b7d72f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -273,9 +273,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; @@ -287,9 +287,9 @@ namespace PolyVox /// Sets the number of blocks which can be in memory before the paging system starts unloading them void setMaxNumberOfBlocksInMemory(uint32_t uMaxNumberOfBlocksInMemory); /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector @@ -337,10 +337,10 @@ namespace PolyVox // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 template VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; /// gets called when a new region is allocated and needs to be filled /// NOTE: accessing ANY voxels outside this region during the process of this function diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 13e95372..e9967114 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -166,14 +166,14 @@ namespace PolyVox { switch(eWrapMode) { - case WrapModes::None: - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Validate: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); case WrapModes::Clamp: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); case WrapModes::Border: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); - case WrapModes::DontCheck: - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::AssumeValid: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); default: // Should never happen POLYVOX_ASSERT(false, "Invalid wrap mode"); @@ -273,13 +273,13 @@ namespace PolyVox template void LargeVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - if((eWrapMode != WrapModes::None) && (eWrapMode != WrapModes::DontCheck)) + if((eWrapMode != WrapModes::Validate) && (eWrapMode != WrapModes::AssumeValid)) { POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); } // This validation is skipped if the wrap mode is 'DontCheck' - if(eWrapMode == WrapModes::None) + if(eWrapMode == WrapModes::Validate) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -754,14 +754,14 @@ namespace PolyVox } template - VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -775,7 +775,7 @@ namespace PolyVox uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -783,7 +783,7 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } else { @@ -792,7 +792,7 @@ namespace PolyVox } template - VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const + VoxelType LargeVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const { const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 019359f0..71f2be01 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -123,9 +123,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; @@ -133,9 +133,9 @@ namespace PolyVox POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector @@ -157,10 +157,10 @@ namespace PolyVox // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 template VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; //The block data VoxelType* m_pData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 3b87a4d3..c76601b8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -124,14 +124,14 @@ namespace PolyVox { switch(eWrapMode) { - case WrapModes::None: - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Validate: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); case WrapModes::Clamp: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); case WrapModes::Border: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); - case WrapModes::DontCheck: - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::AssumeValid: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); default: // Should never happen POLYVOX_ASSERT(false, "Invalid wrap mode"); @@ -203,13 +203,13 @@ namespace PolyVox template void RawVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - if((eWrapMode != WrapModes::None) && (eWrapMode != WrapModes::DontCheck)) + if((eWrapMode != WrapModes::Validate) && (eWrapMode != WrapModes::AssumeValid)) { POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); } // This validation is skipped if the wrap mode is 'DontCheck' - if(eWrapMode == WrapModes::None) + if(eWrapMode == WrapModes::Validate) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -334,14 +334,14 @@ namespace PolyVox } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -355,7 +355,7 @@ namespace PolyVox uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -363,7 +363,7 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } else { @@ -372,7 +372,7 @@ namespace PolyVox } template - VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const + VoxelType RawVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const { const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index d257123d..e8dda3e3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -162,9 +162,9 @@ namespace PolyVox VoxelType getVoxel(const Vector3DInt32& v3dPos, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const; + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const; /// Gets a voxel at the position given by x,y,z coordinates POLYVOX_DEPRECATED VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; @@ -172,9 +172,9 @@ namespace PolyVox POLYVOX_DEPRECATED VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the voxel at the position given by x,y,z coordinates - void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by a 3D vector - void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::None); + void setVoxel(const Vector3DInt32& v3dPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by x,y,z coordinates bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector @@ -196,10 +196,10 @@ namespace PolyVox // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 template VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; + VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index ce0ed3b9..f32aacdd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -124,14 +124,14 @@ namespace PolyVox { switch(eWrapMode) { - case WrapModes::None: - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::Validate: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); case WrapModes::Clamp: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); case WrapModes::Border: return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); - case WrapModes::DontCheck: - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); + case WrapModes::AssumeValid: + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); default: // Should never happen POLYVOX_ASSERT(false, "Invalid wrap mode"); @@ -203,13 +203,13 @@ namespace PolyVox template void SimpleVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode) { - if((eWrapMode != WrapModes::None) && (eWrapMode != WrapModes::DontCheck)) + if((eWrapMode != WrapModes::Validate) && (eWrapMode != WrapModes::AssumeValid)) { POLYVOX_THROW(std::invalid_argument, "Invalid wrap mode in call to setVoxel(). It must be 'None' or 'DontCheck'."); } // This validation is skipped if the wrap mode is 'DontCheck' - if(eWrapMode == WrapModes::None) + if(eWrapMode == WrapModes::Validate) { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -385,14 +385,14 @@ namespace PolyVox } template - VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); } - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -406,7 +406,7 @@ namespace PolyVox uYPos = (std::min)(uYPos, this->m_regValidRegion.getUpperY()); uZPos = (std::min)(uZPos, this->m_regValidRegion.getUpperZ()); - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } template @@ -414,7 +414,7 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) { - return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. + return getVoxelImpl(uXPos, uYPos, uZPos, WrapModeType(), tBorder); // No wrapping as we've just validated the position. } else { @@ -423,7 +423,7 @@ namespace PolyVox } template - VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const + VoxelType SimpleVolume::getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType /*tBorder*/) const { const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl index 9ecb80e7..2c6c129d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl @@ -72,7 +72,7 @@ namespace PolyVox { for(int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++) { - const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz, WrapModes::DontCheck); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues. + const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxel(sx,sy,sz, WrapModes::AssumeValid); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues. const typename DstVolumeType::VoxelType& tDstVoxel = static_cast(tSrcVoxel); m_pVolDst->setVoxelAt(dx,dy,dz,tDstVoxel); } diff --git a/tests/TestAStarPathfinder.cpp b/tests/TestAStarPathfinder.cpp index 120aa7ac..e36752f5 100644 --- a/tests/TestAStarPathfinder.cpp +++ b/tests/TestAStarPathfinder.cpp @@ -40,7 +40,7 @@ bool testVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos) return false; } - typename VolumeType::VoxelType voxel = volData->getVoxel(v3dPos, WrapModes::None); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues. + typename VolumeType::VoxelType voxel = volData->getVoxel(v3dPos, WrapModes::Validate); // FIXME use templatised version of getVoxel(), but watch out for Linux compile issues. if(voxel != 0) { return false; diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index 704d8ced..91a619b4 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -86,11 +86,11 @@ public: } /// Gets a voxel at the position given by x,y,z coordinates - VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const + VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const { switch(eWrapMode) { - case WrapModes::None: + case WrapModes::Validate: { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) { @@ -121,7 +121,7 @@ public: return tBorder; } } - case WrapModes::DontCheck: + case WrapModes::AssumeValid: { return mVolumeData[uXPos][uYPos][uZPos]; } @@ -135,7 +135,7 @@ public: } /// Gets a voxel at the position given by a 3D vector - VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::None, VoxelType tBorder = VoxelType()) const + VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) const { return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), eWrapMode, tBorder); } From a1d773f5e72ae79c0b036a7d5c9612b5c2fc8bd3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 16 Jun 2013 17:22:53 +0200 Subject: [PATCH 34/64] Added documentation on voxel access. --- documentation/Volumes.rst | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 documentation/Volumes.rst diff --git a/documentation/Volumes.rst b/documentation/Volumes.rst new file mode 100644 index 00000000..7cf7c82b --- /dev/null +++ b/documentation/Volumes.rst @@ -0,0 +1,62 @@ +******* +Volumes +******* +The volume classes are the heart and soul of Polyvox, providing storage for the huge amounts of data which volumetric environments often require. + +Volume concepts +=============== + +The main volume classes +======================= + +Basic access to volume data +=========================== +At the simplest level, individual voxels can be read and written by the getVoxel() and setVoxel() member functions which exist for each volume. We will focus on reading voxels first. + +Reading voxels +-------------- +The easiest way to read a particular voxel is as follows: + +.. sourcecode :: c++ + + RawVolume* volume = ... // Get a volume from somewhere. + uint8_t uVoxelValue = volume->getVoxel(x, y, z); // Read the voxel at the given position. + +This works great as long as the provided position (x, y, z) does actually represent a valid position inside the volume. If this is not the case then the default behaviour is to throw an exception, so you should be prepared to handle this if you are not certain the position is valid. + +Alternatively you can modify the behaviour which occurs when a position is outside the volume by providing a WrapMode as a fourth parameter to getVoxel(). For example: + +.. sourcecode :: c++ + + // This will return the voxel, or '42' if the position is outside the volume + uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::Border, 42); + + Please see the documentation for WrapMode for more information on the avaiable options here. Note in particular that WrapModes::AssumeValid can be used to skip any bounds checking and so you should use this *if you are certain* that you are accessing a valid position, as it may be noticably faster in some cases. + + .. sourcecode :: c++ + + // This will result in undefined behaviour if the position is outside the volume + uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::AssumeValid); + + Fast access to voxel data is very important in PolyVox, but the above functions have a drawback in that they need to contain logic to evaluate the provided WrapMode and decide how to proceed. This introduces branching into the execution flow and results in larger functions which may prevent inlining. For even more speed you can use version of the above functions which are templatised on the WrapMode rather than taking it as a parameter. This means the condition can be evaluated at compile time rather than run time: For example: + + .. sourcecode :: c++ + + // This will return the voxel, or '42' if the position is outside the volume + uint8_t uVoxelValue = volume->getVoxel(x, y, z, 42); + + Writing voxels + -------------- + The setVoxel() function is used for writting to voxels instread of reading from them, and besides this it has two main behavoural differences when compared to getVoxel(). The first difference is that it is not templatised because the speed of setVoxel() is typically less important than getVoxel() (as writing to voxels is much less common than reading from them). However, we could add these temlatised version in the future if they are needed. + + The second difference is that certain wrap modes such as WrapModes::Border or WrapModes::Clamp do not make much sense when writting to voxel data, and so these are no permitted and will result in an exception being thrown. You should only use WrapModes::Validate (the default) and WrapModes::AssumeValid. For example: + + .. sourcecode :: c++ + + RawVolume* volume = ... // Get a volume from somewhere. + volume->setVoxel(x, y, z, 57); // Write the voxel at the given position. + volume->setVoxel(x, y, z, 57, WrapMopdes::AssumeValid); // No bounds checks + + Notes on error handling and performance + --------------------------------------- + Overall, you should set the wrap mode to WrapModes::AssumeValid for maximum performance (and use templatised versions where available), but note that even this fast version does still contain a POLYVOX_ASSERT() to try and catch mistakes. It appears that this assert prevents inlining (probably due to the logging it performs), but it is anticipated that you will disable such asserts in the final build of your software. \ No newline at end of file From 42ce6ace77cba9b09ba6e2384db9eb8de0388aa0 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 16 Jun 2013 17:56:07 +0200 Subject: [PATCH 35/64] Updated change log. --- CHANGELOG.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 59c4042a..c8df1d8d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,10 @@ This release has focused on... (some introduction here). This line was added just for testing. +Voxel access +------------ +The getVoxelAt() and setVoxelAt() functions have been deprecated and replaced by getVoxel() and setVoxel(). These new functions provide more control over how edge cases are handled and can potentially be faster as well. Please see the 'Volumes' section of the user manual for more information about how voxel access should be performed. + LargeVolume ----------- It is now possible to provide custom compressors for the data which is stored in a LargeVolume. Two compressor implementation are provided with PolyVox - RLECompressor which is suitable for cubic-style terrain, and MinizCompressor which uses the 'miniz' zlib implementation for smooth terrain or general purpose use. Users can provide their own implementation of the compressor interface if they wish. @@ -14,13 +18,17 @@ These changes regarding compression and paging have also affected the LargeVolum Error Handling -------------- -PolyVox now has it's own POLYVOX_ASSERT() macro rather than using the standard assert(). This has some advantages such as allowing a message to be printed and providing file/line information, and it is also possible to enable/disable it independantly of whether you are making a debug or release build +PolyVox now has it's own POLYVOX_ASSERT() macro rather than using the standard assert(). This has some advantages such as allowing a message to be printed and providing file/line information, and it is also possible to enable/disable it independantly of whether you are making a debug or release build. + +A simple logging system has also been added, and the output can be redirected by user code. + +Please see the 'Error Handling' section of the user manual for more information about these changes. Volume wrap modes ----------------- This release has seen a overhaul of the way PolyVox handles voxel positions which are outside of the volume. It used to be the case that you could specify a border value which would be returned whenever an out-of-volume access was performed, but this was not flexible enough for all use cases. You can now choose between different wrapping modes (border, clamp, etc) and apply them to both the volume itself or to samplers. If you have multiple samplers pointing at the same volume then you can choose to have different wrap modes for each of them. -Within the Volume class the getVoxelAt() and setBorderValue() functions have been deprecated. You should now call getVoxel() (which does not perform range checking and will crash when out of range) or getVoxelWithWrapping() (which does perform bounds checks and implements the required wrapping). When you call getVoxelWithWrapping() you are able to specify the required wrap mode for that particular call. For a Sampler you can set the wrap mode once with setWrapMode() and it will persist until you set it again. +Within the Volume class the getVoxelAt() and setBorderValue() functions have been deprecated. Please see the 'Volumes' section of the user manual for more information about how voxel access should now be performed. Various algorithms have also been updated to allow wrap modes to be specified when executing them. From f86ec57e142bbd46822850d534538e03d7352a21 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 16 Jun 2013 18:25:20 +0200 Subject: [PATCH 36/64] Adding skeletons of new paging classes. --- .../include/PolyVoxCore/FilePager.h | 63 +++++++++++++++++++ .../PolyVoxCore/include/PolyVoxCore/Pager.h | 48 ++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/FilePager.h create mode 100644 library/PolyVoxCore/include/PolyVoxCore/Pager.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h new file mode 100644 index 00000000..49ac5637 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -0,0 +1,63 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_FilePager_H__ +#define __PolyVox_FilePager_H__ + +#include "PolyVoxCore/Impl/TypeDef.h" + +#include "PolyVoxCore/Pager.h" + +#include +#include + +namespace PolyVox +{ + /** + * Provides an interface for performing paging of data. + */ + class FilePager : public Pager + { + public: + /// Constructor + FilePager(const std::string& strFolderName) + :Pager() + { + } + + /// Destructor + virtual ~FilePager() {}; + + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + } + + virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + } + + protected: + std::string m_strFolderName; +} + +#endif //__PolyVox_FilePager_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h new file mode 100644 index 00000000..1281fdba --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -0,0 +1,48 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_Pager_H__ +#define __PolyVox_Pager_H__ + +#include "PolyVoxCore/Impl/TypeDef.h" + +#include "PolyVoxCore/ConstVolumeProxy.h" + +namespace PolyVox +{ + /** + * Provides an interface for performing paging of data. + */ + class Pager + { + public: + /// Constructor + Pager() {}; + /// Destructor + virtual ~Pager() {}; + + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region); + virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region); +} + +#endif //__PolyVox_Pager_H__ From 414a012230d59846e143db1ddc9dc3a4cfe07bc3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 16 Jun 2013 19:12:37 +0200 Subject: [PATCH 37/64] Creating a Perlin noise generator as a 'pager'. --- examples/Paging/main.cpp | 70 ++++++++++++++++++- .../include/PolyVoxCore/FilePager.h | 2 + .../include/PolyVoxCore/LargeVolume.h | 1 + .../include/PolyVoxCore/LargeVolume.inl | 2 + .../PolyVoxCore/include/PolyVoxCore/Pager.h | 2 + 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 20a272c6..ab40f514 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -27,6 +27,8 @@ freely, subject to the following restrictions: #include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" +#include "PolyVoxCore/Pager.h" +#include "PolyVoxCore/RLECompressor.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/LargeVolume.h" @@ -197,6 +199,68 @@ void createSphereInVolume(LargeVolume& volData, Vector3DF } } +/** + * Generates data using Perlin noise. + */ +class PerlinNoisePager : public PolyVox::Pager +{ +public: + /// Constructor + PerlinNoisePager() + :Pager() + { + } + + /// Destructor + virtual ~PerlinNoisePager() {}; + + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + Perlin perlin(2,2,1,234); + + for(int x = region.getLowerX(); x <= region.getUpperX(); x++) + { + for(int y = region.getLowerY(); y <= region.getUpperY(); y++) + { + float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); + perlinVal += 1.0f; + perlinVal *= 0.5f; + perlinVal *= 255; + for(int z = region.getLowerZ(); z <= region.getUpperZ(); z++) + { + MaterialDensityPair44 voxel; + if(z < perlinVal) + { + const int xpos = 50; + const int zpos = 100; + if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) { + // tunnel + voxel.setMaterial(0); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); + } else { + // solid + voxel.setMaterial(245); + voxel.setDensity(MaterialDensityPair44::getMaxDensity()); + } + } + else + { + voxel.setMaterial(0); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); + } + + volumeProxy.setVoxelAt(x, y, z, voxel); + } + } + } + } + + virtual void dataOverflowHandler(const ConstVolumeProxy& /*volumeProxy*/, const Region& region) + { + std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl; + } +}; + void load(const ConstVolumeProxy& volume, const PolyVox::Region& reg) { Perlin perlin(2,2,1,234); @@ -250,10 +314,12 @@ int main(int argc, char *argv[]) OpenGLWidget openGLWidget(0); openGLWidget.show(); + RLECompressor* compressor = new RLECompressor(); + //If these lines don't compile, please try commenting them out and using the two lines after //(you will need Boost for this). If you have to do this then please let us know in the forums as //we rely on community feedback to keep the Boost version running. - LargeVolume volData(&load, &unload, 256); + LargeVolume volData(compressor, &load, &unload, 64); //LargeVolume volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2), // polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256); volData.setMaxNumberOfBlocksInMemory(4096); @@ -269,7 +335,7 @@ 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; //volData.setBlockCacheSize(64); - PolyVox::Region reg(Vector3DInt32(-255,0,0), Vector3DInt32(255,255,255)); + PolyVox::Region reg(Vector3DInt32(-63,0,0), Vector3DInt32(63,63,255)); std::cout << "Prefetching region: " << reg.getLowerCorner() << " -> " << reg.getUpperCorner() << std::endl; volData.prefetch(reg); std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl; diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 49ac5637..ad259ace 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -36,6 +36,7 @@ namespace PolyVox /** * Provides an interface for performing paging of data. */ + template class FilePager : public Pager { public: @@ -58,6 +59,7 @@ namespace PolyVox protected: std::string m_strFolderName; + }; } #endif //__PolyVox_FilePager_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index a7b7d72f..ae504a20 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -248,6 +248,7 @@ namespace PolyVox /// Constructor for creating a very large paging volume. LargeVolume ( + Compressor* pCompressor, polyvox_function&, const Region&)> dataRequiredHandler, polyvox_function&, const Region&)> dataOverflowHandler, uint16_t uBlockSideLength = 32 diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index e9967114..4ea2b2af 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -37,11 +37,13 @@ namespace PolyVox template LargeVolume::LargeVolume ( + Compressor* pCompressor, polyvox_function&, const Region&)> dataRequiredHandler, polyvox_function&, const Region&)> dataOverflowHandler, uint16_t uBlockSideLength ) :BaseVolume(Region::MaxRegion) + ,m_pCompressor(pCompressor) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index 1281fdba..706640aa 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -33,6 +33,7 @@ namespace PolyVox /** * Provides an interface for performing paging of data. */ + template class Pager { public: @@ -43,6 +44,7 @@ namespace PolyVox virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region); virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region); + }; } #endif //__PolyVox_Pager_H__ From a14de4a72e554586804c9858aafbcd74b6a5c6dc Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 16 Jun 2013 19:48:14 +0200 Subject: [PATCH 38/64] Replaced std::functions with Pager class for paging. --- examples/OpenGL/main.cpp | 4 ++- examples/Paging/main.cpp | 5 ++-- .../include/PolyVoxCore/LargeVolume.h | 17 +++++------- .../include/PolyVoxCore/LargeVolume.inl | 27 +++++++------------ .../PolyVoxCore/include/PolyVoxCore/Pager.h | 11 ++++++-- tests/testvolume.cpp | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 5ed191f5..ccae9941 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -25,6 +25,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/LargeVolume.h" #include "PolyVoxCore/LowPassFilter.h" #include "PolyVoxCore/RawVolume.h" +#include "PolyVoxCore/RLECompressor.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/Impl/Utility.h" @@ -48,7 +49,8 @@ using namespace std; int main(int argc, char *argv[]) { - LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1))); + RLECompressor* compressor = new RLECompressor(); + LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, 0); //Make our volume contain a sphere in the center. int32_t minPos = 0; diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index ab40f514..8e6cba7f 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -314,12 +314,13 @@ int main(int argc, char *argv[]) OpenGLWidget openGLWidget(0); openGLWidget.show(); - RLECompressor* compressor = new RLECompressor(); + RLECompressor* compressor = new RLECompressor(); + PerlinNoisePager* pager = new PerlinNoisePager(); //If these lines don't compile, please try commenting them out and using the two lines after //(you will need Boost for this). If you have to do this then please let us know in the forums as //we rely on community feedback to keep the Boost version running. - LargeVolume volData(compressor, &load, &unload, 64); + LargeVolume volData(compressor, pager, 64); //LargeVolume volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2), // polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256); volData.setMaxNumberOfBlocksInMemory(4096); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index ae504a20..6de905b3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/BaseVolume.h" #include "Impl/Block.h" #include "PolyVoxCore/Compressor.h" +#include "PolyVoxCore/Pager.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Vector.h" @@ -249,18 +250,15 @@ namespace PolyVox LargeVolume ( Compressor* pCompressor, - polyvox_function&, const Region&)> dataRequiredHandler, - polyvox_function&, const Region&)> dataOverflowHandler, + Pager* pPager, uint16_t uBlockSideLength = 32 ); /// Constructor for creating a fixed size volume. LargeVolume ( const Region& regValid, - Compressor* pCompressor = 0, - polyvox_function&, const Region&)> dataRequiredHandler = 0, - polyvox_function&, const Region&)> dataOverflowHandler = 0, - bool bPagingEnabled = false, + Compressor* pCompressor, + Pager* pPager, uint16_t uBlockSideLength = 32 ); /// Destructor @@ -346,12 +344,12 @@ namespace PolyVox /// gets called when a new region is allocated and needs to be filled /// NOTE: accessing ANY voxels outside this region during the process of this function /// is absolutely unsafe - polyvox_function&, const Region&)> m_funcDataRequiredHandler; + //polyvox_function&, const Region&)> m_funcDataRequiredHandler; /// gets called when a Region needs to be stored by the user, because LargeVolume will erase it right after /// this function returns /// NOTE: accessing ANY voxels outside this region during the process of this function /// is absolutely unsafe - polyvox_function&, const Region&)> m_funcDataOverflowHandler; + //polyvox_function&, const Region&)> m_funcDataOverflowHandler; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; void eraseBlock(typename std::map::iterator itBlock) const; @@ -381,8 +379,7 @@ namespace PolyVox //The compressor used by the Blocks to compress their data if required. Compressor* m_pCompressor; - - bool m_bPagingEnabled; + Pager* m_pPager; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 4ea2b2af..7201836a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -38,16 +38,13 @@ namespace PolyVox LargeVolume::LargeVolume ( Compressor* pCompressor, - polyvox_function&, const Region&)> dataRequiredHandler, - polyvox_function&, const Region&)> dataOverflowHandler, + Pager* pPager, uint16_t uBlockSideLength ) :BaseVolume(Region::MaxRegion) ,m_pCompressor(pCompressor) { - m_funcDataRequiredHandler = dataRequiredHandler; - m_funcDataOverflowHandler = dataOverflowHandler; - m_bPagingEnabled = true; + m_pPager = pPager; //Create a volume of the right size. initialise(Region::MaxRegion,uBlockSideLength); } @@ -66,17 +63,13 @@ namespace PolyVox ( const Region& regValid, Compressor* pCompressor, - polyvox_function&, const Region&)> dataRequiredHandler, - polyvox_function&, const Region&)> dataOverflowHandler, - bool bPagingEnabled, + Pager* pPager, uint16_t uBlockSideLength ) :BaseVolume(regValid) ,m_pCompressor(pCompressor) { - m_funcDataRequiredHandler = dataRequiredHandler; - m_funcDataOverflowHandler = dataOverflowHandler; - m_bPagingEnabled = bPagingEnabled; + m_pPager = pPager; //Create a volume of the right size. initialise(regValid,uBlockSideLength); @@ -540,7 +533,7 @@ namespace PolyVox template void LargeVolume::eraseBlock(typename std::map::iterator itBlock) const { - if(m_funcDataOverflowHandler) + //if(m_funcDataOverflowHandler) { Vector3DInt32 v3dPos = itBlock->first; Vector3DInt32 v3dLower(v3dPos.getX() << m_uBlockSideLengthPower, v3dPos.getY() << m_uBlockSideLengthPower, v3dPos.getZ() << m_uBlockSideLengthPower); @@ -549,7 +542,7 @@ namespace PolyVox Region reg(v3dLower, v3dUpper); ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_funcDataOverflowHandler(ConstVolumeProxy, reg); + m_pPager->dataOverflowHandler(ConstVolumeProxy, reg); } if(m_pCompressor) { @@ -617,7 +610,7 @@ namespace PolyVox //The block is not in the map, so we will have to create a new block and add it. //Before we do so, we might want to dump some existing data to make space. We //Only do this if paging is enabled. - if(m_bPagingEnabled) + if(m_pPager) { // check wether another block needs to be unloaded before this one can be loaded if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory) @@ -648,9 +641,9 @@ namespace PolyVox //We have created the new block. If paging is enabled it should be used to //fill in the required data. Otherwise it is just left in the default state. - if(m_bPagingEnabled) + if(m_pPager) { - if(m_funcDataRequiredHandler) + //if(m_funcDataRequiredHandler) { // "load" will actually call setVoxel, which will in turn call this function again but the block will be found // so this if(itBlock == m_pBlocks.end()) never is entered @@ -659,7 +652,7 @@ namespace PolyVox Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_funcDataRequiredHandler(ConstVolumeProxy, reg); + m_pPager->dataRequiredHandler(ConstVolumeProxy, reg); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index 706640aa..893898bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -42,8 +42,15 @@ namespace PolyVox /// Destructor virtual ~Pager() {}; - virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region); - virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region); + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); + } + + virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); + } }; } diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index dd000a88..4a4d638d 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -277,7 +277,7 @@ TestVolume::TestVolume() //Create the volumes m_pRawVolume = new RawVolume(region); m_pSimpleVolume = new SimpleVolume(region); - m_pLargeVolume = new LargeVolume(region, m_pCompressor); + m_pLargeVolume = new LargeVolume(region, m_pCompressor, 0, 32); // LargeVolume currently fails a test if compression is enabled. It // may be related to accessing the data through more than one sampler? From 3e1539fc62ce3c574a438d4d72652df896081acf Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 17 Jun 2013 11:16:59 +0200 Subject: [PATCH 39/64] Fixed some formatting. --- documentation/Volumes.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/documentation/Volumes.rst b/documentation/Volumes.rst index 7cf7c82b..00681574 100644 --- a/documentation/Volumes.rst +++ b/documentation/Volumes.rst @@ -31,25 +31,25 @@ Alternatively you can modify the behaviour which occurs when a position is outsi // This will return the voxel, or '42' if the position is outside the volume uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::Border, 42); - Please see the documentation for WrapMode for more information on the avaiable options here. Note in particular that WrapModes::AssumeValid can be used to skip any bounds checking and so you should use this *if you are certain* that you are accessing a valid position, as it may be noticably faster in some cases. +Please see the documentation for WrapMode for more information on the avaiable options here. Note in particular that WrapModes::AssumeValid can be used to skip any bounds checking and so you should use this *if you are certain* that you are accessing a valid position, as it may be noticably faster in some cases. .. sourcecode :: c++ // This will result in undefined behaviour if the position is outside the volume uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::AssumeValid); - Fast access to voxel data is very important in PolyVox, but the above functions have a drawback in that they need to contain logic to evaluate the provided WrapMode and decide how to proceed. This introduces branching into the execution flow and results in larger functions which may prevent inlining. For even more speed you can use version of the above functions which are templatised on the WrapMode rather than taking it as a parameter. This means the condition can be evaluated at compile time rather than run time: For example: +Fast access to voxel data is very important in PolyVox, but the above functions have a drawback in that they need to contain logic to evaluate the provided WrapMode and decide how to proceed. This introduces branching into the execution flow and results in larger functions which may prevent inlining. For even more speed you can use version of the above functions which are templatised on the WrapMode rather than taking it as a parameter. This means the condition can be evaluated at compile time rather than run time: For example: .. sourcecode :: c++ // This will return the voxel, or '42' if the position is outside the volume uint8_t uVoxelValue = volume->getVoxel(x, y, z, 42); - Writing voxels - -------------- - The setVoxel() function is used for writting to voxels instread of reading from them, and besides this it has two main behavoural differences when compared to getVoxel(). The first difference is that it is not templatised because the speed of setVoxel() is typically less important than getVoxel() (as writing to voxels is much less common than reading from them). However, we could add these temlatised version in the future if they are needed. +Writing voxels +-------------- +The setVoxel() function is used for writting to voxels instread of reading from them, and besides this it has two main behavoural differences when compared to getVoxel(). The first difference is that it is not templatised because the speed of setVoxel() is typically less important than getVoxel() (as writing to voxels is much less common than reading from them). However, we could add these temlatised version in the future if they are needed. - The second difference is that certain wrap modes such as WrapModes::Border or WrapModes::Clamp do not make much sense when writting to voxel data, and so these are no permitted and will result in an exception being thrown. You should only use WrapModes::Validate (the default) and WrapModes::AssumeValid. For example: +The second difference is that certain wrap modes such as WrapModes::Border or WrapModes::Clamp do not make much sense when writting to voxel data, and so these are no permitted and will result in an exception being thrown. You should only use WrapModes::Validate (the default) and WrapModes::AssumeValid. For example: .. sourcecode :: c++ @@ -57,6 +57,6 @@ Alternatively you can modify the behaviour which occurs when a position is outsi volume->setVoxel(x, y, z, 57); // Write the voxel at the given position. volume->setVoxel(x, y, z, 57, WrapMopdes::AssumeValid); // No bounds checks - Notes on error handling and performance - --------------------------------------- - Overall, you should set the wrap mode to WrapModes::AssumeValid for maximum performance (and use templatised versions where available), but note that even this fast version does still contain a POLYVOX_ASSERT() to try and catch mistakes. It appears that this assert prevents inlining (probably due to the logging it performs), but it is anticipated that you will disable such asserts in the final build of your software. \ No newline at end of file +Notes on error handling and performance +--------------------------------------- +Overall, you should set the wrap mode to WrapModes::AssumeValid for maximum performance (and use templatised versions where available), but note that even this fast version does still contain a POLYVOX_ASSERT() to try and catch mistakes. It appears that this assert prevents inlining (probably due to the logging it performs), but it is anticipated that you will disable such asserts in the final build of your software. \ No newline at end of file From 6781462b592a06c103852379ff7ba8321b926aba Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 17 Jun 2013 11:19:36 +0200 Subject: [PATCH 40/64] More formatting fixes. --- documentation/Volumes.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/Volumes.rst b/documentation/Volumes.rst index 00681574..5249516f 100644 --- a/documentation/Volumes.rst +++ b/documentation/Volumes.rst @@ -33,14 +33,14 @@ Alternatively you can modify the behaviour which occurs when a position is outsi Please see the documentation for WrapMode for more information on the avaiable options here. Note in particular that WrapModes::AssumeValid can be used to skip any bounds checking and so you should use this *if you are certain* that you are accessing a valid position, as it may be noticably faster in some cases. - .. sourcecode :: c++ +.. sourcecode :: c++ // This will result in undefined behaviour if the position is outside the volume uint8_t uVoxelValue = volume->getVoxel(x, y, z, WrapModes::AssumeValid); Fast access to voxel data is very important in PolyVox, but the above functions have a drawback in that they need to contain logic to evaluate the provided WrapMode and decide how to proceed. This introduces branching into the execution flow and results in larger functions which may prevent inlining. For even more speed you can use version of the above functions which are templatised on the WrapMode rather than taking it as a parameter. This means the condition can be evaluated at compile time rather than run time: For example: - .. sourcecode :: c++ +.. sourcecode :: c++ // This will return the voxel, or '42' if the position is outside the volume uint8_t uVoxelValue = volume->getVoxel(x, y, z, 42); @@ -51,7 +51,7 @@ The setVoxel() function is used for writting to voxels instread of reading from The second difference is that certain wrap modes such as WrapModes::Border or WrapModes::Clamp do not make much sense when writting to voxel data, and so these are no permitted and will result in an exception being thrown. You should only use WrapModes::Validate (the default) and WrapModes::AssumeValid. For example: - .. sourcecode :: c++ +.. sourcecode :: c++ RawVolume* volume = ... // Get a volume from somewhere. volume->setVoxel(x, y, z, 57); // Write the voxel at the given position. From 20db75fb753b623b912fecc35e8d2b08418af814 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 07:24:19 +0200 Subject: [PATCH 41/64] Added null pointer check. Added files to CMakeLists.txt --- library/PolyVoxCore/CMakeLists.txt | 2 ++ library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 2c352a50..8366d527 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -57,6 +57,7 @@ SET(CORE_INC_FILES include/PolyVoxCore/DefaultIsQuadNeeded.h include/PolyVoxCore/DefaultMarchingCubesController.h include/PolyVoxCore/Density.h + include/PolyVoxCore/FilePager.h include/PolyVoxCore/GradientEstimators.h include/PolyVoxCore/GradientEstimators.inl include/PolyVoxCore/Interpolation.h @@ -72,6 +73,7 @@ SET(CORE_INC_FILES include/PolyVoxCore/Material.h include/PolyVoxCore/MaterialDensityPair.h include/PolyVoxCore/MinizCompressor.h + include/PolyVoxCore/Pager.h include/PolyVoxCore/PolyVoxForwardDeclarations.h include/PolyVoxCore/Picking.h include/PolyVoxCore/Picking.inl diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 7201836a..6322135b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -533,7 +533,7 @@ namespace PolyVox template void LargeVolume::eraseBlock(typename std::map::iterator itBlock) const { - //if(m_funcDataOverflowHandler) + if(m_pPager) { Vector3DInt32 v3dPos = itBlock->first; Vector3DInt32 v3dLower(v3dPos.getX() << m_uBlockSideLengthPower, v3dPos.getY() << m_uBlockSideLengthPower, v3dPos.getZ() << m_uBlockSideLengthPower); From 5664e2f68186ad84034b1004f565c56598ca1ccd Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 07:30:06 +0200 Subject: [PATCH 42/64] Restored Paging Example back to previous values. --- examples/Paging/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 8e6cba7f..81dc7534 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -320,7 +320,7 @@ int main(int argc, char *argv[]) //If these lines don't compile, please try commenting them out and using the two lines after //(you will need Boost for this). If you have to do this then please let us know in the forums as //we rely on community feedback to keep the Boost version running. - LargeVolume volData(compressor, pager, 64); + LargeVolume volData(compressor, pager, 256); //LargeVolume volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2), // polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256); volData.setMaxNumberOfBlocksInMemory(4096); @@ -336,7 +336,7 @@ 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; //volData.setBlockCacheSize(64); - PolyVox::Region reg(Vector3DInt32(-63,0,0), Vector3DInt32(63,63,255)); + PolyVox::Region reg(Vector3DInt32(-255,0,0), Vector3DInt32(255,255,255)); std::cout << "Prefetching region: " << reg.getLowerCorner() << " -> " << reg.getUpperCorner() << std::endl; volData.prefetch(reg); std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl; From 77a340f2b352958cf48c1e5585368b065068c23d Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 08:02:07 +0000 Subject: [PATCH 43/64] ErrorHandling.rst edited online with Bitbucket The was an extra bracket in the documentation. --- documentation/ErrorHandling.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/ErrorHandling.rst b/documentation/ErrorHandling.rst index 88537a22..b9e8d32e 100644 --- a/documentation/ErrorHandling.rst +++ b/documentation/ErrorHandling.rst @@ -41,7 +41,7 @@ Or you could direct it to std::cout with: .. sourcecode :: c++ - setTraceStream(&(std::cout))); + setTraceStream(&(std::cout)); Note that by default the fatal, error and warning streams go to std::cerr, the info stream goes to std:cout, and the debug and trace streams are suppressed. From 288b448b9f9a5a80052f3bf43e534e51c74adf63 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 10:16:16 +0200 Subject: [PATCH 44/64] Brought across Region operator<< from Cubiquity branch. --- library/PolyVoxCore/include/PolyVoxCore/Region.h | 4 ++++ library/PolyVoxCore/source/Region.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 655b3bce..4fe45a7e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -202,6 +202,10 @@ namespace PolyVox int32_t m_iUpperZ; }; + // Non-member overloaded operators. + /// Stream insertion operator. + std::ostream& operator<<(std::ostream& os, const Region& region); + // Functions to be inlined to to be in the header rather than the .cpp. // 'inline' keyword is used for the definition rather than the declaration. // See also http://www.parashift.com/c++-faq-lite/inline-functions.html diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 444a1770..2f61f63a 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -487,4 +487,17 @@ namespace PolyVox { shrink(v3dAmount.getX(), v3dAmount.getY(), v3dAmount.getZ()); } -} + + /** + * Enables the Region to be used intuitively with output streams such as cout. + * \param os The output stream to write to. + * \param region The Region to write to the stream. + * \return A reference to the output stream to allow chaining. + */ + std::ostream& operator<<(std::ostream& os, const Region& region) + { + os << "(" << region.getLowerX() << "," << region.getLowerY() << "," << region.getLowerZ() << + ") to (" << region.getUpperX() << "," << region.getUpperY() << "," << region.getUpperZ() << ")"; + return os; + } +} \ No newline at end of file From d9ebe96c5abdf3a8c1daa75aba63f407ba06045d Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 10:16:33 +0200 Subject: [PATCH 45/64] Work on FilePager. --- .../include/PolyVoxCore/FilePager.h | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index ad259ace..8ba7a081 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -29,6 +29,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Pager.h" #include +#include #include namespace PolyVox @@ -37,18 +38,85 @@ namespace PolyVox * Provides an interface for performing paging of data. */ template - class FilePager : public Pager + class FilePager : public Pager { public: /// Constructor FilePager(const std::string& strFolderName) :Pager() + ,m_strFolderName(strFolderName) { } /// Destructor virtual ~FilePager() {}; + virtual void pageIn(const Region& region, Block* pBlockData) + { + POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); + POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page in uncompressed block"); + + std::stringstream ss; + ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_" + << region.getUpperX() << "_" << region.getUpperY() << "_" << region.getUpperZ(); + + std::string filename = m_strFolderName + ss.str(); + + // FIXME - This should be replaced by C++ style IO, but currently this causes problems with + // the gameplay-cubiquity integration. See: https://github.com/blackberry/GamePlay/issues/919 + + FILE* pFile = fopen(filename.c_str(), "rb"); + if(pFile) + { + logTrace() << "Paging in data for " << region; + + fread(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile); + + if(ferror(pFile)) + { + POLYVOX_THROW(std::runtime_error, "Error reading in block data, even though a file exists."); + } + + fclose(pFile); + } + else + { + logTrace() << "No data found for " << region << " during paging in."; + } + } + + virtual void pageOut(const Region& region, Block* pBlockData) + { + POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); + POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page out uncompressed block"); + + logTrace() << "Paging out data for " << region; + + std::stringstream ss; + ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_" + << region.getUpperX() << "_" << region.getUpperY() << "_" << region.getUpperZ(); + + std::string filename = m_strFolderName + ss.str(); + + // FIXME - This should be replaced by C++ style IO, but currently this causes problems with + // the gameplay-cubiquity integration. See: https://github.com/blackberry/GamePlay/issues/919 + + FILE* pFile = fopen(filename.c_str(), "wb"); + if(!pFile) + { + POLYVOX_THROW(std::runtime_error, "Unable to open file to write out block data."); + } + + fwrite(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile); + + if(ferror(pFile)) + { + POLYVOX_THROW(std::runtime_error, "Error writing out block data."); + } + + fclose(pFile); + } + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) { } From 564314088263887504b3db376ae4b20bb7a0d750 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 11:19:30 +0200 Subject: [PATCH 46/64] Work on paging to file. --- library/PolyVoxCore/include/PolyVoxCore/FilePager.h | 7 +++++++ library/PolyVoxCore/include/PolyVoxCore/Pager.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 8ba7a081..5e28782d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -70,6 +70,13 @@ namespace PolyVox { logTrace() << "Paging in data for " << region; + fseek(pFile, 0L, SEEK_END); + pBlockData->m_uCompressedDataLength = ftell(pFile); + fseek(pFile, 0L, SEEK_SET); + + delete[] pBlockData->m_pCompressedData; + pBlockData->m_pCompressedData = new uint8_t[pBlockData->m_uCompressedDataLength]; + fread(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile); if(ferror(pFile)) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index 893898bb..13f4ad19 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -24,6 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Pager_H__ #define __PolyVox_Pager_H__ +#include "PolyVoxCore/Impl/Block.h" #include "PolyVoxCore/Impl/TypeDef.h" #include "PolyVoxCore/ConstVolumeProxy.h" @@ -42,6 +43,9 @@ namespace PolyVox /// Destructor virtual ~Pager() {}; + virtual void pageIn(const Region& region, Block* pBlockData) = 0; + virtual void pageOut(const Region& region, Block* pBlockData) = 0; + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) { POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); From 785ac611b959bba697a72cf84a7baac61c8a44f4 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 11:20:05 +0200 Subject: [PATCH 47/64] Work on file paging. --- examples/Paging/main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 81dc7534..4622764c 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -214,6 +214,18 @@ public: /// Destructor virtual ~PerlinNoisePager() {}; + virtual void pageIn(const Region& region, Block* pBlockData) + { + POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); + + + } + + virtual void pageOut(const Region& region, Block* pBlockData) + { + std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl; + } + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) { Perlin perlin(2,2,1,234); From e80fa3de7dd5636ad5774d6893d4e47fd7f53c6c Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 12:16:52 +0200 Subject: [PATCH 48/64] Added functions for accessing compressed data in block. --- .../include/PolyVoxCore/Impl/Block.h | 3 ++ .../include/PolyVoxCore/Impl/Block.inl | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 1f7b71d5..93a9c0f0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -51,10 +51,13 @@ namespace PolyVox public: Block(uint16_t uSideLength = 0); + const uint8_t* getCompressedData(void) const; + const uint32_t getCompressedDataLength(void) const; uint16_t getSideLength(void) const; VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxel(const Vector3DUint16& v3dPos) const; + void setCompressedData(const uint8_t* const data, uint32_t dataLength); void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 61c9baac..64fbe33b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -51,6 +51,24 @@ namespace PolyVox } } + template + const uint8_t* Block::getCompressedData(void) const + { + POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); + POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); + + return m_pCompressedData; + } + + template + const uint32_t Block::getCompressedDataLength(void) const + { + POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); + POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); + + return m_uCompressedDataLength; + } + template uint16_t Block::getSideLength(void) const { @@ -64,6 +82,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call getVoxel() when a block is compressed"); POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); return m_tUncompressedData @@ -80,6 +99,20 @@ namespace PolyVox return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } + template + void Block::setCompressedData(const uint8_t* const data, uint32_t dataLength) + { + POLYVOX_ASSERT(m_bIsCompressed, "You cannot call setCompressedData() when the block is not compressed"); + POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); + POLYVOX_ASSERT(m_pCompressedData != data, "Attempting to copy data onto itself"); + + delete[] m_pCompressedData; + + m_uCompressedDataLength = dataLength; + m_pCompressedData = new uint8_t[dataLength]; + memcpy(m_pCompressedData, data, dataLength); + } + template void Block::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue) { @@ -87,6 +120,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call setVoxelAt() when a block is compressed"); POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); m_tUncompressedData From 59505d47e9509dd8a8c25dede649294aa9782d26 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 23 Jun 2013 23:17:40 +0200 Subject: [PATCH 49/64] Tidying up Block and FilePager. --- examples/Basic/main.cpp | 24 +++++++++++++++---- .../include/PolyVoxCore/FilePager.h | 18 +++++++------- .../include/PolyVoxCore/Impl/Block.h | 4 +++- .../include/PolyVoxCore/Impl/Block.inl | 8 ++++++- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index e7359f52..40bf0058 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -26,14 +26,17 @@ freely, subject to the following restrictions: #include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxCore/SimpleVolume.h" +//#include "PolyVoxCore/SimpleVolume.h" +#include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxCore/RLECompressor.h" +#include "PolyVoxCore/FilePager.h" #include //Use the PolyVox namespace using namespace PolyVox; -void createSphereInVolume(SimpleVolume& volData, float fRadius) +void createSphereInVolume(LargeVolume& volData, float fRadius) { //This vector hold the position of the center of the volume Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); @@ -68,21 +71,32 @@ void createSphereInVolume(SimpleVolume& volData, float fRadius) int main(int argc, char *argv[]) { + setTraceStream(&(std::cout)); + setDebugStream(&(std::cout)); + setInfoStream(&(std::cout)); + //Create and show the Qt OpenGL window QApplication app(argc, argv); OpenGLWidget openGLWidget(0); openGLWidget.show(); //Create an empty volume and then place a sphere in it - SimpleVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); + RLECompressor* pCompressor = new RLECompressor(); + FilePager* pFilePager = new FilePager("D:/temp/voldata/"); + + LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32); + //volData.setMaxNumberOfUncompressedBlocks(6); + //volData.setMaxNumberOfBlocksInMemory(7); + + createSphereInVolume(volData, 30); //A mesh object to hold the result of surface extraction SurfaceMesh mesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - CubicSurfaceExtractorWithNormals< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); - //MarchingCubesSurfaceExtractor< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + CubicSurfaceExtractorWithNormals< LargeVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + //MarchingCubesSurfaceExtractor< LargeVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); //Execute the surface extractor. surfaceExtractor.execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 5e28782d..97b9f2cc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -54,7 +54,7 @@ namespace PolyVox virtual void pageIn(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); - POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page in uncompressed block"); + POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page in uncompressed block"); std::stringstream ss; ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_" @@ -71,13 +71,13 @@ namespace PolyVox logTrace() << "Paging in data for " << region; fseek(pFile, 0L, SEEK_END); - pBlockData->m_uCompressedDataLength = ftell(pFile); + size_t fileSizeInBytes = ftell(pFile); fseek(pFile, 0L, SEEK_SET); - - delete[] pBlockData->m_pCompressedData; - pBlockData->m_pCompressedData = new uint8_t[pBlockData->m_uCompressedDataLength]; - - fread(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile); + + uint8_t* buffer = new uint8_t[fileSizeInBytes]; + fread(buffer, sizeof(uint8_t), fileSizeInBytes, pFile); + pBlockData->setCompressedData(buffer, fileSizeInBytes); + delete[] buffer; if(ferror(pFile)) { @@ -95,7 +95,7 @@ namespace PolyVox virtual void pageOut(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); - POLYVOX_ASSERT(pBlockData->m_bIsCompressed, "Attempting to page out uncompressed block"); + POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page out uncompressed block"); logTrace() << "Paging out data for " << region; @@ -114,7 +114,7 @@ namespace PolyVox POLYVOX_THROW(std::runtime_error, "Unable to open file to write out block data."); } - fwrite(pBlockData->m_pCompressedData, sizeof(uint8_t), pBlockData->m_uCompressedDataLength, pFile); + fwrite(pBlockData->getCompressedData(), sizeof(uint8_t), pBlockData->getCompressedDataLength(), pFile); if(ferror(pFile)) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 93a9c0f0..8c3b68bd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -51,12 +51,14 @@ namespace PolyVox public: Block(uint16_t uSideLength = 0); - const uint8_t* getCompressedData(void) const; + const uint8_t* const getCompressedData(void) const; const uint32_t getCompressedDataLength(void) const; uint16_t getSideLength(void) const; VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxel(const Vector3DUint16& v3dPos) const; + bool isCompressed(void); + void setCompressedData(const uint8_t* const data, uint32_t dataLength); void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 64fbe33b..c2f38883 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -52,7 +52,7 @@ namespace PolyVox } template - const uint8_t* Block::getCompressedData(void) const + const uint8_t* const Block::getCompressedData(void) const { POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); @@ -99,6 +99,12 @@ namespace PolyVox return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } + template + bool Block::isCompressed(void) + { + return m_bIsCompressed; + } + template void Block::setCompressedData(const uint8_t* const data, uint32_t dataLength) { From c346d19d77da28c322ce667dec43560d4549a4f5 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 25 Jun 2013 16:20:58 +0200 Subject: [PATCH 50/64] Doing some tidying in the Block class. --- .../include/PolyVoxCore/Impl/Block.h | 11 ----- .../include/PolyVoxCore/Impl/Block.inl | 41 ++++++++----------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 8c3b68bd..8bc6c5fd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -37,17 +37,6 @@ namespace PolyVox template class Block { - template - struct RunlengthEntry - { - LengthType length; - VoxelType value; - - //We can parametise the length on anything up to uint32_t. - //This lets us experiment with the optimal size in the future. - static uint32_t maxRunlength(void) {return (std::numeric_limits::max)();} - }; - public: Block(uint16_t uSideLength = 0); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index c2f38883..edba9045 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -45,10 +45,25 @@ namespace PolyVox ,m_bIsCompressed(false) ,m_bIsUncompressedDataModified(true) { - if(uSideLength != 0) + if(uSideLength == 0) { - initialise(uSideLength); + POLYVOX_THROW(std::invalid_argument, "Block side cannot be zero."); } + + if(!isPowerOf2(uSideLength)) + { + POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); + } + + //Compute the side length + m_uSideLength = uSideLength; + m_uSideLengthPower = logBase2(uSideLength); + + //Create the block data + const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; + m_tUncompressedData = new VoxelType[uNoOfVoxels]; + std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, VoxelType()); + m_bIsUncompressedDataModified = true; } template @@ -145,28 +160,6 @@ namespace PolyVox setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); } - template - void Block::initialise(uint16_t uSideLength) - { - //Release mode validation - if(!isPowerOf2(uSideLength)) - { - POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); - } - - //Compute the side length - m_uSideLength = uSideLength; - m_uSideLengthPower = logBase2(uSideLength); - - //Create the block data - m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; - - //Clear it (should we bother?) - const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; - std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, VoxelType()); - m_bIsUncompressedDataModified = true; - } - template uint32_t Block::calculateSizeInBytes(void) { From baed7ddccc172b3989cf5d746b8179b7984f8284 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 25 Jun 2013 16:45:53 +0200 Subject: [PATCH 51/64] Tidying up and refactoring of block class. --- .../include/PolyVoxCore/Impl/Block.h | 7 ++-- .../include/PolyVoxCore/Impl/Block.inl | 36 +++++++++---------- .../include/PolyVoxCore/LargeVolume.h | 4 +-- .../include/PolyVoxCore/LargeVolume.inl | 12 +++---- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 8bc6c5fd..2d4cfeee 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -38,7 +38,7 @@ namespace PolyVox class Block { public: - Block(uint16_t uSideLength = 0); + Block(uint16_t uSideLength, Compressor* pCompressor); const uint8_t* const getCompressedData(void) const; const uint32_t getCompressedDataLength(void) const; @@ -56,9 +56,10 @@ namespace PolyVox uint32_t calculateSizeInBytes(void); public: - void compress(Compressor* pCompressor); - void uncompress(Compressor* pCompressor); + void compress(); + void uncompress(); + Compressor* m_pCompressor; uint8_t* m_pCompressedData; uint32_t m_uCompressedDataLength; VoxelType* m_tUncompressedData; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index edba9045..8a75beab 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -36,8 +36,9 @@ freely, subject to the following restrictions: namespace PolyVox { template - Block::Block(uint16_t uSideLength) - :m_pCompressedData(0) + Block::Block(uint16_t uSideLength, Compressor* pCompressor) + :m_pCompressor(pCompressor) + ,m_pCompressedData(0) ,m_uCompressedDataLength(0) ,m_tUncompressedData(0) ,m_uSideLength(0) @@ -47,7 +48,7 @@ namespace PolyVox { if(uSideLength == 0) { - POLYVOX_THROW(std::invalid_argument, "Block side cannot be zero."); + POLYVOX_THROW(std::invalid_argument, "Block side length cannot be zero."); } if(!isPowerOf2(uSideLength)) @@ -55,6 +56,11 @@ namespace PolyVox POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } + if(pCompressor == 0) + { + POLYVOX_THROW(std::invalid_argument, "Block must be provided with a valid compressor."); + } + //Compute the side length m_uSideLength = uSideLength; m_uSideLengthPower = logBase2(uSideLength); @@ -169,18 +175,13 @@ namespace PolyVox } template - void Block::compress(Compressor* pCompressor) + void Block::compress() { if(m_bIsCompressed) { POLYVOX_THROW(invalid_operation, "Attempted to compress block which is already flagged as compressed."); } - if(!pCompressor) - { - POLYVOX_THROW(std::invalid_argument, "A valid compressor must be provided"); - } - POLYVOX_ASSERT(m_tUncompressedData != 0, "No uncompressed data is present."); //If the uncompressed data hasn't actually been @@ -202,7 +203,7 @@ namespace PolyVox try { - uCompressedLength = pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength); + uCompressedLength = m_pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength); // Create new compressed data and copy across m_pCompressedData = new uint8_t[uCompressedLength]; @@ -214,7 +215,9 @@ namespace PolyVox // It is possible for the compression to fail. A common cause for this would be if the destination // buffer is not big enough. So now we try again using a buffer that is definitely big enough. // Note that ideally we will choose our earlier buffer size so that this almost never happens. - uint32_t uMaxCompressedSize = pCompressor->getMaxCompressedSize(uSrcLength); + logWarning() << "The compressor failed to compress the block, proabaly due to the buffer being too small."; + logWarning() << "The compression will be tried again with a larger buffer"; + uint32_t uMaxCompressedSize = m_pCompressor->getMaxCompressedSize(uSrcLength); uint8_t* buffer = new uint8_t[ uMaxCompressedSize ]; pDstData = reinterpret_cast( buffer ); @@ -222,7 +225,7 @@ namespace PolyVox try { - uCompressedLength = pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength); + uCompressedLength = m_pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength); // Create new compressed data and copy across m_pCompressedData = new uint8_t[uCompressedLength]; @@ -248,18 +251,13 @@ namespace PolyVox } template - void Block::uncompress(Compressor* pCompressor) + void Block::uncompress() { if(!m_bIsCompressed) { POLYVOX_THROW(invalid_operation, "Attempted to uncompress block which is not flagged as compressed."); } - if(!pCompressor) - { - POLYVOX_THROW(std::invalid_argument, "A valid compressor must be provided"); - } - POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists."); m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; @@ -271,7 +269,7 @@ namespace PolyVox //MinizCompressor compressor; //RLECompressor compressor; - uint32_t uUncompressedLength = pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength); + uint32_t uUncompressedLength = m_pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength); POLYVOX_ASSERT(uUncompressedLength == m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType), "Destination length has changed."); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 6de905b3..8e46cb79 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -234,8 +234,8 @@ namespace PolyVox struct LoadedBlock { public: - LoadedBlock(uint16_t uSideLength = 0) - :block(uSideLength) + LoadedBlock(uint16_t uSideLength, Compressor* pCompressor) + :block(uSideLength, pCompressor) ,timestamp(0) { } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 6322135b..9fc1d7c1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -471,7 +471,7 @@ namespace PolyVox { for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) { - m_vecUncompressedBlockCache[ct]->block.compress(m_pCompressor); + m_vecUncompressedBlockCache[ct]->block.compress(); } m_vecUncompressedBlockCache.clear(); } @@ -552,7 +552,7 @@ namespace PolyVox if(m_vecUncompressedBlockCache[ct] == &(itBlock->second)) { // TODO: compression is unneccessary? or will not compressing this cause a memleak? - itBlock->second.block.compress(m_pCompressor); + itBlock->second.block.compress(); // put last object in cache here m_vecUncompressedBlockCache[ct] = m_vecUncompressedBlockCache.back(); // decrease cache size by one since last element is now in here twice @@ -630,12 +630,12 @@ namespace PolyVox } // create the new block - LoadedBlock newBlock(m_uBlockSideLength); + LoadedBlock newBlock(m_uBlockSideLength, m_pCompressor); // Blocks start out compressed - should we change this? // Or maybe we should just 'seed' them with compressed data, // rather than creating an empty block and then compressing? - newBlock.block.compress(m_pCompressor); + newBlock.block.compress(); itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; @@ -688,7 +688,7 @@ namespace PolyVox } //Compress the least recently used block. - m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress(m_pCompressor); + m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress(); //We don't actually remove any elements from this vector, we //simply change the pointer to point at the new uncompressed bloack. @@ -699,7 +699,7 @@ namespace PolyVox m_vecUncompressedBlockCache.push_back(&loadedBlock); } - loadedBlock.block.uncompress(m_pCompressor); + loadedBlock.block.uncompress(); m_pLastAccessedBlock = &(loadedBlock.block); POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); From 6b92a5ab51f112f25437139cea52a20915006e47 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 25 Jun 2013 17:04:10 +0200 Subject: [PATCH 52/64] More tidying/refaxctoring of Block class. --- .../include/PolyVoxCore/FilePager.h | 2 -- .../include/PolyVoxCore/Impl/Block.h | 3 +-- .../include/PolyVoxCore/Impl/Block.inl | 24 +++++++------------ .../include/PolyVoxCore/LargeVolume.inl | 2 +- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 97b9f2cc..07dc94e1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -54,7 +54,6 @@ namespace PolyVox virtual void pageIn(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); - POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page in uncompressed block"); std::stringstream ss; ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_" @@ -95,7 +94,6 @@ namespace PolyVox virtual void pageOut(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); - POLYVOX_ASSERT(pBlockData->isCompressed(), "Attempting to page out uncompressed block"); logTrace() << "Paging out data for " << region; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 2d4cfeee..cc6253b6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -46,7 +46,7 @@ namespace PolyVox VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxel(const Vector3DUint16& v3dPos) const; - bool isCompressed(void); + bool hasUncompressedData(void) const; void setCompressedData(const uint8_t* const data, uint32_t dataLength); void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); @@ -65,7 +65,6 @@ namespace PolyVox VoxelType* m_tUncompressedData; uint16_t m_uSideLength; uint8_t m_uSideLengthPower; - bool m_bIsCompressed; bool m_bIsUncompressedDataModified; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 8a75beab..39bddb3a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -43,7 +43,6 @@ namespace PolyVox ,m_tUncompressedData(0) ,m_uSideLength(0) ,m_uSideLengthPower(0) - ,m_bIsCompressed(false) ,m_bIsUncompressedDataModified(true) { if(uSideLength == 0) @@ -75,18 +74,14 @@ namespace PolyVox template const uint8_t* const Block::getCompressedData(void) const { - POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); - return m_pCompressedData; } template const uint32_t Block::getCompressedDataLength(void) const { - POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); - return m_uCompressedDataLength; } @@ -103,7 +98,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); - POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call getVoxel() when a block is compressed"); + POLYVOX_ASSERT(hasUncompressedData(), "The block must have uncompressed data to call getVoxel()"); POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); return m_tUncompressedData @@ -121,15 +116,14 @@ namespace PolyVox } template - bool Block::isCompressed(void) + bool Block::hasUncompressedData(void) const { - return m_bIsCompressed; + return m_tUncompressedData != 0; } template void Block::setCompressedData(const uint8_t* const data, uint32_t dataLength) { - POLYVOX_ASSERT(m_bIsCompressed, "You cannot call setCompressedData() when the block is not compressed"); POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); POLYVOX_ASSERT(m_pCompressedData != data, "Attempting to copy data onto itself"); @@ -147,7 +141,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); - POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call setVoxelAt() when a block is compressed"); + POLYVOX_ASSERT(hasUncompressedData(), "The block must have uncompressed data to call setVoxelAt()"); POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); m_tUncompressedData @@ -177,9 +171,9 @@ namespace PolyVox template void Block::compress() { - if(m_bIsCompressed) + if(!hasUncompressedData()) { - POLYVOX_THROW(invalid_operation, "Attempted to compress block which is already flagged as compressed."); + POLYVOX_THROW(invalid_operation, "No uncompressed data to compress."); } POLYVOX_ASSERT(m_tUncompressedData != 0, "No uncompressed data is present."); @@ -247,15 +241,14 @@ namespace PolyVox //Flag the uncompressed data as no longer being used. delete[] m_tUncompressedData; m_tUncompressedData = 0; - m_bIsCompressed = true; } template void Block::uncompress() { - if(!m_bIsCompressed) + if(hasUncompressedData()) { - POLYVOX_THROW(invalid_operation, "Attempted to uncompress block which is not flagged as compressed."); + POLYVOX_THROW(invalid_operation, "Uncompressed data already exists."); } POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists."); @@ -275,7 +268,6 @@ namespace PolyVox //m_tUncompressedData = reinterpret_cast(uncompressedResult.ptr); - m_bIsCompressed = false; m_bIsUncompressedDataModified = false; } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 9fc1d7c1..47746f4d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -663,7 +663,7 @@ namespace PolyVox m_v3dLastAccessedBlockPos = v3dBlockPos; m_pLastAccessedBlock = &(loadedBlock.block); - if(loadedBlock.block.m_bIsCompressed == false) + if(loadedBlock.block.hasUncompressedData()) { POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); return m_pLastAccessedBlock; From a2210fc3f01d1ac484a0b5ea27fd25c777da23af Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 25 Jun 2013 20:57:50 +0200 Subject: [PATCH 53/64] Renamed compress and uncompress functions. --- .../include/PolyVoxCore/Impl/Block.h | 7 +++---- .../include/PolyVoxCore/Impl/Block.inl | 20 +++++++++---------- .../include/PolyVoxCore/LargeVolume.inl | 10 +++++----- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index cc6253b6..ed9ca146 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -52,13 +52,12 @@ namespace PolyVox void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); - void initialise(uint16_t uSideLength); + void createUncompressedData(void); + void destroyUncompressedData(void); + uint32_t calculateSizeInBytes(void); public: - void compress(); - void uncompress(); - Compressor* m_pCompressor; uint8_t* m_pCompressedData; uint32_t m_uCompressedDataLength; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 39bddb3a..cf103eaa 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -161,15 +161,7 @@ namespace PolyVox } template - uint32_t Block::calculateSizeInBytes(void) - { - //FIXME - This function is incomplete. - uint32_t uSizeInBytes = sizeof(Block); - return uSizeInBytes; - } - - template - void Block::compress() + void Block::destroyUncompressedData() { if(!hasUncompressedData()) { @@ -244,7 +236,7 @@ namespace PolyVox } template - void Block::uncompress() + void Block::createUncompressedData() { if(hasUncompressedData()) { @@ -270,4 +262,12 @@ namespace PolyVox m_bIsUncompressedDataModified = false; } + + template + uint32_t Block::calculateSizeInBytes(void) + { + //FIXME - This function is incomplete. + uint32_t uSizeInBytes = sizeof(Block); + return uSizeInBytes; + } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 47746f4d..b49ce49f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -471,7 +471,7 @@ namespace PolyVox { for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) { - m_vecUncompressedBlockCache[ct]->block.compress(); + m_vecUncompressedBlockCache[ct]->block.destroyUncompressedData(); } m_vecUncompressedBlockCache.clear(); } @@ -552,7 +552,7 @@ namespace PolyVox if(m_vecUncompressedBlockCache[ct] == &(itBlock->second)) { // TODO: compression is unneccessary? or will not compressing this cause a memleak? - itBlock->second.block.compress(); + itBlock->second.block.destroyUncompressedData(); // put last object in cache here m_vecUncompressedBlockCache[ct] = m_vecUncompressedBlockCache.back(); // decrease cache size by one since last element is now in here twice @@ -635,7 +635,7 @@ namespace PolyVox // Blocks start out compressed - should we change this? // Or maybe we should just 'seed' them with compressed data, // rather than creating an empty block and then compressing? - newBlock.block.compress(); + newBlock.block.destroyUncompressedData(); itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; @@ -688,7 +688,7 @@ namespace PolyVox } //Compress the least recently used block. - m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress(); + m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.destroyUncompressedData(); //We don't actually remove any elements from this vector, we //simply change the pointer to point at the new uncompressed bloack. @@ -699,7 +699,7 @@ namespace PolyVox m_vecUncompressedBlockCache.push_back(&loadedBlock); } - loadedBlock.block.uncompress(); + loadedBlock.block.createUncompressedData(); m_pLastAccessedBlock = &(loadedBlock.block); POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); From 900e4e0ecda1be0955cfdd9e0e7eb3ff37ec022c Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 25 Jun 2013 21:18:06 +0200 Subject: [PATCH 54/64] Refactoring some LargeVolume code... --- .../include/PolyVoxCore/LargeVolume.h | 2 +- .../include/PolyVoxCore/LargeVolume.inl | 51 +++++++++---------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 8e46cb79..c0643a75 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -363,7 +363,7 @@ namespace PolyVox //than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache //of blocks. However, this could mean the same block data is uncompressed and modified in more than one //location in memory... could be messy with threading. - mutable std::vector< LoadedBlock* > m_vecUncompressedBlockCache; + mutable std::vector< LoadedBlock* > m_vecBlocksWithUncompressedData; mutable uint32_t m_uTimestamper; mutable Vector3DInt32 m_v3dLastAccessedBlockPos; mutable Block* m_pLastAccessedBlock; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index b49ce49f..66b711f7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -469,11 +469,11 @@ namespace PolyVox template void LargeVolume::clearBlockCache(void) { - for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) + for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++) { - m_vecUncompressedBlockCache[ct]->block.destroyUncompressedData(); + m_vecBlocksWithUncompressedData[ct]->block.destroyUncompressedData(); } - m_vecUncompressedBlockCache.clear(); + m_vecBlocksWithUncompressedData.clear(); } //////////////////////////////////////////////////////////////////////////////// @@ -544,23 +544,22 @@ namespace PolyVox m_pPager->dataOverflowHandler(ConstVolumeProxy, reg); } - if(m_pCompressor) + + for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++) { - for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) + // find the block in the uncompressed cache + if(m_vecBlocksWithUncompressedData[ct] == &(itBlock->second)) { - // find the block in the uncompressed cache - if(m_vecUncompressedBlockCache[ct] == &(itBlock->second)) - { - // TODO: compression is unneccessary? or will not compressing this cause a memleak? - itBlock->second.block.destroyUncompressedData(); - // put last object in cache here - m_vecUncompressedBlockCache[ct] = m_vecUncompressedBlockCache.back(); - // decrease cache size by one since last element is now in here twice - m_vecUncompressedBlockCache.resize(m_vecUncompressedBlockCache.size()-1); - break; - } + // TODO: compression is unneccessary? or will not compressing this cause a memleak? + itBlock->second.block.destroyUncompressedData(); + // put last object in cache here + m_vecBlocksWithUncompressedData[ct] = m_vecBlocksWithUncompressedData.back(); + // decrease cache size by one since last element is now in here twice + m_vecBlocksWithUncompressedData.resize(m_vecBlocksWithUncompressedData.size()-1); + break; } } + m_pBlocks.erase(itBlock); } @@ -635,7 +634,7 @@ namespace PolyVox // Blocks start out compressed - should we change this? // Or maybe we should just 'seed' them with compressed data, // rather than creating an empty block and then compressing? - newBlock.block.destroyUncompressedData(); + //newBlock.block.destroyUncompressedData(); itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; @@ -670,7 +669,7 @@ namespace PolyVox } //If we are allowed to compress then check whether we need to - if((m_pCompressor) && (m_vecUncompressedBlockCache.size() == m_uMaxNumberOfUncompressedBlocks)) + if(m_vecBlocksWithUncompressedData.size() == m_uMaxNumberOfUncompressedBlocks) { int32_t leastRecentlyUsedBlockIndex = -1; uint32_t uLeastRecentTimestamp = (std::numeric_limits::max)(); @@ -678,25 +677,25 @@ namespace PolyVox //Currently we find the oldest block by iterating over the whole array. Of course we could store the blocks sorted by //timestamp (set, priority_queue, etc) but then we'll need to move them around as the timestamp changes. Can come back //to this if it proves to be a bottleneck (compraed to the cost of actually doing the compression/decompression). - for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) + for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++) { - if(m_vecUncompressedBlockCache[ct]->timestamp < uLeastRecentTimestamp) + if(m_vecBlocksWithUncompressedData[ct]->timestamp < uLeastRecentTimestamp) { - uLeastRecentTimestamp = m_vecUncompressedBlockCache[ct]->timestamp; + uLeastRecentTimestamp = m_vecBlocksWithUncompressedData[ct]->timestamp; leastRecentlyUsedBlockIndex = ct; } } //Compress the least recently used block. - m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.destroyUncompressedData(); + m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex]->block.destroyUncompressedData(); //We don't actually remove any elements from this vector, we //simply change the pointer to point at the new uncompressed bloack. - m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex] = &loadedBlock; + m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex] = &loadedBlock; } else { - m_vecUncompressedBlockCache.push_back(&loadedBlock); + m_vecBlocksWithUncompressedData.push_back(&loadedBlock); } loadedBlock.block.createUncompressedData(); @@ -734,8 +733,8 @@ namespace PolyVox } //Memory used by the block cache. - uSizeInBytes += m_vecUncompressedBlockCache.capacity() * sizeof(LoadedBlock); - uSizeInBytes += m_vecUncompressedBlockCache.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); + uSizeInBytes += m_vecBlocksWithUncompressedData.capacity() * sizeof(LoadedBlock); + uSizeInBytes += m_vecBlocksWithUncompressedData.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); return uSizeInBytes; } From 0cf3de4e7644df99a3e2bb6020fa9ec43985d0c7 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 25 Jun 2013 22:54:40 +0200 Subject: [PATCH 55/64] Removed LoadedBlock and put timestamp into regular Block. --- .../include/PolyVoxCore/Impl/Block.h | 2 + .../include/PolyVoxCore/LargeVolume.h | 18 ++----- .../include/PolyVoxCore/LargeVolume.inl | 49 +++++++++---------- 3 files changed, 27 insertions(+), 42 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index ed9ca146..8a9932c0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -65,6 +65,8 @@ namespace PolyVox uint16_t m_uSideLength; uint8_t m_uSideLengthPower; bool m_bIsUncompressedDataModified; + + uint32_t timestamp; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index c0643a75..daded00b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -231,18 +231,6 @@ namespace PolyVox // Make the ConstVolumeProxy a friend friend class ConstVolumeProxy; - struct LoadedBlock - { - public: - LoadedBlock(uint16_t uSideLength, Compressor* pCompressor) - :block(uSideLength, pCompressor) - ,timestamp(0) - { - } - - Block block; - uint32_t timestamp; - }; #endif public: @@ -352,18 +340,18 @@ namespace PolyVox //polyvox_function&, const Region&)> m_funcDataOverflowHandler; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; - void eraseBlock(typename std::map::iterator itBlock) const; + void eraseBlock(typename std::map, BlockPositionCompare>::iterator itBlock) const; /// this function can be called by m_funcDataRequiredHandler without causing any weird effects bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; //The block data - mutable std::map m_pBlocks; + mutable std::map, BlockPositionCompare> m_pBlocks; //The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather //than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache //of blocks. However, this could mean the same block data is uncompressed and modified in more than one //location in memory... could be messy with threading. - mutable std::vector< LoadedBlock* > m_vecBlocksWithUncompressedData; + mutable std::vector< Block* > m_vecBlocksWithUncompressedData; mutable uint32_t m_uTimestamper; mutable Vector3DInt32 m_v3dLastAccessedBlockPos; mutable Block* m_pLastAccessedBlock; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 66b711f7..8f9e6085 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -381,7 +381,7 @@ namespace PolyVox for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++) { Vector3DInt32 pos(x,y,z); - typename std::map::iterator itBlock = m_pBlocks.find(pos); + typename std::map, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(pos); if(itBlock != m_pBlocks.end()) { @@ -412,7 +412,7 @@ namespace PolyVox template void LargeVolume::flushAll() { - typename std::map::iterator i; + typename std::map, BlockPositionCompare>::iterator i; //Replaced the for loop here as the call to //eraseBlock was invalidating the iterator. while(m_pBlocks.size() > 0) @@ -446,7 +446,7 @@ namespace PolyVox for(int32_t z = v3dStart.getZ(); z <= v3dEnd.getZ(); z++) { Vector3DInt32 pos(x,y,z); - typename std::map::iterator itBlock = m_pBlocks.find(pos); + typename std::map, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(pos); if(itBlock == m_pBlocks.end()) { // not loaded, not unloading @@ -471,7 +471,7 @@ namespace PolyVox { for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++) { - m_vecBlocksWithUncompressedData[ct]->block.destroyUncompressedData(); + m_vecBlocksWithUncompressedData[ct]->destroyUncompressedData(); } m_vecBlocksWithUncompressedData.clear(); } @@ -531,7 +531,7 @@ namespace PolyVox } template - void LargeVolume::eraseBlock(typename std::map::iterator itBlock) const + void LargeVolume::eraseBlock(typename std::map, BlockPositionCompare>::iterator itBlock) const { if(m_pPager) { @@ -551,7 +551,7 @@ namespace PolyVox if(m_vecBlocksWithUncompressedData[ct] == &(itBlock->second)) { // TODO: compression is unneccessary? or will not compressing this cause a memleak? - itBlock->second.block.destroyUncompressedData(); + itBlock->second.destroyUncompressedData(); // put last object in cache here m_vecBlocksWithUncompressedData[ct] = m_vecBlocksWithUncompressedData.back(); // decrease cache size by one since last element is now in here twice @@ -602,7 +602,7 @@ namespace PolyVox return m_pLastAccessedBlock; } - typename std::map::iterator itBlock = m_pBlocks.find(v3dBlockPos); + typename std::map, BlockPositionCompare>::iterator itBlock = m_pBlocks.find(v3dBlockPos); // check whether the block is already loaded if(itBlock == m_pBlocks.end()) { @@ -615,8 +615,8 @@ namespace PolyVox if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory) { // find the least recently used block - typename std::map::iterator i; - typename std::map::iterator itUnloadBlock = m_pBlocks.begin(); + typename std::map, BlockPositionCompare>::iterator i; + typename std::map, BlockPositionCompare>::iterator itUnloadBlock = m_pBlocks.begin(); for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { if(i->second.timestamp < itUnloadBlock->second.timestamp) @@ -629,12 +629,7 @@ namespace PolyVox } // create the new block - LoadedBlock newBlock(m_uBlockSideLength, m_pCompressor); - - // Blocks start out compressed - should we change this? - // Or maybe we should just 'seed' them with compressed data, - // rather than creating an empty block and then compressing? - //newBlock.block.destroyUncompressedData(); + Block newBlock(m_uBlockSideLength, m_pCompressor); itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; @@ -657,12 +652,12 @@ namespace PolyVox } //Get the block and mark that we accessed it - LoadedBlock& loadedBlock = itBlock->second; - loadedBlock.timestamp = ++m_uTimestamper; + Block& block = itBlock->second; + block.timestamp = ++m_uTimestamper; m_v3dLastAccessedBlockPos = v3dBlockPos; - m_pLastAccessedBlock = &(loadedBlock.block); + m_pLastAccessedBlock = █ - if(loadedBlock.block.hasUncompressedData()) + if(block.hasUncompressedData()) { POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); return m_pLastAccessedBlock; @@ -687,20 +682,20 @@ namespace PolyVox } //Compress the least recently used block. - m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex]->block.destroyUncompressedData(); + m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex]->destroyUncompressedData(); //We don't actually remove any elements from this vector, we //simply change the pointer to point at the new uncompressed bloack. - m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex] = &loadedBlock; + m_vecBlocksWithUncompressedData[leastRecentlyUsedBlockIndex] = █ } else { - m_vecBlocksWithUncompressedData.push_back(&loadedBlock); + m_vecBlocksWithUncompressedData.push_back(&block); } - loadedBlock.block.createUncompressedData(); + block.createUncompressedData(); - m_pLastAccessedBlock = &(loadedBlock.block); + m_pLastAccessedBlock = &(block); POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); return m_pLastAccessedBlock; } @@ -725,15 +720,15 @@ namespace PolyVox uint32_t uSizeInBytes = sizeof(LargeVolume); //Memory used by the blocks - typename std::map::iterator i; + typename std::map, BlockPositionCompare>::iterator i; for(i = m_pBlocks.begin(); i != m_pBlocks.end(); i++) { //Inaccurate - account for rest of loaded block. - uSizeInBytes += i->second.block.calculateSizeInBytes(); + uSizeInBytes += i->second.calculateSizeInBytes(); } //Memory used by the block cache. - uSizeInBytes += m_vecBlocksWithUncompressedData.capacity() * sizeof(LoadedBlock); + uSizeInBytes += m_vecBlocksWithUncompressedData.capacity() * sizeof(Block); uSizeInBytes += m_vecBlocksWithUncompressedData.size() * m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); return uSizeInBytes; From 8ab6d73f0af7f1dbd13060d83980fffa92b750c5 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 25 Jun 2013 23:34:58 +0200 Subject: [PATCH 56/64] Work on LargeVolume refactoring - getting FilePager working. --- examples/Basic/main.cpp | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/FilePager.h | 2 ++ .../include/PolyVoxCore/Impl/Block.inl | 5 ++++- .../include/PolyVoxCore/LargeVolume.inl | 16 +++++++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 40bf0058..444e71fb 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -85,8 +85,8 @@ int main(int argc, char *argv[]) FilePager* pFilePager = new FilePager("D:/temp/voldata/"); LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32); - //volData.setMaxNumberOfUncompressedBlocks(6); - //volData.setMaxNumberOfBlocksInMemory(7); + volData.setMaxNumberOfUncompressedBlocks(6); + volData.setMaxNumberOfBlocksInMemory(7); createSphereInVolume(volData, 30); diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 07dc94e1..5d8d97ed 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -54,6 +54,7 @@ namespace PolyVox virtual void pageIn(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page in NULL block"); + POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); std::stringstream ss; ss << region.getLowerX() << "_" << region.getLowerY() << "_" << region.getLowerZ() << "_" @@ -94,6 +95,7 @@ namespace PolyVox virtual void pageOut(const Region& region, Block* pBlockData) { POLYVOX_ASSERT(pBlockData, "Attempting to page out NULL block"); + POLYVOX_ASSERT(pBlockData->hasUncompressedData() == false, "Block should not have uncompressed data"); logTrace() << "Paging out data for " << region; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index cf103eaa..3076d2bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -64,11 +64,14 @@ namespace PolyVox m_uSideLength = uSideLength; m_uSideLengthPower = logBase2(uSideLength); - //Create the block data + //Temporarily create the block data. This is just so we can compress it an discard it. + // FIXME - this is a temporary solution. const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; m_tUncompressedData = new VoxelType[uNoOfVoxels]; std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, VoxelType()); m_bIsUncompressedDataModified = true; + + destroyUncompressedData(); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 8f9e6085..dccaa4cd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -540,9 +540,11 @@ namespace PolyVox Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); - ConstVolumeProxy ConstVolumeProxy(*this, reg); + /*ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_pPager->dataOverflowHandler(ConstVolumeProxy, reg); + m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);*/ + + m_pPager->pageOut(reg, &(itBlock->second)); } for(uint32_t ct = 0; ct < m_vecBlocksWithUncompressedData.size(); ct++) @@ -631,7 +633,9 @@ namespace PolyVox // create the new block Block newBlock(m_uBlockSideLength, m_pCompressor); - itBlock = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)).first; + auto retVal = m_pBlocks.insert(std::make_pair(v3dBlockPos, newBlock)); + itBlock = retVal.first; + POLYVOX_ASSERT(retVal.second == true, "Element was not supposed to exist!"); //We have created the new block. If paging is enabled it should be used to //fill in the required data. Otherwise it is just left in the default state. @@ -645,8 +649,10 @@ namespace PolyVox Vector3DInt32 v3dLower(v3dBlockPos.getX() << m_uBlockSideLengthPower, v3dBlockPos.getY() << m_uBlockSideLengthPower, v3dBlockPos.getZ() << m_uBlockSideLengthPower); Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); - ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_pPager->dataRequiredHandler(ConstVolumeProxy, reg); + /*ConstVolumeProxy ConstVolumeProxy(*this, reg); + m_pPager->dataRequiredHandler(ConstVolumeProxy, reg);*/ + + m_pPager->pageIn(reg, &(itBlock->second)); } } } From 44d525f5912f2eb232d0b9355f0f058f73c1508b Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 26 Jun 2013 17:02:06 +0200 Subject: [PATCH 57/64] Tidying up and refactoring LargeVolume. --- examples/Basic/main.cpp | 6 +-- examples/Paging/main.cpp | 2 +- .../include/PolyVoxCore/LargeVolume.h | 35 +++++++------ .../include/PolyVoxCore/LargeVolume.inl | 51 ++++++++++++------- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 444e71fb..407d4e8e 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -82,11 +82,11 @@ int main(int argc, char *argv[]) //Create an empty volume and then place a sphere in it RLECompressor* pCompressor = new RLECompressor(); - FilePager* pFilePager = new FilePager("D:/temp/voldata/"); + FilePager* pFilePager = new FilePager("C:/temp/voldata/"); LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32); - volData.setMaxNumberOfUncompressedBlocks(6); - volData.setMaxNumberOfBlocksInMemory(7); + volData.setMaxNumberOfUncompressedBlocks(2); + volData.setMaxNumberOfBlocksInMemory(4); createSphereInVolume(volData, 30); diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 4622764c..03601f9b 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -332,7 +332,7 @@ int main(int argc, char *argv[]) //If these lines don't compile, please try commenting them out and using the two lines after //(you will need Boost for this). If you have to do this then please let us know in the forums as //we rely on community feedback to keep the Boost version running. - LargeVolume volData(compressor, pager, 256); + LargeVolume volData(Region::MaxRegion, compressor, pager, 256); //LargeVolume volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2), // polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256); volData.setMaxNumberOfBlocksInMemory(4096); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index daded00b..581f1adf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -233,20 +233,19 @@ namespace PolyVox #endif - public: - /// Constructor for creating a very large paging volume. + public: + /// Constructor for creating a fixed size volume. LargeVolume ( - Compressor* pCompressor, - Pager* pPager, - uint16_t uBlockSideLength = 32 + const Region& regValid, + uint16_t uBlockSideLength = 32 ); /// Constructor for creating a fixed size volume. LargeVolume ( const Region& regValid, - Compressor* pCompressor, - Pager* pPager, + Compressor* pCompressor, + Pager* pPager , uint16_t uBlockSideLength = 32 ); /// Destructor @@ -319,7 +318,7 @@ namespace PolyVox return false; } }; - void initialise(const Region& regValidRegion, uint16_t uBlockSideLength); + void initialise(); // A trick to implement specialization of template member functions in template classes. See http://stackoverflow.com/a/4951057 template @@ -344,13 +343,13 @@ namespace PolyVox /// this function can be called by m_funcDataRequiredHandler without causing any weird effects bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; - //The block data + // The block data mutable std::map, BlockPositionCompare> m_pBlocks; - //The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather - //than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache - //of blocks. However, this could mean the same block data is uncompressed and modified in more than one - //location in memory... could be messy with threading. + // The cache of uncompressed blocks. The uncompressed block data and the timestamps are stored here rather + // than in the Block class. This is so that in the future each VolumeIterator might to maintain its own cache + // of blocks. However, this could mean the same block data is uncompressed and modified in more than one + // location in memory... could be messy with threading. mutable std::vector< Block* > m_vecBlocksWithUncompressedData; mutable uint32_t m_uTimestamper; mutable Vector3DInt32 m_v3dLastAccessedBlockPos; @@ -358,16 +357,20 @@ namespace PolyVox uint32_t m_uMaxNumberOfUncompressedBlocks; uint32_t m_uMaxNumberOfBlocksInMemory; - //The size of the volume + // The size of the volume Region m_regValidRegionInBlocks; - //The size of the blocks + // The size of the blocks uint16_t m_uBlockSideLength; uint8_t m_uBlockSideLengthPower; - //The compressor used by the Blocks to compress their data if required. + // The compressor used by the Blocks to compress their data if required. Compressor* m_pCompressor; Pager* m_pPager; + + // Whether we created the compressor or whether it was provided + // by the user. This controls whether we delete it on destruction. + bool m_bIsOurCompressor; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index dccaa4cd..640ddc3e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -23,6 +23,8 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/ErrorHandling.h" +#include "PolyVoxCore/MinizCompressor.h" + //Included here rather than in the .h because it refers to LargeVolume (avoids forward declaration) #include "PolyVoxCore/ConstVolumeProxy.h" @@ -37,16 +39,19 @@ namespace PolyVox template LargeVolume::LargeVolume ( - Compressor* pCompressor, - Pager* pPager, - uint16_t uBlockSideLength + const Region& regValid, + uint16_t uBlockSideLength ) - :BaseVolume(Region::MaxRegion) - ,m_pCompressor(pCompressor) + :BaseVolume(regValid) { - m_pPager = pPager; - //Create a volume of the right size. - initialise(Region::MaxRegion,uBlockSideLength); + m_uBlockSideLength = uBlockSideLength; + + m_pCompressor = new MinizCompressor(); + m_bIsOurCompressor = true; + + m_pPager = 0; + + initialise(); } //////////////////////////////////////////////////////////////////////////////// @@ -67,12 +72,16 @@ namespace PolyVox uint16_t uBlockSideLength ) :BaseVolume(regValid) - ,m_pCompressor(pCompressor) { + + m_uBlockSideLength = uBlockSideLength; + + m_pCompressor = pCompressor; + m_bIsOurCompressor = false; + m_pPager = pPager; - //Create a volume of the right size. - initialise(regValid,uBlockSideLength); + initialise(); } //////////////////////////////////////////////////////////////////////////////// @@ -95,6 +104,12 @@ namespace PolyVox LargeVolume::~LargeVolume() { flushAll(); + + // Only delete the compressor if it was created by us (in the constructor), not by the user. + if(m_bIsOurCompressor) + { + delete m_pCompressor; + } } //////////////////////////////////////////////////////////////////////////////// @@ -480,33 +495,31 @@ namespace PolyVox /// This function should probably be made internal... //////////////////////////////////////////////////////////////////////////////// template - void LargeVolume::initialise(const Region& regValidRegion, uint16_t uBlockSideLength) + void LargeVolume::initialise() { //Validate parameters - if(uBlockSideLength == 0) + if(m_uBlockSideLength == 0) { POLYVOX_THROW(std::invalid_argument, "Block side length cannot be zero."); } - if(!isPowerOf2(uBlockSideLength)) + + if(!isPowerOf2(m_uBlockSideLength)) { POLYVOX_THROW(std::invalid_argument, "Block side length must be a power of two."); } + if(!m_pCompressor) { - POLYVOX_THROW(std::invalid_argument, "You must provide a compressor for the LargeVolume to use."); + POLYVOX_THROW(std::invalid_argument, "You must provide a valid compressor for the LargeVolume to use."); } m_uTimestamper = 0; m_uMaxNumberOfUncompressedBlocks = 16; - m_uBlockSideLength = uBlockSideLength; m_uMaxNumberOfBlocksInMemory = 1024; m_v3dLastAccessedBlockPos = Vector3DInt32(0,0,0); //There are no invalid positions, but initially the m_pLastAccessedBlock pointer will be null; m_pLastAccessedBlock = 0; - this->m_regValidRegion = regValidRegion; - //Compute the block side length - m_uBlockSideLength = uBlockSideLength; m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); m_regValidRegionInBlocks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uBlockSideLengthPower); From 938eea7c8e2a28eb85575e8ebf99b61935873373 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Jun 2013 22:01:44 +0200 Subject: [PATCH 58/64] Work on tidying LargeVolume... --- examples/Basic/main.cpp | 2 +- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 407d4e8e..b3ba51b7 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) //Create an empty volume and then place a sphere in it RLECompressor* pCompressor = new RLECompressor(); - FilePager* pFilePager = new FilePager("C:/temp/voldata/"); + FilePager* pFilePager = new FilePager("D:/temp/voldata/"); LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32); volData.setMaxNumberOfUncompressedBlocks(2); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 640ddc3e..4473e350 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -546,6 +546,11 @@ namespace PolyVox template void LargeVolume::eraseBlock(typename std::map, BlockPositionCompare>::iterator itBlock) const { + if(itBlock->second.hasUncompressedData()) + { + itBlock->second.destroyUncompressedData(); + } + if(m_pPager) { Vector3DInt32 v3dPos = itBlock->first; @@ -565,8 +570,6 @@ namespace PolyVox // find the block in the uncompressed cache if(m_vecBlocksWithUncompressedData[ct] == &(itBlock->second)) { - // TODO: compression is unneccessary? or will not compressing this cause a memleak? - itBlock->second.destroyUncompressedData(); // put last object in cache here m_vecBlocksWithUncompressedData[ct] = m_vecBlocksWithUncompressedData.back(); // decrease cache size by one since last element is now in here twice From acb43d54d996bab4b2faa09a57f3f8bc2f6ef635 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Jun 2013 22:08:49 +0200 Subject: [PATCH 59/64] Fixed paging example. --- examples/Paging/main.cpp | 80 ++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 03601f9b..9ddf456f 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -216,9 +216,47 @@ public: virtual void pageIn(const Region& region, Block* pBlockData) { - POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); + pBlockData->createUncompressedData(); - + Perlin perlin(2,2,1,234); + + for(int x = region.getLowerX(); x <= region.getUpperX(); x++) + { + for(int y = region.getLowerY(); y <= region.getUpperY(); y++) + { + float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); + perlinVal += 1.0f; + perlinVal *= 0.5f; + perlinVal *= 255; + for(int z = region.getLowerZ(); z <= region.getUpperZ(); z++) + { + MaterialDensityPair44 voxel; + if(z < perlinVal) + { + const int xpos = 50; + const int zpos = 100; + if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) { + // tunnel + voxel.setMaterial(0); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); + } else { + // solid + voxel.setMaterial(245); + voxel.setDensity(MaterialDensityPair44::getMaxDensity()); + } + } + else + { + voxel.setMaterial(0); + voxel.setDensity(MaterialDensityPair44::getMinDensity()); + } + + pBlockData->setVoxelAt(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), voxel); + } + } + } + + pBlockData->destroyUncompressedData(); } virtual void pageOut(const Region& region, Block* pBlockData) @@ -228,43 +266,7 @@ public: virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) { - Perlin perlin(2,2,1,234); - - for(int x = region.getLowerX(); x <= region.getUpperX(); x++) - { - for(int y = region.getLowerY(); y <= region.getUpperY(); y++) - { - float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); - perlinVal += 1.0f; - perlinVal *= 0.5f; - perlinVal *= 255; - for(int z = region.getLowerZ(); z <= region.getUpperZ(); z++) - { - MaterialDensityPair44 voxel; - if(z < perlinVal) - { - const int xpos = 50; - const int zpos = 100; - if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) { - // tunnel - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } else { - // solid - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } - - volumeProxy.setVoxelAt(x, y, z, voxel); - } - } - } + POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); } virtual void dataOverflowHandler(const ConstVolumeProxy& /*volumeProxy*/, const Region& region) From 1064ea1c4777fcf10abcea778684ea8ba2a3352c Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Jun 2013 22:14:01 +0200 Subject: [PATCH 60/64] Stripped out unused code. --- examples/Paging/main.cpp | 65 --------------- library/PolyVoxCore/CMakeLists.txt | 1 - .../include/PolyVoxCore/ConstVolumeProxy.h | 83 ------------------- .../include/PolyVoxCore/FilePager.h | 8 -- .../include/PolyVoxCore/LargeVolume.h | 17 ---- .../include/PolyVoxCore/LargeVolume.inl | 32 ------- .../PolyVoxCore/include/PolyVoxCore/Pager.h | 12 --- 7 files changed, 218 deletions(-) delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 9ddf456f..f10c2331 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -263,64 +263,8 @@ public: { std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl; } - - virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) - { - POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); - } - - virtual void dataOverflowHandler(const ConstVolumeProxy& /*volumeProxy*/, const Region& region) - { - std::cout << "warning unloading region: " << region.getLowerCorner() << " -> " << region.getUpperCorner() << std::endl; - } }; -void load(const ConstVolumeProxy& volume, const PolyVox::Region& reg) -{ - Perlin perlin(2,2,1,234); - - for(int x = reg.getLowerX(); x <= reg.getUpperX(); x++) - { - for(int y = reg.getLowerY(); y <= reg.getUpperY(); y++) - { - float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); - perlinVal += 1.0f; - perlinVal *= 0.5f; - perlinVal *= 255; - for(int z = reg.getLowerZ(); z <= reg.getUpperZ(); z++) - { - MaterialDensityPair44 voxel; - if(z < perlinVal) - { - const int xpos = 50; - const int zpos = 100; - if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) { - // tunnel - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } else { - // solid - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } - - volume.setVoxelAt(x, y, z, voxel); - } - } - } -} - -void unload(const ConstVolumeProxy& /*vol*/, const PolyVox::Region& reg) -{ - std::cout << "warning unloading region: " << reg.getLowerCorner() << " -> " << reg.getUpperCorner() << std::endl; -} - int main(int argc, char *argv[]) { //Create and show the Qt OpenGL window @@ -330,19 +274,10 @@ int main(int argc, char *argv[]) RLECompressor* compressor = new RLECompressor(); PerlinNoisePager* pager = new PerlinNoisePager(); - - //If these lines don't compile, please try commenting them out and using the two lines after - //(you will need Boost for this). If you have to do this then please let us know in the forums as - //we rely on community feedback to keep the Boost version running. LargeVolume volData(Region::MaxRegion, compressor, pager, 256); - //LargeVolume volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2), - // polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256); volData.setMaxNumberOfBlocksInMemory(4096); volData.setMaxNumberOfUncompressedBlocks(64); - //volData.dataRequiredHandler = &load; - //volData.dataOverflowHandler = &unload; - //volData.setMaxNumberOfUncompressedBlocks(4096); //createSphereInVolume(volData, 30); //createPerlinTerrain(volData); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 8366d527..a8ce8a0c 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -49,7 +49,6 @@ SET(CORE_INC_FILES include/PolyVoxCore/BaseVolume.inl include/PolyVoxCore/BaseVolumeSampler.inl include/PolyVoxCore/Compressor.h - include/PolyVoxCore/ConstVolumeProxy.h include/PolyVoxCore/CubicSurfaceExtractor.h include/PolyVoxCore/CubicSurfaceExtractor.inl include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h deleted file mode 100644 index 751377ec..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_ConstVolumeProxy_H__ -#define __PolyVox_ConstVolumeProxy_H__ - -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/Vector.h" - -namespace PolyVox -{ - template - class ConstVolumeProxy - { - //LargeVolume is a friend so it can call the constructor. - friend class LargeVolume; - public: - VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const - { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); - return m_pVolume.getVoxel(uXPos, uYPos, uZPos); - } - - VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const - { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region"); - return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); - } - - void setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const - { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(m_regValid.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)), "Position is outside valid region"); - m_pVolume.setVoxelAtConst(uXPos, uYPos, uZPos, tValue); - } - - void setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) const - { - // PolyVox does not throw an exception when a voxel is out of range. Please see 'Error Handling' in the User Manual. - POLYVOX_ASSERT(m_regValid.containsPoint(v3dPos), "Position is outside valid region"); - setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); - } - private: - //Private constructor, so client code can't abuse this class. - ConstVolumeProxy(const LargeVolume& pVolume, const Region& regValid) - :m_pVolume(pVolume) - ,m_regValid(regValid) - { - } - - //Private assignment operator, so client code can't abuse this class. - ConstVolumeProxy& operator=(const ConstVolumeProxy& rhs) - { - } - - const LargeVolume& m_pVolume; - const Region& m_regValid; - }; -} - -#endif //__PolyVox_ConstVolumeProxy_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h index 5d8d97ed..e5ab35b3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/FilePager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/FilePager.h @@ -124,14 +124,6 @@ namespace PolyVox fclose(pFile); } - virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) - { - } - - virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region) - { - } - protected: std::string m_strFolderName; }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 581f1adf..103d7ca8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -42,8 +42,6 @@ freely, subject to the following restrictions: namespace PolyVox { - template class ConstVolumeProxy; - /// The LargeVolume class provides a memory efficient method of storing voxel data while also allowing fast access and modification. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// A LargeVolume is essentially a 3D array in which each element (or voxel) is identified by a three dimensional (x,y,z) coordinate. @@ -228,9 +226,6 @@ namespace PolyVox VoxelType* mCurrentVoxel; }; - // Make the ConstVolumeProxy a friend - friend class ConstVolumeProxy; - #endif public: @@ -327,21 +322,9 @@ namespace PolyVox VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; VoxelType getVoxelImpl(int32_t uXPos, int32_t uYPos, int32_t uZPos, WrapModeType, VoxelType tBorder) const; - - /// gets called when a new region is allocated and needs to be filled - /// NOTE: accessing ANY voxels outside this region during the process of this function - /// is absolutely unsafe - //polyvox_function&, const Region&)> m_funcDataRequiredHandler; - /// gets called when a Region needs to be stored by the user, because LargeVolume will erase it right after - /// this function returns - /// NOTE: accessing ANY voxels outside this region during the process of this function - /// is absolutely unsafe - //polyvox_function&, const Region&)> m_funcDataOverflowHandler; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; void eraseBlock(typename std::map, BlockPositionCompare>::iterator itBlock) const; - /// this function can be called by m_funcDataRequiredHandler without causing any weird effects - bool setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const; // The block data mutable std::map, BlockPositionCompare> m_pBlocks; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 4473e350..ef8dbb40 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -25,9 +25,6 @@ freely, subject to the following restrictions: #include "PolyVoxCore/MinizCompressor.h" -//Included here rather than in the .h because it refers to LargeVolume (avoids forward declaration) -#include "PolyVoxCore/ConstVolumeProxy.h" - namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// @@ -558,9 +555,6 @@ namespace PolyVox Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); - /*ConstVolumeProxy ConstVolumeProxy(*this, reg); - - m_pPager->dataOverflowHandler(ConstVolumeProxy, reg);*/ m_pPager->pageOut(reg, &(itBlock->second)); } @@ -581,30 +575,6 @@ namespace PolyVox m_pBlocks.erase(itBlock); } - template - bool LargeVolume::setVoxelAtConst(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) const - { - //We don't have any range checks in this function because it - //is a private function only called by the ConstVolumeProxy. The - //ConstVolumeProxy takes care of ensuring the range is appropriate. - - const int32_t blockX = uXPos >> m_uBlockSideLengthPower; - const int32_t blockY = uYPos >> m_uBlockSideLengthPower; - const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; - - const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower); - const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower); - const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower); - - Block* pUncompressedBlock = getUncompressedBlock(blockX, blockY, blockZ); - - pUncompressedBlock->setVoxelAt(xOffset,yOffset,zOffset, tValue); - - //Return true to indicate that we modified a voxel. - return true; - } - - template Block* LargeVolume::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const { @@ -665,8 +635,6 @@ namespace PolyVox Vector3DInt32 v3dLower(v3dBlockPos.getX() << m_uBlockSideLengthPower, v3dBlockPos.getY() << m_uBlockSideLengthPower, v3dBlockPos.getZ() << m_uBlockSideLengthPower); Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); - /*ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_pPager->dataRequiredHandler(ConstVolumeProxy, reg);*/ m_pPager->pageIn(reg, &(itBlock->second)); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index 13f4ad19..4cb95adc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -27,8 +27,6 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Impl/Block.h" #include "PolyVoxCore/Impl/TypeDef.h" -#include "PolyVoxCore/ConstVolumeProxy.h" - namespace PolyVox { /** @@ -45,16 +43,6 @@ namespace PolyVox virtual void pageIn(const Region& region, Block* pBlockData) = 0; virtual void pageOut(const Region& region, Block* pBlockData) = 0; - - virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) - { - POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); - } - - virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region) - { - POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); - } }; } From 56cf423bfd15a7d798300a6583bf8bbddbf3258f Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Jun 2013 22:39:15 +0200 Subject: [PATCH 61/64] Added POLYVOX_THROW_IF macro to simplify error handling. --- .../PolyVoxCore/include/PolyVoxCore/Array.inl | 30 ++------ .../include/PolyVoxCore/Impl/ErrorHandling.h | 77 ++++++++++++++----- 2 files changed, 65 insertions(+), 42 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Array.inl b/library/PolyVoxCore/include/PolyVoxCore/Array.inl index 1821817d..53f428ac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Array.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Array.inl @@ -73,10 +73,7 @@ namespace PolyVox template SubArray Array::operator[](uint32_t uIndex) { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } + POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); return SubArray(&m_pElements[uIndex*m_pOffsets[0]], @@ -95,10 +92,7 @@ namespace PolyVox template const SubArray Array::operator[](uint32_t uIndex) const { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } + POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); return SubArray(&m_pElements[uIndex*m_pOffsets[0]], @@ -147,10 +141,7 @@ namespace PolyVox m_uNoOfElements = 1; for (uint32_t i = 0; i uint32_t Array::getDimension(uint32_t uDimension) { - if(uDimension >= noOfDims) - { - POLYVOX_THROW(std::out_of_range, "Array dimension out of range"); - } + POLYVOX_THROW_IF(uDimension >= noOfDims, std::out_of_range, "Array dimension out of range"); return m_pDimensions[uDimension]; } @@ -266,10 +254,7 @@ namespace PolyVox template ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } + POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); return m_pElements[uIndex]; } @@ -277,10 +262,7 @@ namespace PolyVox template const ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) const { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } + POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); return m_pElements[uIndex]; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 5080f7db..afc452c0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -255,15 +255,36 @@ namespace PolyVox * ... */ #ifdef POLYVOX_THROW_ENABLED - #define POLYVOX_THROW(type, message) \ - PolyVox::logError() << (message); \ - throw type((message)) - // Some fast functions (getVoxel(), etc) use exceptions for error handling but don't want the overhead of logging. - // This overhead is present even if no exception is thrown, probably because the presence of the logging code prevents - // some inlining. Therefore we provide this macro which doesn't log for such specialised circumstances. - #define POLYVOX_THROW_DONT_LOG(type, message) \ - throw type((message)) + #define POLYVOX_THROW_IF(condition, type, message) \ + /* We use the do...while(0) construct in our macros (for reasons see here: http://stackoverflow.com/a/154138) \ + but Visual Studio gives unhelpful 'conditional expression is constant' warnings. The recommended solution \ + (http://stackoverflow.com/a/1946485) is to disable these warnings. */ \ + POLYVOX_MSC_WARNING_PUSH \ + POLYVOX_DISABLE_MSC_WARNING(4127) \ + do \ + { \ + if ((condition)) \ + { \ + PolyVox::logError() << (message); \ + throw type((message)); \ + } \ + } while(0) \ + POLYVOX_MSC_WARNING_POP + + #define POLYVOX_THROW(type, message) \ + /* We use the do...while(0) construct in our macros (for reasons see here: http://stackoverflow.com/a/154138) \ + but Visual Studio gives unhelpful 'conditional expression is constant' warnings. The recommended solution \ + (http://stackoverflow.com/a/1946485) is to disable these warnings. */ \ + POLYVOX_MSC_WARNING_PUSH \ + POLYVOX_DISABLE_MSC_WARNING(4127) \ + do \ + { \ + PolyVox::logError() << (message); \ + throw type((message)); \ + } while(0) \ + POLYVOX_MSC_WARNING_POP + #else namespace PolyVox { @@ -273,17 +294,37 @@ namespace PolyVox void setThrowHandler(ThrowHandler newHandler); } - #define POLYVOX_THROW(type, message) \ - PolyVox::logError() << (message); \ - type except = (type)((message)); \ - getThrowHandler()((except), __FILE__, __LINE__) + #define POLYVOX_THROW_IF(condition, type, message) \ + /* We use the do...while(0) construct in our macros (for reasons see here: http://stackoverflow.com/a/154138) \ + but Visual Studio gives unhelpful 'conditional expression is constant' warnings. The recommended solution \ + (http://stackoverflow.com/a/1946485) is to disable these warnings. */ \ + POLYVOX_MSC_WARNING_PUSH \ + POLYVOX_DISABLE_MSC_WARNING(4127) \ + do \ + { \ + if ((condition)) \ + { \ + PolyVox::logError() << (message); \ + type except = (type)((message)); \ + getThrowHandler()((except), __FILE__, __LINE__); \ + } \ + } while(0) \ + POLYVOX_MSC_WARNING_POP + + #define POLYVOX_THROW(type, message) \ + /* We use the do...while(0) construct in our macros (for reasons see here: http://stackoverflow.com/a/154138) \ + but Visual Studio gives unhelpful 'conditional expression is constant' warnings. The recommended solution \ + (http://stackoverflow.com/a/1946485) is to disable these warnings. */ \ + POLYVOX_MSC_WARNING_PUSH \ + POLYVOX_DISABLE_MSC_WARNING(4127) \ + do \ + { \ + PolyVox::logError() << (message); \ + type except = (type)((message)); \ + getThrowHandler()((except), __FILE__, __LINE__); \ + } while(0) \ + POLYVOX_MSC_WARNING_POP - // Some fast functions (getVoxel(), etc) use exceptions for error handling but don't want the overhead of logging. - // This overhead is present even if no exception is thrown, probably because the presence of the logging code prevents - // some inlining. Therefore we provide this macro which doesn't log for such specialised circumstances. - #define POLYVOX_THROW_DONT_LOG(type, message) \ - type except = (type)((message)); \ - getThrowHandler()((except), __FILE__, __LINE__) #endif namespace PolyVox From 72b3cd5154e52b489d30d4246c4ea885839325f4 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 26 Jun 2013 23:39:21 +0200 Subject: [PATCH 62/64] Tidying up and comments. --- examples/Paging/main.cpp | 128 +----------------- .../include/PolyVoxCore/LargeVolume.inl | 3 +- 2 files changed, 4 insertions(+), 127 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index f10c2331..55e08b75 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -37,129 +37,6 @@ freely, subject to the following restrictions: //Use the PolyVox namespace using namespace PolyVox; -void createPerlinVolumeSlow(LargeVolume& volData) -{ - Perlin perlin(2,8,1,234); - - for(int z = 1; z < 256-1; z++) - { - std::cout << z << std::endl; - for(int y = 1; y < 256-1; y++) - { - for(int x = 1; x < 256-1; x++) - { - float perlinVal = perlin.Get3D(x /static_cast(256-1), (y) / static_cast(256-1), z / static_cast(256-1)); - - perlinVal += 1.0f; - perlinVal *= 0.5f; - perlinVal *= MaterialDensityPair44::getMaxDensity(); - - MaterialDensityPair44 voxel; - - voxel.setMaterial(245); - voxel.setDensity(perlinVal); - - /*if(perlinVal < 0.0f) - { - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - }*/ - - volData.setVoxelAt(x, y, z, voxel); - } - } - } -} - -/*void createPerlinVolumeFast(LargeVolume& volData) -{ - Perlin perlin(2,8,1,234); - - for(int blockZ = 0; blockZ < volData.m_uDepthInBlocks; blockZ++) - { - std::cout << blockZ << std::endl; - for(int blockY = 0; blockY < volData.m_uHeightInBlocks; blockY++) - { - for(int blockX = 0; blockX < volData.m_uWidthInBlocks; blockX++) - { - for(int offsetz = 0; offsetz < volData.m_uBlockSideLength; offsetz++) - { - for(int offsety = 0; offsety < volData.m_uBlockSideLength; offsety++) - { - for(int offsetx = 0; offsetx < volData.m_uBlockSideLength; offsetx++) - { - int x = blockX * volData.m_uBlockSideLength + offsetx; - int y = blockY * volData.m_uBlockSideLength + offsety; - int z = blockZ * volData.m_uBlockSideLength + offsetz; - - if((x == 0) || (x == volData.getWidth()-1)) continue; - if((y == 0) || (y == volData.getHeight()-1)) continue; - if((z == 0) || (z == volData.getDepth()-1)) continue; - - float perlinVal = perlin.Get3D(x /static_cast(volData.getWidth()-1), (y) / static_cast(volData.getHeight()-1), z / static_cast(volData.getDepth()-1)); - - MaterialDensityPair44 voxel; - if(perlinVal < 0.0f) - { - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } - - volData.setVoxelAt(x, y, z, voxel); - } - } - } - } - } - } -}*/ - -void createPerlinTerrain(LargeVolume& volData) -{ - Perlin perlin(2,2,1,234); - - for(int x = 1; x < 255-1; x++) - { - if(x%(255/100) == 0) { - std::cout << "." << std::flush; - } - for(int y = 1; y < 255-1; y++) - { - float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); - perlinVal += 1.0f; - perlinVal *= 0.5f; - perlinVal *= 255; - for(int z = 1; z < 255-1; z++) - { - MaterialDensityPair44 voxel; - if(z < perlinVal) - { - voxel.setMaterial(245); - voxel.setDensity(MaterialDensityPair44::getMaxDensity()); - } - else - { - voxel.setMaterial(0); - voxel.setDensity(MaterialDensityPair44::getMinDensity()); - } - - volData.setVoxelAt(x, y, z, voxel); - } - } - } - std::cout << std::endl; -} - void createSphereInVolume(LargeVolume& volData, Vector3DFloat v3dVolCenter, float fRadius) { //This vector hold the position of the center of the volume @@ -251,12 +128,13 @@ public: voxel.setDensity(MaterialDensityPair44::getMinDensity()); } + // Voxel position within a block always start from zero. So if a block represents region (4, 8, 12) to (11, 19, 15) + // then the valid block voxels are from (0, 0, 0) to (7, 11, 3). Hence we subtract the lower corner position of the + // region from the volume space position in order to get the block space position. pBlockData->setVoxelAt(x - region.getLowerX(), y - region.getLowerY(), z - region.getLowerZ(), voxel); } } } - - pBlockData->destroyUncompressedData(); } virtual void pageOut(const Region& region, Block* pBlockData) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index ef8dbb40..ab6f4b46 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -586,7 +586,7 @@ namespace PolyVox //This check should also provide a significant speed boost as usually it is true. if((v3dBlockPos == m_v3dLastAccessedBlockPos) && (m_pLastAccessedBlock != 0)) { - POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); + POLYVOX_ASSERT(m_pLastAccessedBlock->hasUncompressedData(), "Last accessed block has no uncompressed data."); return m_pLastAccessedBlock; } @@ -649,7 +649,6 @@ namespace PolyVox if(block.hasUncompressedData()) { - POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data"); return m_pLastAccessedBlock; } From 97a501e3dabb8217aea290bf6144f5616eea42ea Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 27 Jun 2013 16:41:24 +0200 Subject: [PATCH 63/64] Updated changelog. --- CHANGELOG.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c8df1d8d..d50bb57e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -10,9 +10,13 @@ The getVoxelAt() and setVoxelAt() functions have been deprecated and replaced by LargeVolume ----------- +Behaviour and interface of the LargeVolume has changed significantly and code which uses it will certainly need to be updated. Plese see the LargeVolume API docs for full details of how it now works. + It is now possible to provide custom compressors for the data which is stored in a LargeVolume. Two compressor implementation are provided with PolyVox - RLECompressor which is suitable for cubic-style terrain, and MinizCompressor which uses the 'miniz' zlib implementation for smooth terrain or general purpose use. Users can provide their own implementation of the compressor interface if they wish. -Note that the setCompressionEnabled() functionality has been removed and a compressor must always be provided when constructing the volume. The ability to disable compression was of questionable benefit and was complicating the logic in the code. In practice it is still possible to mostly disable compression by setting the maximum number of uncompressed blocks to a high value by calling setMaxNumberOfUncompressedBlocks(). +Note that the setCompressionEnabled() functionality has been removed and a compressor must always be provided when constructing the volume. The ability to disable compression was of questionable benefit and was complicating the logic in the code. + +The LargeVolume also supports custom paging code which can be supplied by providing a subclass of Pager and implementing the relevant methods. This replaces the dataRequiredHandler() and dataOverflowHandler() functions. These changes regarding compression and paging have also affected the LargeVolume constructors(s). Please see the API docs to see how they look now. From f3ec94dd75415f1e212fb03c63a768c7fd9de999 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Thu, 27 Jun 2013 16:43:49 +0200 Subject: [PATCH 64/64] Reverted changes made for testing. --- examples/Basic/main.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index b3ba51b7..64097731 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -26,17 +26,14 @@ freely, subject to the following restrictions: #include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVoxCore/SurfaceMesh.h" -//#include "PolyVoxCore/SimpleVolume.h" -#include "PolyVoxCore/LargeVolume.h" -#include "PolyVoxCore/RLECompressor.h" -#include "PolyVoxCore/FilePager.h" +#include "PolyVoxCore/SimpleVolume.h" #include //Use the PolyVox namespace using namespace PolyVox; -void createSphereInVolume(LargeVolume& volData, float fRadius) +void createSphereInVolume(SimpleVolume& volData, float fRadius) { //This vector hold the position of the center of the volume Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); @@ -71,32 +68,21 @@ void createSphereInVolume(LargeVolume& volData, float fRadius) int main(int argc, char *argv[]) { - setTraceStream(&(std::cout)); - setDebugStream(&(std::cout)); - setInfoStream(&(std::cout)); - //Create and show the Qt OpenGL window QApplication app(argc, argv); OpenGLWidget openGLWidget(0); openGLWidget.show(); //Create an empty volume and then place a sphere in it - RLECompressor* pCompressor = new RLECompressor(); - FilePager* pFilePager = new FilePager("D:/temp/voldata/"); - - LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)), pCompressor, pFilePager, 32); - volData.setMaxNumberOfUncompressedBlocks(2); - volData.setMaxNumberOfBlocksInMemory(4); - - + SimpleVolume 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 mesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - CubicSurfaceExtractorWithNormals< LargeVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); - //MarchingCubesSurfaceExtractor< LargeVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + CubicSurfaceExtractorWithNormals< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + //MarchingCubesSurfaceExtractor< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); //Execute the surface extractor. surfaceExtractor.execute(); @@ -106,4 +92,4 @@ int main(int argc, char *argv[]) //Run the message pump. return app.exec(); -} +} \ No newline at end of file