diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h index f44fbc7d..a76ff391 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.h @@ -183,6 +183,9 @@ namespace PolyVox int32_t m_uLongestSideLength; int32_t m_uShortestSideLength; float m_fDiagonalLength; + + //The border value + VoxelType m_tBorderValue; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 3e41528d..d50c0838 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -31,6 +31,7 @@ namespace PolyVox template BaseVolume::BaseVolume(const Region& regValid) :m_regValidRegion(regValid) + ,m_tBorderValue(0) { } @@ -76,8 +77,7 @@ namespace PolyVox template VoxelType BaseVolume::getBorderValue(void) const { - assert(false); - return VoxelType(); + return m_tBorderValue; } //////////////////////////////////////////////////////////////////////////////// @@ -181,9 +181,9 @@ namespace PolyVox /// \param tBorder The value to use for voxels outside the volume. //////////////////////////////////////////////////////////////////////////////// template - void BaseVolume::setBorderValue(const VoxelType& /*tBorder*/) + void BaseVolume::setBorderValue(const VoxelType& tBorder) { - assert(false); + m_tBorderValue = tBorder; } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 3c7a5c36..189ac286 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -117,15 +117,11 @@ namespace PolyVox /// Destructor ~RawVolume(); - /// Gets the value used for voxels which are outside the volume - VoxelType getBorderValue(void) 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; - /// 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 bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector @@ -146,9 +142,6 @@ namespace PolyVox //The block data VoxelType* m_pData; - - //The border value - VoxelType m_tBorderValue; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index a40fb53b..61acfdd8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -73,17 +73,6 @@ namespace PolyVox assert(false); // See function comment above. } - //////////////////////////////////////////////////////////////////////////////// - /// The border value is returned whenever an attempt is made to read a voxel which - /// is outside the extents of the volume. - /// \return The value used for voxels outside of the volume - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType RawVolume::getBorderValue(void) const - { - return m_tBorderValue; - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel @@ -123,15 +112,6 @@ namespace PolyVox return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - //////////////////////////////////////////////////////////////////////////////// - /// \param tBorder The value to use for voxels outside the volume. - //////////////////////////////////////////////////////////////////////////////// - template - void RawVolume::setBorderValue(const VoxelType& tBorder) - { - m_tBorderValue = tBorder; - } - //////////////////////////////////////////////////////////////////////////////// /// \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/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 97e72162..6dbffedd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -249,8 +249,8 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel0px1ny1nz(void) const - { - if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) + { + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getWidth() * this->mVolume->getHeight()); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 6d9df551..4e9d180c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -158,15 +158,11 @@ namespace PolyVox /// Destructor ~SimpleVolume(); - /// Gets the value used for voxels which are outside the volume - VoxelType getBorderValue(void) 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; - /// 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 bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector @@ -190,12 +186,6 @@ namespace PolyVox //The block data Block* m_pBlocks; - //We don't store an actual Block for the border, just the uncompressed data. This is partly because the border - //block does not have a position (so can't be passed to getUncompressedBlock()) and partly because there's a - //good chance we'll often hit it anyway. It's a chunk of homogenous data (rather than a single value) so that - //the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume. - VoxelType* m_pUncompressedBorderData; - //The size of the volume in vlocks Region m_regValidRegionInBlocks; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 12cee40f..6602bac7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -56,7 +56,6 @@ namespace PolyVox SimpleVolume::~SimpleVolume() { delete[] m_pBlocks; - delete[] m_pUncompressedBorderData; } //////////////////////////////////////////////////////////////////////////////// @@ -72,17 +71,6 @@ namespace PolyVox assert(false); // See function comment above. } - //////////////////////////////////////////////////////////////////////////////// - /// The border value is returned whenever an attempt is made to read a voxel which - /// is outside the extents of the volume. - /// \return The value used for voxels outside of the volume - //////////////////////////////////////////////////////////////////////////////// - template - VoxelType SimpleVolume::getBorderValue(void) const - { - return *m_pUncompressedBorderData; - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel @@ -122,17 +110,6 @@ namespace PolyVox return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } - //////////////////////////////////////////////////////////////////////////////// - /// \param tBorder The value to use for voxels outside the volume. - //////////////////////////////////////////////////////////////////////////////// - template - void SimpleVolume::setBorderValue(const VoxelType& tBorder) - { - /*Block* pUncompressedBorderBlock = getUncompressedBlock(&m_pBorderBlock); - return pUncompressedBorderBlock->fill(tBorder);*/ - std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, tBorder); - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel @@ -199,7 +176,6 @@ namespace PolyVox m_uBlockSideLength = uBlockSideLength; m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; - m_pUncompressedBorderData = 0; this->m_regValidRegion = regValidRegion; @@ -223,10 +199,6 @@ namespace PolyVox m_pBlocks[i].initialise(m_uBlockSideLength); } - //Create the border block - m_pUncompressedBorderData = new VoxelType[m_uNoOfVoxelsPerBlock]; - std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, VoxelType()); - //Other properties we might find useful later this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth()); this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth()); @@ -264,8 +236,8 @@ namespace PolyVox uint32_t uSizeOfBlockInBytes = m_uNoOfVoxelsPerBlock * sizeof(VoxelType); - //Memory used by the blocks ( + 1 is for border) - uSizeInBytes += uSizeOfBlockInBytes * (m_uNoOfBlocksInVolume + 1); + //Memory used by the blocks + uSizeInBytes += uSizeOfBlockInBytes * (m_uNoOfBlocksInVolume); return uSizeInBytes; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 074581e9..85ce8c10 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -144,16 +144,9 @@ namespace PolyVox uYPosInBlock * this->mVolume->m_uBlockSideLength + uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; - if(this->mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) - { - Block* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); + Block* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); - mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock; - } - else - { - mCurrentVoxel = this->mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock; - } + mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock; } /**