Moved some code around...

This commit is contained in:
David Williams
2008-06-08 18:03:20 +00:00
parent f75805999d
commit adff2177fd
38 changed files with 0 additions and 0 deletions

View File

@ -1,61 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_Block_H__
#define __PolyVox_Block_H__
#pragma region Headers
#include "PolyVoxForwardDeclarations.h"
#include "boost/cstdint.hpp"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class Block
{
//Make BlockVolumeIterator a friend
friend class BlockVolumeIterator<VoxelType>;
public:
Block(boost::uint8_t uSideLengthPower);
Block(const Block& rhs);
~Block();
Block& operator=(const Block& rhs);
boost::uint16_t getSideLength(void) const;
VoxelType getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const;
void setVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos, VoxelType tValue);
void fill(VoxelType tValue);
private:
boost::uint8_t m_uSideLengthPower;
boost::uint16_t m_uSideLength;
VoxelType* m_tData;
};
}
#include "Block.inl"
#endif

View File

@ -1,124 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#pragma region Headers
#include <cassert>
#include <cstring> //For memcpy
#include <stdexcept> //for std::invalid_argument
#pragma endregion
namespace PolyVox
{
#pragma region Constructors/Destructors
template <typename VoxelType>
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
if(uSideLengthPower > 8)
{
throw std::invalid_argument("Block side length power must be less than or equal to eight");
}
//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[m_uSideLength * m_uSideLength * m_uSideLength];
}
template <typename VoxelType>
Block<VoxelType>::Block(const Block<VoxelType>& rhs)
{
*this = rhs;
}
template <typename VoxelType>
Block<VoxelType>::~Block()
{
delete[] m_tData;
m_tData = 0;
}
#pragma endregion
#pragma region Operators
template <typename VoxelType>
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
{
if (this == &rhs)
{
return *this;
}
memcpy(m_tData, rhs.m_tData, m_uSideLength * m_uSideLength * m_uSideLength);
return *this;
}
#pragma endregion
#pragma region Getters
template <typename VoxelType>
boost::uint16_t Block<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const
{
assert(uXPos < m_uSideLength);
assert(uYPos < m_uSideLength);
assert(uZPos < m_uSideLength);
return m_tData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
];
}
#pragma endregion
#pragma region Setters
template <typename VoxelType>
void Block<VoxelType>::setVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos, VoxelType tValue)
{
assert(uXPos < m_uSideLength);
assert(uYPos < m_uSideLength);
assert(uZPos < m_uSideLength);
m_tData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
] = tValue;
}
#pragma endregion
#pragma region Other
template <typename VoxelType>
void Block<VoxelType>::fill(VoxelType tValue)
{
memset(m_tData, tValue, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
}
#pragma endregion
}

View File

@ -1,86 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_BlockVolume_H__
#define __PolyVox_BlockVolume_H__
#pragma region Headers
#include "PolyVoxForwardDeclarations.h"
#include "boost/cstdint.hpp"
#include <map>
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class BlockVolume
{
//Make BlockVolumeIterator a friend
friend class BlockVolumeIterator<VoxelType>;
public:
BlockVolume(boost::uint8_t uSideLengthPower, boost::uint8_t uBlockSideLengthPower = 5);
BlockVolume(const BlockVolume& rhs);
~BlockVolume();
BlockVolume& operator=(const BlockVolume& rhs);
Region getEnclosingRegion(void) const;
boost::uint16_t getSideLength(void) const;
VoxelType getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const;
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
bool containsPoint(const Vector3DInt32& pos, boost::uint16_t boundary) const;
BlockVolumeIterator<VoxelType> firstVoxel(void);
void idle(boost::uint32_t uAmount);
BlockVolumeIterator<VoxelType> lastVoxel(void);
private:
Block<VoxelType>* getHomogenousBlock(VoxelType tHomogenousValue) const;
Block<VoxelType>** m_pBlocks;
bool* m_pIsShared;
bool* m_pIsPotentiallySharable;
VoxelType* m_pHomogenousValue;
mutable std::map<VoxelType, Block<VoxelType>*> m_pHomogenousBlocks;
boost::uint32_t m_uNoOfBlocksInVolume;
boost::uint16_t m_uSideLengthInBlocks;
boost::uint8_t m_uSideLengthPower;
boost::uint16_t m_uSideLength;
boost::uint8_t m_uBlockSideLengthPower;
boost::uint16_t m_uBlockSideLength;
};
//Some handy typedefs
typedef BlockVolume<float> FloatBlockVolume;
typedef BlockVolume<boost::uint8_t> UInt8BlockVolume;
typedef BlockVolume<boost::uint16_t> UInt16BlockVolume;
}
#include "BlockVolume.inl"
#endif

View File

@ -1,231 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#pragma region Headers
#include "Block.h"
#include "Region.h"
#include "Vector.h"
#include <cassert>
#include <cstring> //For memcpy
#pragma endregion
namespace PolyVox
{
#pragma region Constructors/Destructors
template <typename VoxelType>
BlockVolume<VoxelType>::BlockVolume(boost::uint8_t uSideLengthPower, boost::uint8_t uBlockSideLengthPower)
:m_pBlocks(0)
{
//Check the volume size is sensible. This corresponds to a side length of 65536 voxels
if(uSideLengthPower > 16)
{
throw std::invalid_argument("Volume side length power must be less than or equal to 16");
}
//Compute the volume side length
m_uSideLengthPower = uSideLengthPower;
m_uSideLength = 0x01 << uSideLengthPower;
//Compute the block side length
m_uBlockSideLengthPower = uBlockSideLengthPower;
m_uBlockSideLength = 0x01 << uBlockSideLengthPower;
//Compute the side length in blocks
m_uSideLengthInBlocks = m_uSideLength / m_uBlockSideLength;
//Compute number of blocks in the volume
m_uNoOfBlocksInVolume = m_uSideLengthInBlocks * m_uSideLengthInBlocks * m_uSideLengthInBlocks;
//Create the blocks
m_pBlocks = new Block<VoxelType>*[m_uNoOfBlocksInVolume];
m_pIsShared = new bool[m_uNoOfBlocksInVolume];
m_pIsPotentiallySharable = new bool[m_uNoOfBlocksInVolume];
m_pHomogenousValue = new VoxelType[m_uNoOfBlocksInVolume];
for(boost::uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
{
m_pBlocks[i] = getHomogenousBlock(0); //new Block<VoxelType>(uBlockSideLengthPower);
m_pIsShared[i] = true;
m_pIsPotentiallySharable[i] = false;
m_pHomogenousValue[i] = 0;
}
}
template <typename VoxelType>
BlockVolume<VoxelType>::BlockVolume(const BlockVolume<VoxelType>& rhs)
{
*this = rhs;
}
template <typename VoxelType>
BlockVolume<VoxelType>::~BlockVolume()
{
for(boost::uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
{
delete m_pBlocks[i];
}
}
#pragma endregion
#pragma region Operators
template <typename VoxelType>
BlockVolume<VoxelType>& BlockVolume<VoxelType>::operator=(const BlockVolume& rhs)
{
if (this == &rhs)
{
return *this;
}
/*for(uint16_t i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
{
//FIXME - Add checking...
m_pBlocks[i] = SharedPtr<Block>(new Block);
}*/
for(uint32_t i = 0; i < m_uNoOfBlocksInVolume; ++i)
{
//I think this is OK... If a block is in the homogeneous array it's ref count will be greater
//than 1 as there will be the pointer in the volume and the pointer in the static homogeneous array.
/*if(rhs.m_pBlocks[i].unique())
{
m_pBlocks[i] = SharedPtr<Block>(new Block(*(rhs.m_pBlocks[i])));
}
else
{*/
//we have a block in the homogeneous array - just copy the pointer.
m_pBlocks[i] = rhs.m_pBlocks[i];
//}
}
return *this;
}
#pragma endregion
#pragma region Getters
template <typename VoxelType>
Region BlockVolume<VoxelType>::getEnclosingRegion(void) const
{
return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uSideLength-1,m_uSideLength-1,m_uSideLength-1));
}
template <typename VoxelType>
boost::uint16_t BlockVolume<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType BlockVolume<VoxelType>::getVoxelAt(boost::uint16_t uXPos, boost::uint16_t uYPos, boost::uint16_t uZPos) const
{
assert(uXPos < getSideLength());
assert(uYPos < getSideLength());
assert(uZPos < getSideLength());
const uint16_t blockX = uXPos >> m_uBlockSideLengthPower;
const uint16_t blockY = uYPos >> m_uBlockSideLengthPower;
const uint16_t blockZ = uZPos >> m_uBlockSideLengthPower;
const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
const uint16_t zOffset = uZPos - (blockZ << m_uBlockSideLengthPower);
const Block<VoxelType>* block = m_pBlocks
[
blockX +
blockY * m_uSideLengthInBlocks +
blockZ * m_uSideLengthInBlocks * m_uSideLengthInBlocks
];
return block->getVoxelAt(xOffset,yOffset,zOffset);
}
template <typename VoxelType>
VoxelType BlockVolume<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
{
assert(v3dPos.getX() < m_uSideLength);
assert(v3dPos.getY() < m_uSideLength);
assert(v3dPos.getZ() < m_uSideLength);
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
#pragma endregion
#pragma region Other
template <typename VoxelType>
bool BlockVolume<VoxelType>::containsPoint(const Vector3DFloat& pos, float boundary) const
{
return (pos.getX() <= m_uSideLength - 1 - boundary)
&& (pos.getY() <= m_uSideLength - 1 - boundary)
&& (pos.getZ() <= m_uSideLength - 1 - boundary)
&& (pos.getX() >= boundary)
&& (pos.getY() >= boundary)
&& (pos.getZ() >= boundary);
}
template <typename VoxelType>
bool BlockVolume<VoxelType>::containsPoint(const Vector3DInt32& pos, boost::uint16_t boundary) const
{
return (pos.getX() <= m_uSideLength - 1 - boundary)
&& (pos.getY() <= m_uSideLength - 1 - boundary)
&& (pos.getZ() <= m_uSideLength - 1 - boundary)
&& (pos.getX() >= boundary)
&& (pos.getY() >= boundary)
&& (pos.getZ() >= boundary);
}
template <typename VoxelType>
BlockVolumeIterator<VoxelType> BlockVolume<VoxelType>::firstVoxel(void)
{
BlockVolumeIterator<VoxelType> iter(*this);
iter.setPosition(0,0,0);
return iter;
}
template <typename VoxelType>
void BlockVolume<VoxelType>::idle(boost::uint32_t uAmount)
{
}
template <typename VoxelType>
BlockVolumeIterator<VoxelType> BlockVolume<VoxelType>::lastVoxel(void)
{
BlockVolumeIterator<VoxelType> iter(*this);
iter.setPosition(m_uSideLength-1,m_uSideLength-1,m_uSideLength-1);
return iter;
}
#pragma endregion
#pragma region Private Implementation
template <typename VoxelType>
Block<VoxelType>* BlockVolume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue) const
{
typename std::map<VoxelType, Block<VoxelType>*>::iterator iterResult = m_pHomogenousBlocks.find(tHomogenousValue);
if(iterResult == m_pHomogenousBlocks.end())
{
Block<VoxelType>* pBlock = new Block<VoxelType>(m_uBlockSideLengthPower);
pBlock->fill(tHomogenousValue);
m_pHomogenousBlocks.insert(std::make_pair(tHomogenousValue, pBlock));
return pBlock;
}
return iterResult->second;
}
#pragma endregion
}

View File

@ -1,137 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __VolumeIterator_H__
#define __VolumeIterator_H__
#pragma region Headers
#include "PolyVoxForwardDeclarations.h"
#include "boost/cstdint.hpp"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class BlockVolumeIterator
{
public:
BlockVolumeIterator(BlockVolume<VoxelType>& volume);
~BlockVolumeIterator();
bool operator==(const BlockVolumeIterator& rhs);
bool operator<(const BlockVolumeIterator& rhs);
bool operator>(const BlockVolumeIterator& rhs);
bool operator<=(const BlockVolumeIterator& rhs);
bool operator>=(const BlockVolumeIterator& rhs);
float getAveragedVoxel(boost::uint16_t size) const;
boost::uint16_t getPosX(void) const;
boost::uint16_t getPosY(void) const;
boost::uint16_t getPosZ(void) const;
VoxelType getVoxel(void) const;
void setPosition(const Vector3DInt16& v3dNewPos);
void setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos);
void setValidRegion(const Region& region);
void setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast);
void setVoxel(VoxelType tValue);
bool isValidForRegion(void) const;
void moveForwardInRegionFast(void);
bool moveForwardInRegionXYZ(void);
VoxelType peekVoxel1nx1ny1nz(void) const;
VoxelType peekVoxel1nx1ny0pz(void) const;
VoxelType peekVoxel1nx1ny1pz(void) const;
VoxelType peekVoxel1nx0py1nz(void) const;
VoxelType peekVoxel1nx0py0pz(void) const;
VoxelType peekVoxel1nx0py1pz(void) const;
VoxelType peekVoxel1nx1py1nz(void) const;
VoxelType peekVoxel1nx1py0pz(void) const;
VoxelType peekVoxel1nx1py1pz(void) const;
VoxelType peekVoxel0px1ny1nz(void) const;
VoxelType peekVoxel0px1ny0pz(void) const;
VoxelType peekVoxel0px1ny1pz(void) const;
VoxelType peekVoxel0px0py1nz(void) const;
VoxelType peekVoxel0px0py0pz(void) const;
VoxelType peekVoxel0px0py1pz(void) const;
VoxelType peekVoxel0px1py1nz(void) const;
VoxelType peekVoxel0px1py0pz(void) const;
VoxelType peekVoxel0px1py1pz(void) const;
VoxelType peekVoxel1px1ny1nz(void) const;
VoxelType peekVoxel1px1ny0pz(void) const;
VoxelType peekVoxel1px1ny1pz(void) const;
VoxelType peekVoxel1px0py1nz(void) const;
VoxelType peekVoxel1px0py0pz(void) const;
VoxelType peekVoxel1px0py1pz(void) const;
VoxelType peekVoxel1px1py1nz(void) const;
VoxelType peekVoxel1px1py0pz(void) const;
VoxelType peekVoxel1px1py1pz(void) const;
private:
//The current volume
BlockVolume<VoxelType>& mVolume;
//The current position in the volume
boost::uint16_t mXPosInVolume;
boost::uint16_t mYPosInVolume;
boost::uint16_t mZPosInVolume;
//The position of the current block
boost::uint16_t mXBlock;
boost::uint16_t mYBlock;
boost::uint16_t mZBlock;
//The offset into the current block
boost::uint16_t mXPosInBlock;
boost::uint16_t mYPosInBlock;
boost::uint16_t mZPosInBlock;
//Other current position information
VoxelType* mCurrentVoxel;
boost::uint32_t mBlockIndexInVolume;
boost::uint32_t mVoxelIndexInBlock;
boost::uint16_t mXRegionFirst;
boost::uint16_t mYRegionFirst;
boost::uint16_t mZRegionFirst;
boost::uint16_t mXRegionLast;
boost::uint16_t mYRegionLast;
boost::uint16_t mZRegionLast;
boost::uint16_t mXRegionFirstBlock;
boost::uint16_t mYRegionFirstBlock;
boost::uint16_t mZRegionFirstBlock;
boost::uint16_t mXRegionLastBlock;
boost::uint16_t mYRegionLastBlock;
boost::uint16_t mZRegionLastBlock;
bool mIsValidForRegion;
};
}
#include "BlockVolumeIterator.inl"
#endif

View File

@ -1,672 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#pragma region Headers
#include "Block.h"
#include "BlockVolume.h"
#include "Vector.h"
#pragma endregion
namespace PolyVox
{
#pragma region Constructors/Destructors
template <typename VoxelType>
BlockVolumeIterator<VoxelType>::BlockVolumeIterator(BlockVolume<VoxelType>& volume)
:mVolume(volume)
{
}
template <typename VoxelType>
BlockVolumeIterator<VoxelType>::~BlockVolumeIterator()
{
}
#pragma endregion
#pragma region Operators
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::operator==(const BlockVolumeIterator<VoxelType>& rhs)
{
//We could just check whether the two mCurrentVoxel pointers are equal, but this may not
//be safe in the future if we decide to allow blocks to be shared between volumes
//So we really check whether the positions are the same.
//NOTE: With all iterator comparisons it is the users job to ensure they at least point
//to the same volume. Otherwise they are not comparible.
assert(&mVolume == &rhs.mVolume);
return
(
(mXPosInVolume == rhs.mXPosInVolume) &&
(mYPosInVolume == rhs.mYPosInVolume) &&
(mZPosInVolume == rhs.mZPosInVolume)
);
}
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::operator<(const BlockVolumeIterator<VoxelType>& rhs)
{
assert(&mVolume == &rhs.mVolume);
if(mZPosInVolume < rhs.mZPosInVolume)
return true;
if(mZPosInVolume > rhs.mZPosInVolume)
return false;
if(mYPosInVolume < rhs.mYPosInVolume)
return true;
if(mYPosInVolume > rhs.mYPosInVolume)
return false;
if(mXPosInVolume < rhs.mXPosInVolume)
return true;
if(mXPosInVolume > rhs.mXPosInVolume)
return false;
return false;
}
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::operator>(const BlockVolumeIterator<VoxelType>& rhs)
{
assert(&mVolume == &rhs.mVolume);
return (rhs < *this);
}
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::operator<=(const BlockVolumeIterator<VoxelType>& rhs)
{
assert(&mVolume == &rhs.mVolume);
return (rhs > *this);
}
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::operator>=(const BlockVolumeIterator<VoxelType>& rhs)
{
assert(&mVolume == &rhs.mVolume);
return (rhs < *this);
}
#pragma endregion
#pragma region Getters
template <typename VoxelType>
float BlockVolumeIterator<VoxelType>::getAveragedVoxel(boost::uint16_t size) const
{
assert(mXPosInVolume >= size);
assert(mYPosInVolume >= size);
assert(mZPosInVolume >= size);
assert(mXPosInVolume < mVolume.getSideLength() - (size + 1));
assert(mYPosInVolume < mVolume.getSideLength() - (size + 1));
assert(mZPosInVolume < mVolume.getSideLength() - (size + 1));
float sum = 0.0;
for(uint16_t z = mZPosInVolume-size; z <= mZPosInVolume+size; ++z)
{
for(uint16_t y = mYPosInVolume-size; y <= mYPosInVolume+size; ++y)
{
for(uint16_t x = mXPosInVolume-size; x <= mXPosInVolume+size; ++x)
{
if(mVolume.getVoxelAt(x,y,z) != 0)
{
sum += 1.0;
}
}
}
}
uint16_t kernelSideLength = size * 2 + 1;
uint16_t kernelVolume = kernelSideLength * kernelSideLength * kernelSideLength;
sum /= static_cast<float>(kernelVolume);
return sum;
}
template <typename VoxelType>
boost::uint16_t BlockVolumeIterator<VoxelType>::getPosX(void) const
{
return mXPosInVolume;
}
template <typename VoxelType>
boost::uint16_t BlockVolumeIterator<VoxelType>::getPosY(void) const
{
return mYPosInVolume;
}
template <typename VoxelType>
boost::uint16_t BlockVolumeIterator<VoxelType>::getPosZ(void) const
{
return mZPosInVolume;
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::getVoxel(void) const
{
return *mCurrentVoxel;
}
#pragma endregion
#pragma region Setters
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setPosition(const Vector3DInt16& v3dNewPos)
{
setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ());
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos)
{
mXPosInVolume = xPos;
mYPosInVolume = yPos;
mZPosInVolume = zPos;
mXBlock = mXPosInVolume >> mVolume.m_uBlockSideLengthPower;
mYBlock = mYPosInVolume >> mVolume.m_uBlockSideLengthPower;
mZBlock = mZPosInVolume >> mVolume.m_uBlockSideLengthPower;
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
mZPosInBlock = mZPosInVolume - (mZBlock << mVolume.m_uBlockSideLengthPower);
mBlockIndexInVolume = mXBlock +
mYBlock * mVolume.m_uSideLengthInBlocks +
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setValidRegion(const Region& region)
{
setValidRegion(region.getLowerCorner().getX(),region.getLowerCorner().getY(),region.getLowerCorner().getZ(),region.getUpperCorner().getX(),region.getUpperCorner().getY(),region.getUpperCorner().getZ());
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast)
{
mXRegionFirst = xFirst;
mYRegionFirst = yFirst;
mZRegionFirst = zFirst;
mXRegionLast = xLast;
mYRegionLast = yLast;
mZRegionLast = zLast;
mXRegionFirstBlock = mXRegionFirst >> mVolume.m_uBlockSideLengthPower;
mYRegionFirstBlock = mYRegionFirst >> mVolume.m_uBlockSideLengthPower;
mZRegionFirstBlock = mZRegionFirst >> mVolume.m_uBlockSideLengthPower;
mXRegionLastBlock = mXRegionLast >> mVolume.m_uBlockSideLengthPower;
mYRegionLastBlock = mYRegionLast >> mVolume.m_uBlockSideLengthPower;
mZRegionLastBlock = mZRegionLast >> mVolume.m_uBlockSideLengthPower;
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::setVoxel(VoxelType tValue)
{
const boost::uint32_t uBlockIndex =
mXBlock +
mYBlock * mVolume.m_uSideLengthInBlocks +
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
const bool bIsShared = mVolume.m_pIsShared[uBlockIndex];
const VoxelType tHomogenousValue = mVolume.m_pHomogenousValue[uBlockIndex];
if(bIsShared)
{
if(tHomogenousValue != tValue)
{
mVolume.m_pBlocks[uBlockIndex] = new Block<VoxelType>(mVolume.m_uBlockSideLengthPower);
mVolume.m_pIsShared[uBlockIndex] = false;
mVolume.m_pBlocks[uBlockIndex]->fill(tHomogenousValue);
mCurrentVoxel = mVolume.m_pBlocks[uBlockIndex]->m_tData + mVoxelIndexInBlock;
*mCurrentVoxel = tValue;
}
}
else
{
//There is a chance that setting this voxel makes the block homogenous and therefore shareable.
mVolume.m_pIsPotentiallySharable[uBlockIndex] = true;
*mCurrentVoxel = tValue;
}
}
#pragma endregion
#pragma region Other
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::isValidForRegion(void) const
{
return mIsValidForRegion;
}
template <typename VoxelType>
void BlockVolumeIterator<VoxelType>::moveForwardInRegionFast(void)
{
mXPosInBlock++;
mCurrentVoxel++;
mXPosInVolume++;
if((mXPosInBlock == mVolume.m_uBlockSideLength) || (mXPosInVolume > mXRegionLast))
{
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
mYPosInBlock++;
mYPosInVolume++;
mCurrentVoxel += mVolume.m_uBlockSideLength;
if((mYPosInBlock == mVolume.m_uBlockSideLength) || (mYPosInVolume > mYRegionLast))
{
mYPosInVolume = (std::max)(mYRegionFirst,uint16_t(mYBlock * mVolume.m_uBlockSideLength));
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
mZPosInBlock++;
mZPosInVolume++;
mCurrentVoxel += mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
if((mZPosInBlock == mVolume.m_uBlockSideLength) || (mZPosInVolume > mZRegionLast))
{
//At this point we've left the current block. Find a new one...
++mXBlock;
++mBlockIndexInVolume;
if(mXBlock > mXRegionLastBlock)
{
mXBlock = mXRegionFirstBlock;
mBlockIndexInVolume = mXBlock +
mYBlock * mVolume.m_uSideLengthInBlocks +
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
++mYBlock;
mBlockIndexInVolume += mVolume.m_uSideLengthInBlocks;
if(mYBlock > mYRegionLastBlock)
{
mYBlock = mYRegionFirstBlock;
mBlockIndexInVolume = mXBlock +
mYBlock * mVolume.m_uSideLengthInBlocks +
mZBlock * mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
++mZBlock;
mBlockIndexInVolume += mVolume.m_uSideLengthInBlocks * mVolume.m_uSideLengthInBlocks;
if(mZBlock > mZRegionLastBlock)
{
mIsValidForRegion = false;
return;
}
}
}
Block<VoxelType>* currentBlock = mVolume.m_pBlocks[mBlockIndexInVolume];
//mCurrentBlock = mVolume->m_pBlocks[mBlockIndexInVolume];
mXPosInVolume = (std::max)(mXRegionFirst,uint16_t(mXBlock * mVolume.m_uBlockSideLength));
mYPosInVolume = (std::max)(mYRegionFirst,uint16_t(mYBlock * mVolume.m_uBlockSideLength));
mZPosInVolume = (std::max)(mZRegionFirst,uint16_t(mZBlock * mVolume.m_uBlockSideLength));
mXPosInBlock = mXPosInVolume - (mXBlock << mVolume.m_uBlockSideLengthPower);
mYPosInBlock = mYPosInVolume - (mYBlock << mVolume.m_uBlockSideLengthPower);
mZPosInBlock = mZPosInVolume - (mZBlock << mVolume.m_uBlockSideLengthPower);
mVoxelIndexInBlock = mXPosInBlock +
mYPosInBlock * mVolume.m_uBlockSideLength +
mZPosInBlock * mVolume.m_uBlockSideLength * mVolume.m_uBlockSideLength;
mCurrentVoxel = currentBlock->m_tData + mVoxelIndexInBlock;
}
}
}
}
template <typename VoxelType>
bool BlockVolumeIterator<VoxelType>::moveForwardInRegionXYZ(void)
{
if(mXPosInVolume < mXRegionLast)
{
++mXPosInVolume;
if(mXPosInVolume % mVolume.m_uBlockSideLength != 0)
{
//No need to compute new block.
++mVoxelIndexInBlock;
++mCurrentVoxel;
}
else
{
//A more complex situation. Just call setPosition().
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
}
else
{
mXPosInVolume = mXRegionFirst;
if(mYPosInVolume < mYRegionLast)
{
++mYPosInVolume;
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
//trick here because the x position has been reset and so is likely to be in a different block.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
mYPosInVolume = mYRegionFirst;
if(mZPosInVolume < mZRegionLast)
{
++mZPosInVolume;
//In the case of 'X' we used a trick to avoid calling this evey time. It's hard to use the same
//trick here because the x position has been reset and so is likely to be in a different block.
setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume);
}
else
{
//We've hit the end of the region. Reset x and y positions to where they were.
mXPosInVolume = mXRegionLast;
mYPosInVolume = mYRegionLast;
//Return false to indicate we failed to move forward.
return false;
}
}
}
return true;
}
#pragma endregion
#pragma region Peekers
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1ny1nz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1ny0pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1ny1pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx0py1nz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - 1 - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx0py0pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - 1);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx0py1pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1py1nz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1py0pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1nx1py1pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != 0) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel - 1 + mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1ny1nz(void) const
{
if((mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1ny0pz(void) const
{
if((mYPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1ny1pz(void) const
{
if((mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel - mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px0py1nz(void) const
{
if((mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px0py0pz(void) const
{
return *mCurrentVoxel;
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px0py1pz(void) const
{
if((mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1py1nz(void) const
{
if((mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel + mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1py0pz(void) const
{
if((mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel0px1py1pz(void) const
{
if((mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1);
}
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1ny1nz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1ny0pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1ny1pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != 0) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px0py1nz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel + 1 - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px0py0pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + 1);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px0py1pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1py1nz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != 0))
{
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength - mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1py0pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume);
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::peekVoxel1px1py1pz(void) const
{
if((mXPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mYPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1) && (mZPosInVolume%mVolume.m_uBlockSideLength != mVolume.m_uBlockSideLength-1))
{
return *(mCurrentVoxel + 1 + mVolume.m_uBlockSideLength + mVolume.m_uBlockSideLength*mVolume.m_uBlockSideLength);
}
return mVolume.getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1);
}
#pragma endregion
}

View File

@ -1,45 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_Constants_H__
#define __PolyVox_Constants_H__
#include "boost/cstdint.hpp"
namespace PolyVox
{
//FIXME - i think we can define mod using a bitmask which flattens the upper bits. Should define that here.
//const boost::uint32_t POLYVOX_BLOCK_SIDE_LENGTH_POWER = 5;
//const boost::uint32_t POLYVOX_BLOCK_SIDE_LENGTH = (0x0001 << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
//const boost::uint32_t POLYVOX_NO_OF_VOXELS_IN_BLOCK = (POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH);
const boost::uint16_t POLYVOX_VOLUME_SIDE_LENGTH_POWER = 8;
const boost::uint16_t POLYVOX_VOLUME_SIDE_LENGTH = (0x0001 << POLYVOX_VOLUME_SIDE_LENGTH_POWER);
//const boost::uint32_t POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_BLOCK_SIDE_LENGTH_POWER);
//const boost::uint32_t POLYVOX_NO_OF_BLOCKS_IN_VOLUME = (POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS * POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS);
//const boost::uint32_t POLYVOX_NO_OF_VOXELS_IN_VOLUME = (POLYVOX_VOLUME_SIDE_LENGTH * POLYVOX_VOLUME_SIDE_LENGTH * POLYVOX_VOLUME_SIDE_LENGTH);
const boost::uint16_t POLYVOX_REGION_SIDE_LENGTH_POWER = 4;
const boost::uint16_t POLYVOX_REGION_SIDE_LENGTH = (0x0001 << POLYVOX_REGION_SIDE_LENGTH_POWER);
const boost::uint16_t POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_REGION_SIDE_LENGTH_POWER);
}
#endif

View File

@ -1,35 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_Enums_H__
#define __PolyVox_Enums_H__
namespace PolyVox
{
enum NormalGenerationMethod
{
SIMPLE,
CENTRAL_DIFFERENCE,
SOBEL
};
}
#endif

View File

@ -1,41 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_GradientEstimators_H__
#define __PolyVox_GradientEstimators_H__
#include "BlockVolumeIterator.h"
namespace PolyVox
{
template <typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const BlockVolumeIterator<VoxelType>& volIter);
template <typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter);
template <typename VoxelType>
Vector3DFloat computeSobelGradient(const BlockVolumeIterator<VoxelType>& volIter);
}
#include "GradientEstimators.inl"
#endif //__PolyVox_GradientEstimators_H__

View File

@ -1,158 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const BlockVolumeIterator<VoxelType>& volIter)
{
//FIXME - bitwise way of doing this?
VoxelType voxel1nx = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
VoxelType voxel1px = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
VoxelType voxel1ny = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
VoxelType voxel1py = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
VoxelType voxel1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
VoxelType voxel1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
return Vector3DFloat
(
static_cast<float>(voxel1px) - static_cast<float>(voxel1nx),
static_cast<float>(voxel1py) - static_cast<float>(voxel1ny),
static_cast<float>(voxel1pz) - static_cast<float>(voxel1nz)
);
}
template <typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter)
{
boost::uint16_t initialX = volIter.getPosX();
boost::uint16_t initialY = volIter.getPosY();
boost::uint16_t initialZ = volIter.getPosZ();
//FIXME - bitwise way of doing this?
volIter.setPosition(initialX-1, initialY, initialZ);
float voxel1nx = volIter.getAveragedVoxel(1);
volIter.setPosition(initialX+1, initialY, initialZ);
float voxel1px = volIter.getAveragedVoxel(1);
volIter.setPosition(initialX, initialY-1, initialZ);
float voxel1ny = volIter.getAveragedVoxel(1);
volIter.setPosition(initialX, initialY+1, initialZ);
float voxel1py = volIter.getAveragedVoxel(1);
volIter.setPosition(initialX, initialY, initialZ-1);
float voxel1nz = volIter.getAveragedVoxel(1);
volIter.setPosition(initialX, initialY, initialZ+1);
float voxel1pz = volIter.getAveragedVoxel(1);
return Vector3DFloat
(
voxel1px - voxel1nx,
voxel1py - voxel1ny,
voxel1pz - voxel1nz
);
}
template <typename VoxelType>
Vector3DFloat computeSobelGradient(const BlockVolumeIterator<VoxelType>& volIter)
{
static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, {
{3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } };
const VoxelType pVoxel1nx1ny1nz = volIter.peekVoxel1nx1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny0pz = volIter.peekVoxel1nx1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1ny1pz = volIter.peekVoxel1nx1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1nz = volIter.peekVoxel1nx0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py0pz = volIter.peekVoxel1nx0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx0py1pz = volIter.peekVoxel1nx0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1nz = volIter.peekVoxel1nx1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py0pz = volIter.peekVoxel1nx1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1nx1py1pz = volIter.peekVoxel1nx1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1nz = volIter.peekVoxel0px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny0pz = volIter.peekVoxel0px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1ny1pz = volIter.peekVoxel0px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1nz = volIter.peekVoxel0px0py1nz() > 0 ? 1: 0;
//const VoxelType pVoxel0px0py0pz = volIter.peekVoxel0px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px0py1pz = volIter.peekVoxel0px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1nz = volIter.peekVoxel0px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py0pz = volIter.peekVoxel0px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel0px1py1pz = volIter.peekVoxel0px1py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1nz = volIter.peekVoxel1px1ny1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny0pz = volIter.peekVoxel1px1ny0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1ny1pz = volIter.peekVoxel1px1ny1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1nz = volIter.peekVoxel1px0py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py0pz = volIter.peekVoxel1px0py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px0py1pz = volIter.peekVoxel1px0py1pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1nz = volIter.peekVoxel1px1py1nz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
const VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;
const int xGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
( pVoxel1nx1ny1pz) - weights[0][1][0] * ( pVoxel1nx0py1nz) -
weights[1][1][0] * ( pVoxel1nx0py0pz) - weights[2][1][0] *
( pVoxel1nx0py1pz) - weights[0][2][0] * ( pVoxel1nx1py1nz) -
weights[1][2][0] * ( pVoxel1nx1py0pz) - weights[2][2][0] *
( pVoxel1nx1py1pz) + weights[0][0][2] * ( pVoxel1px1ny1nz) +
weights[1][0][2] * ( pVoxel1px1ny0pz) + weights[2][0][2] *
( pVoxel1px1ny1pz) + weights[0][1][2] * ( pVoxel1px0py1nz) +
weights[1][1][2] * ( pVoxel1px0py0pz) + weights[2][1][2] *
( pVoxel1px0py1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
( pVoxel1px1py1pz));
const int yGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
( pVoxel1nx1ny1pz) + weights[0][2][0] * ( pVoxel1nx1py1nz) +
weights[1][2][0] * ( pVoxel1nx1py0pz) + weights[2][2][0] *
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) -
weights[1][0][1] * ( pVoxel0px1ny0pz) - weights[2][0][1] *
( pVoxel0px1ny1pz) + weights[0][2][1] * ( pVoxel0px1py1nz) +
weights[1][2][1] * ( pVoxel0px1py0pz) + weights[2][2][1] *
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) -
weights[1][0][2] * ( pVoxel1px1ny0pz) - weights[2][0][2] *
( pVoxel1px1ny1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
( pVoxel1px1py1pz));
const int zGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) +
weights[2][0][0] * ( pVoxel1nx1ny1pz) - weights[0][1][0] *
( pVoxel1nx0py1nz) + weights[2][1][0] * ( pVoxel1nx0py1pz) -
weights[0][2][0] * ( pVoxel1nx1py1nz) + weights[2][2][0] *
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) +
weights[2][0][1] * ( pVoxel0px1ny1pz) - weights[0][1][1] *
( pVoxel0px0py1nz) + weights[2][1][1] * ( pVoxel0px0py1pz) -
weights[0][2][1] * ( pVoxel0px1py1nz) + weights[2][2][1] *
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) +
weights[2][0][2] * ( pVoxel1px1ny1pz) - weights[0][1][2] *
( pVoxel1px0py1nz) + weights[2][1][2] * ( pVoxel1px0py1pz) -
weights[0][2][2] * ( pVoxel1px1py1nz) + weights[2][2][2] *
( pVoxel1px1py1pz));
return Vector3DFloat(static_cast<float>(xGrad),static_cast<float>(yGrad),static_cast<float>(zGrad));
}
}

View File

@ -1,73 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_IndexedSurfacePatch_H__
#define __PolyVox_IndexedSurfacePatch_H__
#include <vector>
#include "boost/cstdint.hpp"
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "SurfaceVertex.h"
#include "TypeDef.h"
namespace PolyVox
{
class POLYVOX_API IndexedSurfacePatch
{
public:
IndexedSurfacePatch(bool allowDuplicateVertices);
~IndexedSurfacePatch();
void addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2);
void fillVertexAndIndexData(std::vector<SurfaceVertex>& vecVertices, std::vector<boost::uint32_t>& vecIndices);
const std::vector<SurfaceVertex>& getVertices(void) const;
std::vector<SurfaceVertex>& getVertices(void); //FIXME - non const version should be removed.
const std::vector<boost::uint32_t>& getIndices(void) const;
unsigned short getNoNonUniformTrianges(void);
unsigned short getNoUniformTrianges(void);
public:
std::vector<boost::uint32_t> m_vecTriangleIndices;
std::vector<SurfaceVertex> m_vecVertices;
static boost::int32_t vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static boost::int32_t vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static boost::int32_t vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1];
static boost::int32_t noOfVerticesSubmitted;
static boost::int32_t noOfVerticesAccepted;
static boost::int32_t noOfTrianglesSubmitted;
boost::int32_t getIndexFor(const Vector3DFloat& pos);
void setIndexFor(const Vector3DFloat& pos, boost::int32_t newIndex);
public:
bool m_AllowDuplicateVertices;
};
}
#endif /* __IndexedSurfacePatch_H__ */

View File

@ -1,64 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_LinearVolume_H__
#define __PolyVox_LinearVolume_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "boost/cstdint.hpp"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class LinearVolume
{
public:
LinearVolume(boost::uint8_t uSideLengthPower);
LinearVolume(const LinearVolume& rhs);
~LinearVolume();
LinearVolume& operator=(const LinearVolume& rhs);
//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;
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);
private:
boost::uint32_t getNoOfVoxels(void);
boost::uint8_t m_uSideLengthPower;
boost::uint16_t m_uSideLength;
VoxelType* m_tData;
};
}
#include "LinearVolume.inl"
#endif

View File

@ -1,102 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#include <cstring>
namespace PolyVox
{
template <typename VoxelType>
LinearVolume<VoxelType>::LinearVolume(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>
LinearVolume<VoxelType>::LinearVolume(const LinearVolume<VoxelType>& rhs)
{
*this = rhs;
}
template <typename VoxelType>
LinearVolume<VoxelType>::~LinearVolume()
{
delete[] m_tData;
m_tData = 0;
}
template <typename VoxelType>
LinearVolume<VoxelType>& LinearVolume<VoxelType>::operator=(const LinearVolume<VoxelType>& rhs)
{
if (this == &rhs)
{
return *this;
}
memcpy(m_tData,rhs.m_tData,getNoOfVoxels());
return *this;
}
template <typename VoxelType>
VoxelType LinearVolume<VoxelType>::getVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition) const
{
return m_tData
[
xPosition +
yPosition * m_uSideLength +
zPosition * m_uSideLength * m_uSideLength
];
}
template <typename VoxelType>
void LinearVolume<VoxelType>::setVoxelAt(const boost::uint16_t xPosition, const boost::uint16_t yPosition, const boost::uint16_t zPosition, const VoxelType value)
{
m_tData
[
xPosition +
yPosition * m_uSideLength +
zPosition * m_uSideLength * m_uSideLength
] = value;
}
template <typename VoxelType>
boost::uint16_t LinearVolume<VoxelType>::getSideLength(void)
{
return m_uSideLength;
}
template <typename VoxelType>
boost::uint32_t LinearVolume<VoxelType>::getNoOfVoxels(void)
{
return m_uSideLength * m_uSideLength * m_uSideLength;
}
}

View File

@ -1,31 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_MarchingCubeTables_H__
#define __PolyVox_MarchingCubeTables_H__
namespace PolyVox
{
extern int edgeTable[256];
extern int triTable[256][16];
}
#endif

View File

@ -1,63 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_ForwardDeclarations_H__
#define __PolyVox_ForwardDeclarations_H__
#include "Enums.h"
#include "boost/cstdint.hpp"
namespace PolyVox
{
template <typename VoxelType> class Block;
//---------- BlockVolume ----------
template <typename VoxelType> class BlockVolume;
typedef BlockVolume<float> FloatBlockVolume;
typedef BlockVolume<boost::uint8_t> UInt8BlockVolume;
typedef BlockVolume<boost::uint16_t> UInt16BlockVolume;
//---------------------------------
class IndexedSurfacePatch;
class IntegrealVector3;
template <typename VoxelType> class LinearVolume;
class Region;
class RegionGeometry;
class SurfaceVertex;
//---------- Vector ----------
template <boost::uint32_t Size, typename Type> class Vector;
typedef Vector<3,float> Vector3DFloat;
typedef Vector<3,double> Vector3DDouble;
typedef Vector<3,boost::int8_t> Vector3DInt8;
typedef Vector<3,boost::uint8_t> Vector3DUint8;
typedef Vector<3,boost::int16_t> Vector3DInt16;
typedef Vector<3,boost::uint16_t> Vector3DUint16;
typedef Vector<3,boost::int32_t> Vector3DInt32;
typedef Vector<3,boost::uint32_t> Vector3DUint32;
//----------------------------
class VolumeChangeTracker;
template <typename VoxelType> class BlockVolumeIterator;
}
#endif

View File

@ -1,55 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_Region_H__
#define __PolyVox_Region_H__
#pragma region Headers
#include "TypeDef.h"
#include "Vector.h"
#pragma endregion
namespace PolyVox
{
class POLYVOX_API Region
{
public:
Region();
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
const Vector3DInt32& getLowerCorner(void) const;
const Vector3DInt32& getUpperCorner(void) const;
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
bool containsPoint(const Vector3DInt32& pos, boost::uint8_t boundary) const;
void cropTo(const Region& other);
void shift(const Vector3DInt32& amount);
private:
Vector3DInt32 m_v3dLowerCorner;
Vector3DInt32 m_v3dUpperCorner;
};
}
#endif

View File

@ -1,44 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_RegionGeometry_H__
#define __PolyVox_RegionGeometry_H__
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "Vector.h"
namespace PolyVox
{
class POLYVOX_API RegionGeometry
{
public:
RegionGeometry();
bool m_bIsEmpty;
bool m_bContainsSingleMaterialPatch;
Vector3DInt32 m_v3dRegionPosition;
IndexedSurfacePatch* m_patchSingleMaterial;
};
}
#endif

View File

@ -1,65 +0,0 @@
/******************************************************************************
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.
******************************************************************************/
#ifndef __PolyVox_SurfaceEdge_H__
#define __PolyVox_SurfaceEdge_H__
#include "SurfaceTypes.h"
namespace PolyVox
{
class SurfaceEdge
{
public:
SurfaceEdge(const SurfaceVertexIterator& targetToSet,const SurfaceVertexIterator& sourceToSet);
friend bool operator == (const SurfaceEdge& lhs, const SurfaceEdge& rhs);
friend bool operator < (const SurfaceEdge& lhs, const SurfaceEdge& rhs);
std::string tostring(void);
bool isDegenerate(void);
const SurfaceVertexIterator& getTarget(void) const;
const SurfaceVertexIterator& getSource(void) const;
const SurfaceEdgeIterator& getOtherHalfEdge(void) const;
const SurfaceEdgeIterator& getPreviousHalfEdge(void) const;
const SurfaceEdgeIterator& getNextHalfEdge(void) const;
const SurfaceTriangleIterator& getTriangle(void) const;
void setPreviousHalfEdge(const SurfaceEdgeIterator& previousHalfEdgeToSet);
void setNextHalfEdge(const SurfaceEdgeIterator& nextHalfEdgeToSet);
void setTriangle(const SurfaceTriangleIterator& triangleToSet);
void pairWithOtherHalfEdge(const SurfaceEdgeIterator& otherHalfEdgeToPair);
private:
SurfaceVertexIterator target;
SurfaceVertexIterator source;
SurfaceEdgeIterator previousHalfEdge;
SurfaceEdgeIterator nextHalfEdge;
SurfaceEdgeIterator otherHalfEdge;
SurfaceTriangleIterator triangle;
};
}
#endif

View File

@ -1,54 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_SurfaceExtractors_H__
#define __PolyVox_SurfaceExtractors_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "boost/cstdint.hpp"
#include <list>
#pragma endregion
namespace PolyVox
{
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
boost::uint32_t getIndex(boost::uint32_t x, boost::uint32_t y);
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API boost::uint32_t computeInitialRoughBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask);
POLYVOX_API boost::uint32_t computeRoughBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask);
POLYVOX_API void generateRoughIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]);
POLYVOX_API void generateRoughVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[], Vector3DFloat vertlist[], boost::uint8_t vertMaterials[]);
POLYVOX_API void generateReferenceMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
}
#endif

View File

@ -1,50 +0,0 @@
/******************************************************************************
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.
******************************************************************************/
#ifndef __PolyVox_SurfaceTriangle_H__
#define __PolyVox_SurfaceTriangle_H__
#include "SurfaceTypes.h"
namespace PolyVox
{
class SurfaceTriangle
{
public:
SurfaceTriangle();
friend bool operator == (const SurfaceTriangle& lhs, const SurfaceTriangle& rhs);
friend bool operator < (const SurfaceTriangle& lhs, const SurfaceTriangle& rhs);
const SurfaceEdgeIterator& getEdge(void) const;
void setEdge(const SurfaceEdgeIterator& edgeToSet);
//std::string tostring(void);
private:
SurfaceEdgeIterator edge;
};
//bool operator < (const SurfaceTriangleIterator& lhs, const SurfaceTriangleIterator& rhs);
}
#endif

View File

@ -1,19 +0,0 @@
#ifndef __PolyVox_SurfaceTypes_H__
#define __PolyVox_SurfaceTypes_H__
#include <set>
namespace PolyVox
{
class SurfaceVertex;
typedef std::set<SurfaceVertex>::iterator SurfaceVertexIterator;
typedef std::set<SurfaceVertex>::const_iterator SurfaceVertexConstIterator;
class SurfaceTriangle;
typedef std::set<SurfaceTriangle>::iterator SurfaceTriangleIterator;
typedef std::set<SurfaceTriangle>::const_iterator SurfaceTriangleConstIterator;
class SurfaceEdge;
typedef std::set<SurfaceEdge>::iterator SurfaceEdgeIterator;
typedef std::set<SurfaceEdge>::const_iterator SurfaceEdgeConstIterator;
}
#endif

View File

@ -1,65 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_SurfaceVertex_H__
#define __PolyVox_SurfaceVertex_H__
#include "TypeDef.h"
#include "Vector.h"
namespace PolyVox
{
class POLYVOX_API SurfaceVertex
{
public:
SurfaceVertex();
SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet);
SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet);
friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs);
friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs);
float getAlpha(void) const;
float getMaterial(void) const;
const Vector3DFloat& getNormal(void) const;
const Vector3DFloat& getPosition(void) const;
void setAlpha(float alphaToSet);
void setMaterial(float materialToSet);
void setNormal(const Vector3DFloat& normalToSet);
std::string tostring(void) const;
private:
Vector3DFloat position;
Vector3DFloat normal;
float material;
float alpha;
};
//bool operator < (const SurfaceVertexIterator& lhs, const SurfaceVertexIterator& rhs);
}
#endif

View File

@ -1,37 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
//Dave, maybe make use of OgrePlatform.h instead?
// I think use _OgreExport instead of POLYVOX_API and define OGRE_NONCLIENT_BUILD instead of POLYVOX_EXPORT?
#ifndef __PolyVox_TypeDef_H__
#define __PolyVox_TypeDef_H__
#ifdef WIN32
#ifdef POLYVOX_EXPORT
#define POLYVOX_API __declspec(dllexport)
#else
#define POLYVOX_API __declspec(dllimport)
#endif
#else
#define POLYVOX_API __attribute__ ((visibility("default")))
#endif
#endif

View File

@ -1,35 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_Utility_H__
#define __PolyVox_Utility_H__
#include "TypeDef.h"
#include "boost/cstdint.hpp"
namespace PolyVox
{
POLYVOX_API boost::uint8_t logBase2(boost::uint32_t uInput);
POLYVOX_API bool isPowerOf2(boost::uint32_t uInput);
}
#endif

View File

@ -1,150 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_Vector_H__
#define __PolyVox_Vector_H__
#pragma region Headers
#include "boost/cstdint.hpp"
#include <iostream>
#pragma endregion
namespace PolyVox
{
///Represents a vector in space.
template <boost::uint32_t Size, typename Type>
class Vector
{
public:
///Constructor.
Vector(Type x, Type y) throw();
///Constructor.
Vector(Type x, Type y, Type z) throw();
///Constructor.
Vector(Type x, Type y, Type z, Type w) throw();
///Constructor
Vector(void) throw();
///Copy Constructor.
Vector(const Vector<Size,Type>& vector) throw();
///Copy Constructor which performs casting.
template <typename CastType> explicit Vector(const Vector<Size,CastType>& vector) throw();
///Destructor.
~Vector(void) throw();
///Assignment Operator.
Vector<Size,Type>& operator=(const Vector<Size,Type>& rhs) throw();
///Equality Operator.
bool operator==(const Vector<Size,Type>& rhs) const throw();
///Comparison Operator.
bool operator<(const Vector<Size,Type>& rhs) const throw();
///Addition and Assignment Operator.
Vector<Size,Type>& operator+=(const Vector<Size,Type> &rhs) throw();
///Subtraction and Assignment Operator.
Vector<Size,Type>& operator-=(const Vector<Size,Type> &rhs) throw();
///Multiplication and Assignment Operator.
Vector<Size,Type>& operator*=(const Type& rhs) throw();
///Division and Assignment Operator.
Vector<Size,Type>& operator/=(const Type& rhs) throw();
///Element Access
Type getElement(boost::uint32_t index) const throw();
///Get the x component of the vector.
Type getX(void) const throw();
///Get the y component of the vector.
Type getY(void) const throw();
///Get the z component of the vector.
Type getZ(void) const throw();
///Get the w component of the vector.
Type getW(void) const throw();
///Element Access
void setElement(boost::uint32_t index, Type tValue) throw();
///Set the x component of the vector.
void setX(Type tX) throw();
///Set the y component of the vector.
void setY(Type tY) throw();
///Set the z component of the vector.
void setZ(Type tZ) throw();
///Set the w component of the vector.
void setW(Type tW) throw();
///Get the length of the vector.
double length(void) const throw();
///Get the squared length of the vector.
double lengthSquared(void) const throw();
///Find the angle between this vector and that which is passed as a parameter.
double angleTo(const Vector<Size,Type>& vector) const throw();
///Find the cross product between this vector and the vector passed as a parameter.
Vector<Size,Type> cross(const Vector<Size,Type>& vector) const throw();
///Find the dot product between this vector and the vector passed as a parameter.
Type dot(const Vector<Size,Type>& rhs) const throw();
///Normalise the vector.
void normalise(void) throw();
private:
//Values for the vector
Type m_tElements[Size];
};
//Non-member overloaded operators.
///Addition operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Subtraction operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Multiplication operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Division operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Stream insertion operator.
template <boost::uint32_t Size, typename Type>
std::ostream& operator<<(std::ostream& os, const Vector<Size,Type>& vector) throw();
//Some handy typedefs
///A 3D Vector of floats.
typedef Vector<3,float> Vector3DFloat;
///A 3D Vector of doubles.
typedef Vector<3,double> Vector3DDouble;
///A 3D Vector of signed 8-bit values.
typedef Vector<3,boost::int8_t> Vector3DInt8;
///A 3D Vector of unsigned 8-bit values.
typedef Vector<3,boost::uint8_t> Vector3DUint8;
///A 3D Vector of signed 16-bit values.
typedef Vector<3,boost::int16_t> Vector3DInt16;
///A 3D Vector of unsigned 16-bit values.
typedef Vector<3,boost::uint16_t> Vector3DUint16;
///A 3D Vector of signed 32-bit values.
typedef Vector<3,boost::int32_t> Vector3DInt32;
///A 3D Vector of unsigned 32-bit values.
typedef Vector<3,boost::uint32_t> Vector3DUint32;
}//namespace Thermite
#include "Vector.inl"
#endif

View File

@ -1,536 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#include <cassert>
#include <cmath>
#include <string>
namespace PolyVox
{
/**
This Vector class is templated on both size and data type. It is designed to be
generic but so far had only been tested with vectors of size 2 and 3. Also note
that some of the operations do not make sense with integer types, for example it
does not make conceptual sense to try and normalise an integer Vector.
The elements of the Vector are accessed via the overloaded () operator which takes
an index indicating the element to fetch. They are set using the set() function which
takes an index indicating the element to set and a new value for that element. For
convienience, the functions getX(), setX(), getY(), setY(), getZ(), setZ, w() and setW()
do the same thing for the first 4 elements of the Vector.
A variety of overloaded operators are also provided for comparison and arithmetic
operations. For most of these arithmetic operators only the unary versions are
documented below - however often binary versions are also generated by boost::operators.
Lastly, note that for convienience a set of typedefs are included for 2 and 3 dimentionsal
vectors with type float, double, boost::int32_t, and boost::uint32_t. They are used as follows:
Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.
*/
#pragma region Constructors/Destructors
//-------------------------- Constructors, etc ---------------------------------
/**
Creates a Vector object and initialises it with given values.
\param x x component to set.
\param y y component to set.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type>::Vector(Type x, Type y) throw()
{
m_tElements[0] = x;
m_tElements[1] = y;
}
/**
Creates a Vector3D object and initialises it with given values.
\param x x component to set.
\param y y component to set.
\param z z component to set.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type>::Vector(Type x, Type y, Type z) throw()
{
m_tElements[0] = x;
m_tElements[1] = y;
m_tElements[2] = z;
}
/**
Creates a Vector3D object and initialises it with given values.
\param x x component to set.
\param y y component to set.
\param z z component to set.
\param w w component to set.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type>::Vector(Type x, Type y, Type z, Type w) throw()
{
m_tElements[0] = x;
m_tElements[1] = y;
m_tElements[2] = z;
m_tElements[3] = w;
}
/**
Creates a Vector object but does not initialise it.
*/
template <boost::uint32_t Size, typename Type>
Vector<Size, Type>::Vector(void) throw()
{
}
/**
Copy constructor builds object based on object passed as parameter.
\param vector A reference to the Vector to be copied.
*/
template <boost::uint32_t Size, typename Type>
Vector<Size, Type>::Vector(const Vector<Size, Type>& vector) throw()
{
std::memcpy(m_tElements, vector.m_tElements, sizeof(Type) * Size);
}
/**
This copy constructor allows casting between vectors with different data types.
It is now possible to use code such as:
Vector3DDouble v3dDouble(1.0,2.0,3.0);
Vector3DFloat v3dFloat = static_cast<Vector3DFloat>(v3dDouble); //Casting
\param vector A reference to the Vector to be copied.
*/
template <boost::uint32_t Size, typename Type>
template <typename CastType>
Vector<Size, Type>::Vector(const Vector<Size, CastType>& vector) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] = static_cast<CastType>(vector.getElement(ct));
}
}
/**
Destroys the Vector.
*/
template <boost::uint32_t Size, typename Type>
Vector<Size, Type>::~Vector(void) throw()
{
}
#pragma endregion
#pragma region Operators
/**
Assignment operator copies each element of first Vector to the second.
\param rhs Vector to assign to.
\return A reference to the result to allow chaining.
*/
template <boost::uint32_t Size, typename Type>
Vector<Size, Type>& Vector<Size, Type>::operator=(const Vector<Size, Type>& rhs) throw()
{
if(this == &rhs)
{
return *this;
}
std::memcpy(m_tElements, rhs.m_tElements, sizeof(Type) * Size);
return *this;
}
/**
Checks whether two Vectors are equal.
\param rhs The Vector to compare to.
\return true if the Vectors match.
\see operator!=
*/
template <boost::uint32_t Size, typename Type>
inline bool Vector<Size, Type>::operator==(const Vector<Size, Type> &rhs) const throw()
{
bool equal = true;
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
if(m_tElements[ct] != rhs(ct))
{
equal = false;
break;
}
}
return equal;
}
/**
Checks whether this vector is less than the parameter. The metric is
meaningless but it allows Vectors to me used as key in sdt::map, etc.
\param rhs The Vector to compare to.
\return true if this is less than the parameter
\see operator!=
*/
template <boost::uint32_t Size, typename Type>
inline bool Vector<Size, Type>::operator<(const Vector<Size, Type> &rhs) const throw()
{
for(int ct = 0; ct < Size; ++ct)
{
if (m_tElements[ct] < rhs.m_tElements[ct])
return true;
if (rhs.m_tElements[ct] < m_tElements[ct])
return false;
}
return false;
}
/**
Addition operator adds corresponding elements of the two Vectors.
\param rhs Vector to add
\return The resulting Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator+=(const Vector<Size, Type>& rhs) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] += rhs.m_tElements[ct];
}
return *this;
}
/**
Addition operator adds corresponding elements of the two Vectors.
\param lhs Vector to add to.
\param rhs Vector to add.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result += rhs;
return result;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param rhs Vector to subtract
\return The resulting Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator-=(const Vector<Size, Type>& rhs) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] -= rhs.m_tElements[ct];
}
return *this;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param lhs Vector to subtract from.
\param rhs Vector to subtract.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result -= rhs;
return result;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
\param rhs the number the Vector is multiplied by.
\return The resulting Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator*=(const Type& rhs) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] *= rhs;
}
return *this;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
\param lhs the Vector to multiply.
\param rhs the number the Vector is multiplied by.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw()
{
Vector<Size,Type> result = lhs;
result *= rhs;
return result;
}
/**
Division operator divides each element of the Vector by a number.
\param rhs the number the Vector is divided by.
\return The resulting Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator/=(const Type& rhs) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] /= rhs;
}
return *this;
}
/**
Division operator divides each element of the Vector by a number.
\param lhs the Vector to divide.
\param rhs the number the Vector is divided by.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw()
{
Vector<Size,Type> result = lhs;
result /= rhs;
return result;
}
/**
Enables the Vector to be used intuitively with output streams such as cout.
\param os The output stream to write to.
\param vector The Vector to write to the stream.
\return A reference to the output stream to allow chaining.
*/
template <boost::uint32_t Size, typename Type>
std::ostream& operator<<(std::ostream& os, const Vector<Size, Type>& vector) throw()
{
os << "(";
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
os << vector.getElement(ct);
if(ct < (Size-1))
{
os << ",";
}
}
os << ")";
return os;
}
#pragma endregion
#pragma region Getters
/**
Returns the element at the given position.
\param index The index of the element to return.
\return The element.
*/
template <boost::uint32_t Size, typename Type>
inline Type Vector<Size, Type>::getElement(boost::uint32_t index) const throw()
{
return m_tElements[index];
}
/**
\return A const reference to the X component of a 1, 2, 3, or 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Type Vector<Size, Type>::getX(void) const throw()
{
return m_tElements[0];
}
/**
\return A const reference to the Y component of a 2, 3, or 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Type Vector<Size, Type>::getY(void) const throw()
{
return m_tElements[1];
}
/**
\return A const reference to the Z component of a 3 or 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Type Vector<Size, Type>::getZ(void) const throw()
{
return m_tElements[2];
}
/**
\return A const reference to the W component of a 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Type Vector<Size, Type>::getW(void) const throw()
{
return m_tElements[3];
}
#pragma endregion
#pragma region Setters
/**
\param index The index of the element to set.
\param tValue The new value for the element.
*/
template <boost::uint32_t Size, typename Type>
inline void Vector<Size, Type>::setElement(boost::uint32_t index, Type tValue) throw()
{
m_tElements[index] = tValue;
}
/**
\param tX The new value for the X component of a 1, 2, 3, or 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline void Vector<Size, Type>::setX(Type tX) throw()
{
m_tElements[0] = tX;
}
/**
\param tX The new value for the Y component of a 2, 3, or 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline void Vector<Size, Type>::setY(Type tY) throw()
{
m_tElements[1] = tY;
}
/**
\param tX The new value for the Z component of a 3 or 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline void Vector<Size, Type>::setZ(Type tZ) throw()
{
m_tElements[2] = tZ;
}
/**
\param tX The new value for the W component of a 4 dimensional Vector.
*/
template <boost::uint32_t Size, typename Type>
inline void Vector<Size, Type>::setW(Type tW) throw()
{
m_tElements[3] = tW;
}
#pragma endregion
#pragma region Others
/**
NOTE: This function does not make much sense on integer Vectors.
\return Length of the Vector.
*/
template <boost::uint32_t Size, typename Type>
inline double Vector<Size, Type>::length(void) const throw()
{
return sqrt(lengthSquared());
}
/**
\return Squared length of the Vector.
*/
template <boost::uint32_t Size, typename Type>
inline double Vector<Size, Type>::lengthSquared(void) const throw()
{
double result = 0.0f;
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
result += m_tElements[ct] * m_tElements[ct];
}
return result;
}
/**
This function is commutative, such that a.angleTo(b) == b.angleTo(a). The angle
returned is in radians and varies between 0 and 3.14(pi). It is always positive.
NOTE: This function does not make much sense on integer Vectors.
\param Vector3D The Vector to find the angle to.
\return The angle between them in radians.
*/
template <boost::uint32_t Size, typename Type>
inline double Vector<Size, Type>::angleTo(const Vector<Size, Type>& vector) const throw()
{
return acos(dot(vector) / (vector.length() * this->length()));
}
/**
This function is used to calculate the cross product of two Vectors.
The cross product is the Vector which is perpendicular to the two
given Vectors. It is worth remembering that, unlike the dot product,
it is not commutative. E.g a.b != b.a. The cross product obeys the
right-hand rule such that if the two vectors are given by the index
finger and middle finger respectively then the cross product is given
by the thumb.
\param a first Vector.
\param b Second Vector.
\return The value of the cross product.
\see dot()
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type> Vector<Size, Type>::cross(const Vector<Size, Type>& vector) const throw()
{
Type i = vector.getZ() * this->getY() - vector.getY() * this->getZ();
Type j = vector.getX() * this->getZ() - vector.getZ() * this->getX();
Type k = vector.getY() * this->getX() - vector.getX() * this->getY();
return Vector<Size, Type>(i,j,k);
}
/**
Calculates the dot product of the Vector and the parameter.
This function is commutative, such that a.dot(b) == b.dot(a).
\param rhs The Vector to find the dot product with.
\return The value of the dot product.
\see cross()
*/
template <boost::uint32_t Size, typename Type>
inline Type Vector<Size, Type>::dot(const Vector<Size, Type>& rhs) const throw()
{
Type dotProduct = static_cast<Type>(0);
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
dotProduct += m_tElements[ct] * rhs.m_tElements[ct];
}
return dotProduct;
}
/**
Divides the i, j, and k components by the length to give a Vector of length 1.0.
NOTE: This function does not make much sense on integer Vectors.
*/
template <boost::uint32_t Size, typename Type>
inline void Vector<Size, Type>::normalise(void) throw()
{
double length = this->length();
//FIXME - throw div by zero exception?
if(length < 0.0001f)
{
return;
}
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] /= static_cast<Type>(length);
}
}
#pragma endregion
}//namespace Thermite

View File

@ -1,71 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
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.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_VolumeChangeTracker_H__
#define __PolyVox_VolumeChangeTracker_H__
#include <list>
#include "boost/cstdint.hpp"
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "Region.h"
#include "TypeDef.h"
namespace PolyVox
{
/// Voxel scene manager
class POLYVOX_API VolumeChangeTracker
{
public:
//Constructors, etc
VolumeChangeTracker();
~VolumeChangeTracker();
//Getters
void getChangedRegions(std::list<Region>& listToFill) const;
Region getEnclosingRegion(void) const;
boost::uint16_t getSideLength(void);
BlockVolume<boost::uint8_t>* getVolumeData(void) const;
boost::uint8_t getVoxelAt(const Vector3DUint16& pos);
boost::uint8_t getVoxelAt(boost::uint16_t uX, boost::uint16_t uY, boost::uint16_t uZ);
//Setters
void setAllRegionsUpToDate(bool newUpToDateValue);
void setLockedVoxelAt(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z, boost::uint8_t value);
void setVolumeData(BlockVolume<boost::uint8_t>* volumeDataToSet);
void setVoxelAt(boost::uint16_t x, boost::uint16_t y, boost::uint16_t z, boost::uint8_t value);
//Others
void lockRegion(const Region& regToLock);
void unlockRegion(void);
//void markRegionChanged(boost::uint16_t firstX, boost::uint16_t firstY, boost::uint16_t firstZ, boost::uint16_t lastX, boost::uint16_t lastY, boost::uint16_t lastZ);
private:
bool m_bIsLocked;
Region m_regLastLocked;
BlockVolume<boost::uint8_t>* volumeData;
LinearVolume<bool>* volRegionUpToDate;
};
}
#endif