From 7177db44acd0813ba8a37f16d7f4bd8aa4db46cc Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 20 Apr 2008 18:44:00 +0000 Subject: [PATCH] Templatized Block class. --- CMakeLists.txt | 2 +- include/Block.h | 11 +++++++---- source/Block.cpp => include/Block.inl | 22 ++++++++++++---------- include/PolyVoxForwardDeclarations.h | 2 +- include/Volume.h | 4 ++-- source/Volume.cpp | 4 ++-- source/VolumeIterator.cpp | 14 +++++++------- 7 files changed, 32 insertions(+), 27 deletions(-) rename source/Block.cpp => include/Block.inl (70%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57218438..32772e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ PROJECT(PolyVoxSceneManager) #Projects source files SET(SRC_FILES - source/Block.cpp source/IndexedSurfacePatch.cpp source/MarchingCubesTables.cpp source/PolyVoxSceneManager.cpp @@ -15,6 +14,7 @@ SET(SRC_FILES #Projects headers files SET(INC_FILES include/Block.h + include/Block.inl include/Constants.h include/IndexedSurfacePatch.h include/MarchingCubesTables.h diff --git a/include/Block.h b/include/Block.h index 8d96cae7..fd0aa559 100644 --- a/include/Block.h +++ b/include/Block.h @@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. namespace PolyVox { - class POLYVOX_API Block + template + class Block { //Make VolumeIterator a friend friend class VolumeIterator; @@ -46,14 +47,16 @@ namespace PolyVox //bool isHomogeneous(void); - boost::uint8_t 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); + 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 VoxelType value); //void fillWithValue(const uint8_t value); private: - boost::uint8_t mData[POLYVOX_NO_OF_VOXELS_IN_BLOCK]; + VoxelType mData[POLYVOX_NO_OF_VOXELS_IN_BLOCK]; }; } +#include "Block.inl" + #endif diff --git a/source/Block.cpp b/include/Block.inl similarity index 70% rename from source/Block.cpp rename to include/Block.inl index 13aa0c6a..73bb8f65 100644 --- a/source/Block.cpp +++ b/include/Block.inl @@ -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. ******************************************************************************/ -#include "Block.h" - #include -using namespace boost; - namespace PolyVox { - Block::Block() + template + Block::Block() { } - Block::Block(const Block& rhs) + template + Block::Block(const Block& rhs) { *this = rhs; } - Block::~Block() + template + Block::~Block() { } - Block& Block::operator=(const Block& rhs) + template + Block& Block::operator=(const Block& rhs) { if (this == &rhs) { @@ -51,7 +51,8 @@ namespace PolyVox return *this; } - uint8_t Block::getVoxelAt(const uint16_t xPosition, const uint16_t yPosition, const uint16_t zPosition) const + template + VoxelType Block::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const { 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 + void Block::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value) { mData [ diff --git a/include/PolyVoxForwardDeclarations.h b/include/PolyVoxForwardDeclarations.h index 780e6555..75d6a71b 100644 --- a/include/PolyVoxForwardDeclarations.h +++ b/include/PolyVoxForwardDeclarations.h @@ -5,7 +5,7 @@ namespace PolyVox { - class Block; + template class Block; class IndexedSurfacePatch; class IntegrealVector3; class PolyVoxSceneManager; diff --git a/include/Volume.h b/include/Volume.h index c55b7e8d..5fd087ce 100644 --- a/include/Volume.h +++ b/include/Volume.h @@ -43,7 +43,7 @@ namespace PolyVox Volume& operator=(const Volume& rhs); public: - Block* getBlock(boost::uint16_t index); + Block* getBlock(boost::uint16_t index); bool containsPoint(Vector3DFloat pos, float boundary); bool containsPoint(Vector3DInt32 pos, boost::uint16_t boundary); @@ -55,7 +55,7 @@ namespace PolyVox void tidy(void); private: - Block* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME]; + Block* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME]; }; } diff --git a/source/Volume.cpp b/source/Volume.cpp index 4f3be715..7673563e 100644 --- a/source/Volume.cpp +++ b/source/Volume.cpp @@ -34,7 +34,7 @@ namespace PolyVox { for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) { - mBlocks[i] = new Block; + mBlocks[i] = new Block; } } @@ -124,7 +124,7 @@ namespace PolyVox block->setVoxelAt(xOffset,yOffset,zOffset, value); }*/ - Block* Volume::getBlock(uint16_t index) + Block* Volume::getBlock(uint16_t index) { return mBlocks[index]; } diff --git a/source/VolumeIterator.cpp b/source/VolumeIterator.cpp index 284cbf5d..50feba6b 100644 --- a/source/VolumeIterator.cpp +++ b/source/VolumeIterator.cpp @@ -62,7 +62,7 @@ namespace PolyVox void VolumeIterator::setVoxel(uint8_t value) { - Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; + Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; /*if(!currentBlock.unique()) { @@ -91,7 +91,7 @@ namespace PolyVox const uint16_t yOffset = yPosition - (blockY << POLYVOX_BLOCK_SIDE_LENGTH_POWER); const uint16_t zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER); - const Block* block = mVolume.mBlocks + const Block* block = mVolume.mBlocks [ blockX + 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 zOffset = zPosition - (blockZ << POLYVOX_BLOCK_SIDE_LENGTH_POWER); - Block* block = mVolume.mBlocks + Block* block = mVolume.mBlocks [ blockX + blockY * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS + @@ -324,7 +324,7 @@ namespace PolyVox mBlockIndexInVolume = mXBlock + mYBlock * 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* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; mVoxelIndexInBlock = mXPosInBlock + mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH + @@ -372,7 +372,7 @@ namespace PolyVox mVoxelIndexInBlock = mXPosInBlock + mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH + mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH; - Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; + Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; mYPosInBlock++; @@ -385,7 +385,7 @@ namespace PolyVox mVoxelIndexInBlock = mXPosInBlock + mYPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH + mZPosInBlock * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH; - Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; + Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; mZPosInBlock++; @@ -424,7 +424,7 @@ namespace PolyVox } } - Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; + Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; //mCurrentBlock = mVolume->mBlocks[mBlockIndexInVolume]; mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * POLYVOX_BLOCK_SIDE_LENGTH));