Made SimpleVolume and RawVolume derive from base Volume class.

This commit is contained in:
David Williams 2011-07-24 21:33:04 +01:00
parent 555ddc47a5
commit 8c7056d1a9
8 changed files with 40 additions and 196 deletions

View File

@ -27,6 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxImpl/Block.h" #include "PolyVoxImpl/Block.h"
#include "PolyVoxCore/Region.h" #include "PolyVoxCore/Region.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Volume.h"
#include <limits> #include <limits>
#include <map> #include <map>
@ -141,10 +142,10 @@ namespace PolyVox
/// of the block cache (amoung other problems). /// of the block cache (amoung other problems).
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> template <typename VoxelType>
class LargeVolume class LargeVolume : public Volume<VoxelType>
{ {
public: public:
class Sampler class Sampler : public Volume<VoxelType>::Sampler
{ {
public: public:
Sampler(LargeVolume<VoxelType>* volume); Sampler(LargeVolume<VoxelType>* volume);
@ -257,20 +258,6 @@ namespace PolyVox
/// Gets the value used for voxels which are outside the volume /// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(void) const; 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 <tt>x,y,z</tt> coordinates /// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector /// Gets a voxel at the position given by a 3D vector
@ -342,18 +329,12 @@ private:
VoxelType* m_pUncompressedBorderData; VoxelType* m_pUncompressedBorderData;
//The size of the volume //The size of the volume
Region m_regValidRegion;
Region m_regValidRegionInBlocks; Region m_regValidRegionInBlocks;
//The size of the blocks //The size of the blocks
uint16_t m_uBlockSideLength; uint16_t m_uBlockSideLength;
uint8_t m_uBlockSideLengthPower; uint8_t m_uBlockSideLengthPower;
//Some useful sizes
int32_t m_uLongestSideLength;
int32_t m_uShortestSideLength;
float m_fDiagonalLength;
bool m_bCompressionEnabled; bool m_bCompressionEnabled;
bool m_bPagingEnabled; bool m_bPagingEnabled;
}; };

View File

@ -49,6 +49,7 @@ namespace PolyVox
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler, polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
uint16_t uBlockSideLength uint16_t uBlockSideLength
) )
:Volume<VoxelType>(Region::MaxRegion)
{ {
m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataRequiredHandler = dataRequiredHandler;
m_funcDataOverflowHandler = dataOverflowHandler; m_funcDataOverflowHandler = dataOverflowHandler;
@ -95,6 +96,7 @@ namespace PolyVox
bool bPagingEnabled, bool bPagingEnabled,
uint16_t uBlockSideLength uint16_t uBlockSideLength
) )
:Volume<VoxelType>(regValid)
{ {
m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataRequiredHandler = dataRequiredHandler;
m_funcDataOverflowHandler = dataOverflowHandler; m_funcDataOverflowHandler = dataOverflowHandler;
@ -124,79 +126,6 @@ namespace PolyVox
return *m_pUncompressedBorderData; return *m_pUncompressedBorderData;
} }
////////////////////////////////////////////////////////////////////////////////
/// \return A Region representing the extent of the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
Region LargeVolume<VoxelType>::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 <typename VoxelType>
int32_t LargeVolume<VoxelType>::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 <typename VoxelType>
int32_t LargeVolume<VoxelType>::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 <typename VoxelType>
int32_t LargeVolume<VoxelType>::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 <typename VoxelType>
int32_t LargeVolume<VoxelType>::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 <typename VoxelType>
int32_t LargeVolume<VoxelType>::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 <typename VoxelType>
float LargeVolume<VoxelType>::getDiagonalLength(void) const
{
return m_fDiagonalLength;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel /// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel /// \param uYPos The \c y position of the voxel

View File

@ -117,11 +117,15 @@ namespace PolyVox
/// Destructor /// Destructor
~RawVolume(); ~RawVolume();
/// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(void) const;
/// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates /// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector /// Gets a voxel at the position given by a 3D vector
VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; 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 <tt>x,y,z</tt> coordinates /// Sets the voxel at the position given by <tt>x,y,z</tt> coordinates
bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue);
/// Sets the voxel at the position given by a 3D vector /// Sets the voxel at the position given by a 3D vector
@ -136,6 +140,9 @@ namespace PolyVox
private: private:
//The block data //The block data
VoxelType* m_pData; VoxelType* m_pData;
//The border value
VoxelType m_tBorderValue;
}; };
} }

View File

@ -63,6 +63,17 @@ namespace PolyVox
m_pData = 0; 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 <typename VoxelType>
VoxelType RawVolume<VoxelType>::getBorderValue(void) const
{
return m_tBorderValue;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel /// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y 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()); return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
} }
////////////////////////////////////////////////////////////////////////////////
/// \param tBorder The value to use for voxels outside the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
void RawVolume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{
m_tBorderValue = tBorder;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// \param uXPos the \c x position of the voxel /// \param uXPos the \c x position of the voxel
/// \param uYPos the \c y position of the voxel /// \param uYPos the \c y position of the voxel

View File

@ -26,6 +26,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Region.h" #include "PolyVoxCore/Region.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Volume.h"
#include <limits> #include <limits>
#include <memory> #include <memory>
@ -33,7 +34,7 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
template <typename VoxelType> template <typename VoxelType>
class SimpleVolume class SimpleVolume : public Volume<VoxelType>
{ {
public: public:
#ifndef SWIG #ifndef SWIG
@ -61,7 +62,7 @@ namespace PolyVox
uint8_t m_uSideLengthPower; uint8_t m_uSideLengthPower;
}; };
class Sampler class Sampler : public Volume<VoxelType>::Sampler
{ {
public: public:
Sampler(SimpleVolume<VoxelType>* volume); Sampler(SimpleVolume<VoxelType>* volume);
@ -149,20 +150,6 @@ namespace PolyVox
/// Gets the value used for voxels which are outside the volume /// Gets the value used for voxels which are outside the volume
VoxelType getBorderValue(void) const; 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 <tt>x,y,z</tt> coordinates /// Gets a voxel at the position given by <tt>x,y,z</tt> coordinates
VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const;
/// Gets a voxel at the position given by a 3D vector /// 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. //the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume.
VoxelType* m_pUncompressedBorderData; VoxelType* m_pUncompressedBorderData;
//The size of the volume //The size of the volume in vlocks
Region m_regValidRegion;
Region m_regValidRegionInBlocks; Region m_regValidRegionInBlocks;
//Volume size measured in blocks. //Volume size measured in blocks.
@ -206,11 +192,6 @@ private:
//The size of the blocks //The size of the blocks
uint16_t m_uBlockSideLength; uint16_t m_uBlockSideLength;
uint8_t m_uBlockSideLengthPower; uint8_t m_uBlockSideLengthPower;
//Some useful sizes
int32_t m_uLongestSideLength;
int32_t m_uShortestSideLength;
float m_fDiagonalLength;
}; };
} }

View File

@ -69,6 +69,7 @@ namespace PolyVox
const Region& regValid, const Region& regValid,
uint16_t uBlockSideLength uint16_t uBlockSideLength
) )
:Volume<VoxelType>(regValid)
{ {
//Create a volume of the right size. //Create a volume of the right size.
resize(regValid,uBlockSideLength); resize(regValid,uBlockSideLength);
@ -95,79 +96,6 @@ namespace PolyVox
return *m_pUncompressedBorderData; return *m_pUncompressedBorderData;
} }
////////////////////////////////////////////////////////////////////////////////
/// \return A Region representing the extent of the volume.
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
Region SimpleVolume<VoxelType>::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 <typename VoxelType>
int32_t SimpleVolume<VoxelType>::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 <typename VoxelType>
int32_t SimpleVolume<VoxelType>::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 <typename VoxelType>
int32_t SimpleVolume<VoxelType>::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 <typename VoxelType>
int32_t SimpleVolume<VoxelType>::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 <typename VoxelType>
int32_t SimpleVolume<VoxelType>::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 <typename VoxelType>
float SimpleVolume<VoxelType>::getDiagonalLength(void) const
{
return m_fDiagonalLength;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// \param uXPos The \c x position of the voxel /// \param uXPos The \c x position of the voxel
/// \param uYPos The \c y position of the voxel /// \param uYPos The \c y position of the voxel

View File

@ -130,9 +130,6 @@ namespace PolyVox
uint32_t calculateSizeInBytes(void); uint32_t calculateSizeInBytes(void);
protected: protected:
//The border value
VoxelType m_tBorderValue;
//The size of the volume //The size of the volume
Region m_regValidRegion; Region m_regValidRegion;

View File

@ -54,7 +54,8 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
VoxelType Volume<VoxelType>::getBorderValue(void) const VoxelType Volume<VoxelType>::getBorderValue(void) const
{ {
return m_tBorderValue; assert(false);
return VoxelType();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -160,7 +161,7 @@ namespace PolyVox
template <typename VoxelType> template <typename VoxelType>
void Volume<VoxelType>::setBorderValue(const VoxelType& tBorder) void Volume<VoxelType>::setBorderValue(const VoxelType& tBorder)
{ {
m_tBorderValue = tBorder; assert(false);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////