Templatized Block class.
This commit is contained in:
parent
35f9996663
commit
7177db44ac
@ -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
|
||||
|
@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOX_API Block
|
||||
template <typename VoxelType>
|
||||
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
|
||||
|
@ -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 <cstring>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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 <typename VoxelType>
|
||||
VoxelType Block<VoxelType>::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 <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
|
||||
[
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class Block;
|
||||
template <typename VoxelType> class Block;
|
||||
class IndexedSurfacePatch;
|
||||
class IntegrealVector3;
|
||||
class PolyVoxSceneManager;
|
||||
|
@ -43,7 +43,7 @@ namespace PolyVox
|
||||
Volume& operator=(const Volume& rhs);
|
||||
|
||||
public:
|
||||
Block* getBlock(boost::uint16_t index);
|
||||
Block<boost::uint8_t>* 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<boost::uint8_t>* mBlocks[POLYVOX_NO_OF_BLOCKS_IN_VOLUME];
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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<boost::uint8_t>;
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ namespace PolyVox
|
||||
block->setVoxelAt(xOffset,yOffset,zOffset, value);
|
||||
}*/
|
||||
|
||||
Block* Volume::getBlock(uint16_t index)
|
||||
Block<boost::uint8_t>* Volume::getBlock(uint16_t index)
|
||||
{
|
||||
return mBlocks[index];
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace PolyVox
|
||||
|
||||
void VolumeIterator::setVoxel(uint8_t value)
|
||||
{
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* 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<boost::uint8_t>* 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<boost::uint8_t>* 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<boost::uint8_t>* 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<boost::uint8_t>* 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<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
mCurrentVoxel = currentBlock->mData + mVoxelIndexInBlock;
|
||||
|
||||
mZPosInBlock++;
|
||||
@ -424,7 +424,7 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
Block* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
Block<boost::uint8_t>* currentBlock = mVolume.mBlocks[mBlockIndexInVolume];
|
||||
//mCurrentBlock = mVolume->mBlocks[mBlockIndexInVolume];
|
||||
|
||||
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * POLYVOX_BLOCK_SIDE_LENGTH));
|
||||
|
Loading…
x
Reference in New Issue
Block a user