Templatized Block class.

This commit is contained in:
David Williams 2008-04-20 18:44:00 +00:00
parent 35f9996663
commit 7177db44ac
7 changed files with 32 additions and 27 deletions

View File

@ -2,7 +2,6 @@ PROJECT(PolyVoxSceneManager)
#Projects source files #Projects source files
SET(SRC_FILES SET(SRC_FILES
source/Block.cpp
source/IndexedSurfacePatch.cpp source/IndexedSurfacePatch.cpp
source/MarchingCubesTables.cpp source/MarchingCubesTables.cpp
source/PolyVoxSceneManager.cpp source/PolyVoxSceneManager.cpp
@ -15,6 +14,7 @@ SET(SRC_FILES
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
include/Block.h include/Block.h
include/Block.inl
include/Constants.h include/Constants.h
include/IndexedSurfacePatch.h include/IndexedSurfacePatch.h
include/MarchingCubesTables.h include/MarchingCubesTables.h

View File

@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace PolyVox namespace PolyVox
{ {
class POLYVOX_API Block template <typename VoxelType>
class Block
{ {
//Make VolumeIterator a friend //Make VolumeIterator a friend
friend class VolumeIterator; friend class VolumeIterator;
@ -46,14 +47,16 @@ namespace PolyVox
//bool isHomogeneous(void); //bool isHomogeneous(void);
boost::uint8_t getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const; VoxelType getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const;
void setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const boost::uint8_t value); void setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value);
//void fillWithValue(const uint8_t value); //void fillWithValue(const uint8_t value);
private: private:
boost::uint8_t mData[POLYVOX_NO_OF_VOXELS_IN_BLOCK]; VoxelType mData[POLYVOX_NO_OF_VOXELS_IN_BLOCK];
}; };
} }
#include "Block.inl"
#endif #endif

View File

@ -17,29 +17,29 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/ ******************************************************************************/
#include "Block.h"
#include <cstring> #include <cstring>
using namespace boost;
namespace PolyVox namespace PolyVox
{ {
Block::Block() template <typename VoxelType>
Block<VoxelType>::Block()
{ {
} }
Block::Block(const Block& rhs) template <typename VoxelType>
Block<VoxelType>::Block(const Block<VoxelType>& rhs)
{ {
*this = rhs; *this = rhs;
} }
Block::~Block() template <typename VoxelType>
Block<VoxelType>::~Block()
{ {
} }
Block& Block::operator=(const Block& rhs) template <typename VoxelType>
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
{ {
if (this == &rhs) if (this == &rhs)
{ {
@ -51,7 +51,8 @@ namespace PolyVox
return *this; return *this;
} }
uint8_t Block::getVoxelAt(const uint16_t xPosition, const uint16_t yPosition, const uint16_t zPosition) const template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const
{ {
return mData return mData
[ [
@ -61,7 +62,8 @@ namespace PolyVox
]; ];
} }
void Block::setVoxelAt(const uint16_t xPosition, const uint16_t yPosition, const uint16_t zPosition, const uint8_t value) template <typename VoxelType>
void Block<VoxelType>::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value)
{ {
mData mData
[ [

View File

@ -5,7 +5,7 @@
namespace PolyVox namespace PolyVox
{ {
class Block; template <typename VoxelType> class Block;
class IndexedSurfacePatch; class IndexedSurfacePatch;
class IntegrealVector3; class IntegrealVector3;
class PolyVoxSceneManager; class PolyVoxSceneManager;

View File

@ -43,7 +43,7 @@ namespace PolyVox
Volume& operator=(const Volume& rhs); Volume& operator=(const Volume& rhs);
public: public:
Block* getBlock(boost::uint16_t index); Block<boost::uint8_t>* getBlock(boost::uint16_t index);
bool containsPoint(Vector3DFloat pos, float boundary); bool containsPoint(Vector3DFloat pos, float boundary);
bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary); bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary);
@ -55,7 +55,7 @@ namespace PolyVox
void tidy(void); void tidy(void);
private: private:
Block* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME]; Block<boost::uint8_t>* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME];
}; };
} }

View File

@ -34,7 +34,7 @@ namespace PolyVox
{ {
for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
{ {
mBlocks[i] = new Block; mBlocks[i] = new Block<boost::uint8_t>;
} }
} }
@ -124,7 +124,7 @@ namespace PolyVox
block->setVoxelAt(xOffset,yOffset,zOffset, value); block->setVoxelAt(xOffset,yOffset,zOffset, value);
}*/ }*/
Block* Volume::getBlock(uint16_t index) Block<boost::uint8_t>* Volume::getBlock(uint16_t index)
{ {
return mBlocks[index]; return mBlocks[index];
} }

View File

@ -62,7 +62,7 @@ namespace PolyVox
void VolumeIterator::setVoxel(uint8_t value) void VolumeIterator::setVoxel(uint8_t value)
{ {
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
/*if(!currentBlock.unique()) /*if(!currentBlock.unique())
{ {
@ -91,7 +91,7 @@ namespace PolyVox
const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER); const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER); const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
const Block* block = mVolume.mBlocks const Block<boost::uint8_t>* block = mVolume.mBlocks
[ [
blockX + blockX +
blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS + blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS +
@ -135,7 +135,7 @@ namespace PolyVox
const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER); const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER); const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
Block* block = mVolume.mBlocks Block<boost::uint8_t>* block = mVolume.mBlocks
[ [
blockX + blockX +
blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS + blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS +
@ -324,7 +324,7 @@ namespace PolyVox
mBlockIndexInVolume = mXBlock + mBlockIndexInVolume = mXBlock +
mYBlock * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS + mYBlock * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS +
mZBlock * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS; mZBlock * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS;
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
mVoxelIndexInBlock = mXPosInBlock + mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH + mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH +
@ -372,7 +372,7 @@ namespace PolyVox
mVoxelIndexInBlock = mXPosInBlock + mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH + mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH +
mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH; mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH;
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock;
mYPosInBlock++; mYPosInBlock++;
@ -385,7 +385,7 @@ namespace PolyVox
mVoxelIndexInBlock = mXPosInBlock + mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH + mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH +
mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH; mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH;
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock;
mZPosInBlock++; mZPosInBlock++;
@ -424,7 +424,7 @@ namespace PolyVox
} }
} }
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
//mCurrentBlock = mVolume->mBlocks[mBlockIndexInVolume]; //mCurrentBlock = mVolume->mBlocks[mBlockIndexInVolume];
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * POLYVOX_BLOCK_SIDE_LENGTH)); mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * POLYVOX_BLOCK_SIDE_LENGTH));