Changes to allow varying block sizes.
This commit is contained in:
		| @@ -23,11 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | |||||||
| #define __PolyVox_Block_H__ | #define __PolyVox_Block_H__ | ||||||
|  |  | ||||||
| #pragma region Headers | #pragma region Headers | ||||||
| #include "boost/cstdint.hpp" |  | ||||||
|  |  | ||||||
| #include "Constants.h" | #include "Constants.h" | ||||||
| #include "PolyVoxForwardDeclarations.h" | #include "PolyVoxForwardDeclarations.h" | ||||||
| #include "TypeDef.h" | #include "TypeDef.h" | ||||||
|  |  | ||||||
|  | #include "boost/cstdint.hpp" | ||||||
| #pragma endregion | #pragma endregion | ||||||
|  |  | ||||||
| namespace PolyVox | namespace PolyVox | ||||||
| @@ -40,7 +40,7 @@ namespace PolyVox | |||||||
|  |  | ||||||
| 		//Block interface | 		//Block interface | ||||||
| 	public: | 	public: | ||||||
| 		Block(); | 		Block(boost::uint8_t uSideLengthPower); | ||||||
| 		Block(const Block& rhs); | 		Block(const Block& rhs); | ||||||
| 		~Block(); | 		~Block(); | ||||||
|  |  | ||||||
| @@ -48,13 +48,18 @@ namespace PolyVox | |||||||
|  |  | ||||||
| 		//bool isHomogeneous(void); | 		//bool isHomogeneous(void); | ||||||
|  |  | ||||||
|  | 		boost::uint16_t getSideLength(void); | ||||||
|  |  | ||||||
| 		VoxelType 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 VoxelType value); | 		void setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value); | ||||||
|  |  | ||||||
| 		//void fillWithValue(const VoxelType value); | 		//void fillWithValue(const VoxelType value); | ||||||
|  |  | ||||||
| 	private: | 	private: | ||||||
| 		VoxelType mData[POLYVOX_NO_OF_VOXELS_IN_BLOCK];		 | 		boost::uint32_t getNoOfVoxels(void); | ||||||
|  | 		boost::uint8_t m_uSideLengthPower; | ||||||
|  | 		boost::uint16_t m_uSideLength; | ||||||
|  | 		VoxelType* m_tData;		 | ||||||
| 	}; | 	}; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,8 +23,19 @@ namespace PolyVox | |||||||
| { | { | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| 	Block<VoxelType>::Block() | 	Block<VoxelType>::Block(boost::uint8_t uSideLengthPower) | ||||||
|  | 		:m_tData(0) | ||||||
| 	{ | 	{ | ||||||
|  | 		//Check the block size is sensible. This corresponds to a side length of 256 voxels | ||||||
|  | 		assert(uSideLengthPower <= 8); | ||||||
|  |  | ||||||
|  | 		//Compute the side length | ||||||
|  | 		m_uSideLengthPower = uSideLengthPower; | ||||||
|  | 		m_uSideLength = 0x01 << uSideLengthPower; | ||||||
|  |  | ||||||
|  | 		//If this fails an exception will be thrown. Memory is not    | ||||||
|  | 		//allocated and there is nothing else in this class to clean up | ||||||
|  | 		m_tData = new VoxelType[getNoOfVoxels()]; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| @@ -36,6 +47,8 @@ namespace PolyVox | |||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| 	Block<VoxelType>::~Block() | 	Block<VoxelType>::~Block() | ||||||
| 	{ | 	{ | ||||||
|  | 		delete[] m_tData; | ||||||
|  | 		m_tData = 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| @@ -46,7 +59,7 @@ namespace PolyVox | |||||||
| 			return *this; | 			return *this; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		memcpy(mData,rhs.mData,POLYVOX_NO_OF_VOXELS_IN_BLOCK); | 		memcpy(m_tData,rhs.m_tData,getNoOfVoxels()); | ||||||
|  |  | ||||||
| 		return *this; | 		return *this; | ||||||
| 	} | 	} | ||||||
| @@ -54,25 +67,37 @@ namespace PolyVox | |||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| 	VoxelType Block<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const | 	VoxelType Block<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const | ||||||
| 	{ | 	{ | ||||||
| 		return mData | 		return m_tData | ||||||
| 			[ | 			[ | ||||||
| 				xPosition +  | 				xPosition +  | ||||||
| 				yPosition * POLYVOX_BLOCK_SIDE_LENGTH +  | 				yPosition * m_uSideLength +  | ||||||
| 				zPosition * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH | 				zPosition * m_uSideLength * m_uSideLength | ||||||
| 			]; | 			]; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	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) | 	void Block<VoxelType>::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value) | ||||||
| 	{ | 	{ | ||||||
| 		mData | 		m_tData | ||||||
| 			[ | 			[ | ||||||
| 				xPosition +  | 				xPosition +  | ||||||
| 				yPosition * POLYVOX_BLOCK_SIDE_LENGTH +  | 				yPosition * m_uSideLength +  | ||||||
| 				zPosition * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH | 				zPosition * m_uSideLength * m_uSideLength | ||||||
| 			] = value; | 			] = value; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	template <typename VoxelType> | ||||||
|  | 	boost::uint16_t Block<VoxelType>::getSideLength(void) | ||||||
|  | 	{ | ||||||
|  | 		return m_uSideLength; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	template <typename VoxelType> | ||||||
|  | 	boost::uint32_t Block<VoxelType>::getNoOfVoxels(void) | ||||||
|  | 	{ | ||||||
|  | 		return m_uSideLength * m_uSideLength * m_uSideLength; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/*void Block::fillWithValue(const VoxelType value) | 	/*void Block::fillWithValue(const VoxelType value) | ||||||
| 	{ | 	{ | ||||||
| 		memset(mData,value,POLYVOX_NO_OF_VOXELS_IN_BLOCK); | 		memset(mData,value,POLYVOX_NO_OF_VOXELS_IN_BLOCK); | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ namespace PolyVox | |||||||
| 	{ | 	{ | ||||||
| 		for(boost::uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) | 		for(boost::uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i) | ||||||
| 		{ | 		{ | ||||||
| 			mBlocks[i] = new Block<VoxelType>; | 			mBlocks[i] = new Block<VoxelType>(POLYVOX_BLOCK_SIDE_LENGTH_POWER); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -49,7 +49,7 @@ namespace PolyVox | |||||||
| 		,mYPosInBlock(0) | 		,mYPosInBlock(0) | ||||||
| 		,mZPosInBlock(0) | 		,mZPosInBlock(0) | ||||||
| 		,mIsValidForRegion(true) | 		,mIsValidForRegion(true) | ||||||
| 		,mCurrentVoxel(volume.mBlocks[0]->mData) | 		,mCurrentVoxel(volume.mBlocks[0]->m_tData) | ||||||
| 		//,mCurrentBlock(volume->mBlocks[0]) | 		//,mCurrentBlock(volume->mBlocks[0]) | ||||||
| 		,mVoxelIndexInBlock(0) | 		,mVoxelIndexInBlock(0) | ||||||
| 		,mBlockIndexInVolume(0) | 		,mBlockIndexInVolume(0) | ||||||
| @@ -172,7 +172,7 @@ namespace PolyVox | |||||||
| 			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; | ||||||
|  |  | ||||||
| 		mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; | 		mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| @@ -217,7 +217,7 @@ namespace PolyVox | |||||||
| 				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<VoxelType>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; | 			Block<VoxelType>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; | ||||||
| 			mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; | 			mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock; | ||||||
|  |  | ||||||
| 			mYPosInBlock++; | 			mYPosInBlock++; | ||||||
| 			mYPosInVolume++; | 			mYPosInVolume++; | ||||||
| @@ -230,7 +230,7 @@ namespace PolyVox | |||||||
| 					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<VoxelType>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; | 				Block<VoxelType>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume]; | ||||||
| 				mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; | 				mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock; | ||||||
|  |  | ||||||
| 				mZPosInBlock++; | 				mZPosInBlock++; | ||||||
| 				mZPosInVolume++; | 				mZPosInVolume++; | ||||||
| @@ -283,7 +283,7 @@ namespace PolyVox | |||||||
| 						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; | ||||||
|  |  | ||||||
| 					mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock; | 					mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		}		 | 		}		 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user