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

@ -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

93
include/Block.inl Normal file
View File

@ -0,0 +1,93 @@
/******************************************************************************
This file is part of a voxel plugin for OGRE
Copyright (C) 2006 David Williams
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
#include <cstring>
namespace PolyVox
{
template <typename VoxelType>
Block<VoxelType>::Block()
{
}
template <typename VoxelType>
Block<VoxelType>::Block(const Block<VoxelType>& rhs)
{
*this = rhs;
}
template <typename VoxelType>
Block<VoxelType>::~Block()
{
}
template <typename VoxelType>
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
{
if (this == &rhs)
{
return *this;
}
memcpy(mData,rhs.mData,POLYVOX_NO_OF_VOXELS_IN_BLOCK);
return *this;
}
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
[
xPosition +
yPosition * POLYVOX_BLOCK_SIDE_LENGTH +
zPosition * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH
];
}
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
[
xPosition +
yPosition * POLYVOX_BLOCK_SIDE_LENGTH +
zPosition * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH
] = value;
}
/*void Block::fillWithValue(const uint8_t value)
{
memset(mData,value,POLYVOX_NO_OF_VOXELS_IN_BLOCK);
}*/
/*bool Block::isHomogeneous(void)
{
uint8_t uFirstVoxel = mData[0];
for(uint32_t ct = 1; ct < POLYVOX_NO_OF_VOXELS_IN_BLOCK; ++ct)
{
if(mData[ct] != uFirstVoxel)
{
return false;
}
}
return true;
}*/
}

View File

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

View File

@ -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];
};
}