From 8c7056d1a999b6f13c0d6e76624ca993f502c7fd Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 24 Jul 2011 21:33:04 +0100 Subject: [PATCH] Made SimpleVolume and RawVolume derive from base Volume class. --- .../include/PolyVoxCore/LargeVolume.h | 25 +------ .../include/PolyVoxCore/LargeVolume.inl | 75 +------------------ .../include/PolyVoxCore/RawVolume.h | 7 ++ .../include/PolyVoxCore/RawVolume.inl | 20 +++++ .../include/PolyVoxCore/SimpleVolume.h | 27 +------ .../include/PolyVoxCore/SimpleVolume.inl | 74 +----------------- .../PolyVoxCore/include/PolyVoxCore/Volume.h | 3 - .../include/PolyVoxCore/Volume.inl | 5 +- 8 files changed, 40 insertions(+), 196 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 0e611446..4c111ce9 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 "PolyVoxImpl/Block.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Volume.h" #include #include @@ -141,10 +142,10 @@ namespace PolyVox /// of the block cache (amoung other problems). //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template - class LargeVolume + class LargeVolume : public Volume { public: - class Sampler + class Sampler : public Volume::Sampler { public: Sampler(LargeVolume* volume); @@ -257,20 +258,6 @@ namespace PolyVox /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the LargeVolume. - Region getEnclosingRegion(void) const; - /// Gets the width of the volume in voxels. - int32_t getWidth(void) const; - /// Gets the height of the volume in voxels. - int32_t getHeight(void) const; - /// Gets the depth of the volume in voxels. - int32_t getDepth(void) const; - /// Gets the length of the longest side in voxels - int32_t getLongestSideLength(void) const; - /// Gets the length of the shortest side in voxels - 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 getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector @@ -342,18 +329,12 @@ private: VoxelType* m_pUncompressedBorderData; //The size of the volume - Region m_regValidRegion; Region m_regValidRegionInBlocks; //The size of the blocks uint16_t m_uBlockSideLength; uint8_t m_uBlockSideLengthPower; - //Some useful sizes - int32_t m_uLongestSideLength; - int32_t m_uShortestSideLength; - float m_fDiagonalLength; - bool m_bCompressionEnabled; bool m_bPagingEnabled; }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index f21153d2..a3d8c500 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -49,6 +49,7 @@ namespace PolyVox polyvox_function&, const Region&)> dataOverflowHandler, uint16_t uBlockSideLength ) + :Volume(Region::MaxRegion) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; @@ -95,6 +96,7 @@ namespace PolyVox bool bPagingEnabled, uint16_t uBlockSideLength ) + :Volume(regValid) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; @@ -124,79 +126,6 @@ namespace PolyVox return *m_pUncompressedBorderData; } - //////////////////////////////////////////////////////////////////////////////// - /// \return A Region representing the extent of the volume. - //////////////////////////////////////////////////////////////////////////////// - template - Region LargeVolume::getEnclosingRegion(void) const - { - return m_regValidRegion; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64. - /// \sa getHeight(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getWidth(void) const - { - return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64. - /// \sa getWidth(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getHeight(void) const - { - return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64. - /// \sa getWidth(), getHeight() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getDepth(void) const - { - return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the shortest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 256. - /// \sa getLongestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getShortestSideLength(void) const - { - return m_uShortestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the longest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 1024. - /// \sa getShortestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getLongestSideLength(void) const - { - return m_uLongestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the diagonal in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024) - /// = 1173.139. This value is computed on volume creation so retrieving it is fast. - /// \sa getShortestSideLength(), getLongestSideLength() - //////////////////////////////////////////////////////////////////////////////// - template - float LargeVolume::getDiagonalLength(void) const - { - return m_fDiagonalLength; - } - //////////////////////////////////////////////////////////////////////////////// /// \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 88ad1a18..877a519e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -117,11 +117,15 @@ 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 @@ -136,6 +140,9 @@ namespace PolyVox private: //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 ab0a95aa..51d0ee6f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -63,6 +63,17 @@ namespace PolyVox m_pData = 0; } + //////////////////////////////////////////////////////////////////////////////// + /// 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 @@ -97,6 +108,15 @@ 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/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index d2c2edfc..788b98aa 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -26,6 +26,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Region.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Volume.h" #include #include @@ -33,7 +34,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - class SimpleVolume + class SimpleVolume : public Volume { public: #ifndef SWIG @@ -61,7 +62,7 @@ namespace PolyVox uint8_t m_uSideLengthPower; }; - class Sampler + class Sampler : public Volume::Sampler { public: Sampler(SimpleVolume* volume); @@ -149,20 +150,6 @@ namespace PolyVox /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the SimpleVolume. - Region getEnclosingRegion(void) const; - /// Gets the width of the volume in voxels. - int32_t getWidth(void) const; - /// Gets the height of the volume in voxels. - int32_t getHeight(void) const; - /// Gets the depth of the volume in voxels. - int32_t getDepth(void) const; - /// Gets the length of the longest side in voxels - int32_t getLongestSideLength(void) const; - /// Gets the length of the shortest side in voxels - 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 getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector @@ -193,8 +180,7 @@ private: //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 - Region m_regValidRegion; + //The size of the volume in vlocks Region m_regValidRegionInBlocks; //Volume size measured in blocks. @@ -206,11 +192,6 @@ private: //The size of the blocks uint16_t m_uBlockSideLength; uint8_t m_uBlockSideLengthPower; - - //Some useful sizes - int32_t m_uLongestSideLength; - int32_t m_uShortestSideLength; - float m_fDiagonalLength; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 3554c687..96466a58 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -69,6 +69,7 @@ namespace PolyVox const Region& regValid, uint16_t uBlockSideLength ) + :Volume(regValid) { //Create a volume of the right size. resize(regValid,uBlockSideLength); @@ -95,79 +96,6 @@ namespace PolyVox return *m_pUncompressedBorderData; } - //////////////////////////////////////////////////////////////////////////////// - /// \return A Region representing the extent of the volume. - //////////////////////////////////////////////////////////////////////////////// - template - Region SimpleVolume::getEnclosingRegion(void) const - { - return m_regValidRegion; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64. - /// \sa getHeight(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getWidth(void) const - { - return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64. - /// \sa getWidth(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getHeight(void) const - { - return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64. - /// \sa getWidth(), getHeight() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getDepth(void) const - { - return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the shortest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 256. - /// \sa getLongestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getShortestSideLength(void) const - { - return m_uShortestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the longest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 1024. - /// \sa getShortestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getLongestSideLength(void) const - { - return m_uLongestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the diagonal in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024) - /// = 1173.139. This value is computed on volume creation so retrieving it is fast. - /// \sa getShortestSideLength(), getLongestSideLength() - //////////////////////////////////////////////////////////////////////////////// - template - float SimpleVolume::getDiagonalLength(void) const - { - return m_fDiagonalLength; - } - //////////////////////////////////////////////////////////////////////////////// /// \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/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h index 2e662836..5b8f311b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -130,9 +130,6 @@ namespace PolyVox uint32_t calculateSizeInBytes(void); protected: - //The border value - VoxelType m_tBorderValue; - //The size of the volume Region m_regValidRegion; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl index 5dd05be7..0a7f4cad 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl @@ -54,7 +54,8 @@ namespace PolyVox template VoxelType Volume::getBorderValue(void) const { - return m_tBorderValue; + assert(false); + return VoxelType(); } //////////////////////////////////////////////////////////////////////////////// @@ -160,7 +161,7 @@ namespace PolyVox template void Volume::setBorderValue(const VoxelType& tBorder) { - m_tBorderValue = tBorder; + assert(false); } ////////////////////////////////////////////////////////////////////////////////