Rearranging files in PolyVox.

This commit is contained in:
David Williams
2008-07-03 19:17:17 +00:00
parent 4f546d1dc4
commit 29ef5f021e
49 changed files with 6623 additions and 10 deletions

View File

@ -0,0 +1,61 @@
#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 "PolyVoxCStdInt.h"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class Block
{
//Make BlockVolumeIterator a friend
friend class BlockVolumeIterator<VoxelType>;
public:
Block(uint8 uSideLengthPower);
Block(const Block& rhs);
~Block();
Block& operator=(const Block& rhs);
uint16 getSideLength(void) const;
VoxelType getVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos) const;
void setVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos, VoxelType tValue);
void fill(VoxelType tValue);
private:
uint8 m_uSideLengthPower;
uint16 m_uSideLength;
VoxelType* m_tData;
};
}
#include "Block.inl"
#endif

View File

@ -0,0 +1,124 @@
#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(uint8 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>
uint16 Block<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(uint16 uXPos, uint16 uYPos, uint16 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(uint16 uXPos, uint16 uYPos, uint16 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

@ -0,0 +1,86 @@
#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 "PolyVoxCStdInt.h"
#include <map>
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class BlockVolume
{
//Make BlockVolumeIterator a friend
friend class BlockVolumeIterator<VoxelType>;
public:
BlockVolume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower = 5);
BlockVolume(const BlockVolume& rhs);
~BlockVolume();
BlockVolume& operator=(const BlockVolume& rhs);
Region getEnclosingRegion(void) const;
uint16 getSideLength(void) const;
VoxelType getVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos) const;
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
bool containsPoint(const Vector3DFloat& pos, float boundary) const;
bool containsPoint(const Vector3DInt32& pos, uint16 boundary) const;
BlockVolumeIterator<VoxelType> firstVoxel(void);
void idle(uint32 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;
uint32 m_uNoOfBlocksInVolume;
uint16 m_uSideLengthInBlocks;
uint8 m_uSideLengthPower;
uint16 m_uSideLength;
uint8 m_uBlockSideLengthPower;
uint16 m_uBlockSideLength;
};
//Some handy typedefs
typedef BlockVolume<float> FloatBlockVolume;
typedef BlockVolume<uint8> UInt8BlockVolume;
typedef BlockVolume<uint16> UInt16BlockVolume;
}
#include "BlockVolume.inl"
#endif

View File

@ -0,0 +1,231 @@
#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(uint8 uSideLengthPower, uint8 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(uint32 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(uint32 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 i = 0; i < POLYVOX_NO_OF_BLOCKS_IN_VOLUME; ++i)
{
//FIXME - Add checking...
m_pBlocks[i] = SharedPtr<Block>(new Block);
}*/
for(uint32 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>
uint16 BlockVolume<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType BlockVolume<VoxelType>::getVoxelAt(uint16 uXPos, uint16 uYPos, uint16 uZPos) const
{
assert(uXPos < getSideLength());
assert(uYPos < getSideLength());
assert(uZPos < getSideLength());
const uint16 blockX = uXPos >> m_uBlockSideLengthPower;
const uint16 blockY = uYPos >> m_uBlockSideLengthPower;
const uint16 blockZ = uZPos >> m_uBlockSideLengthPower;
const uint16 xOffset = uXPos - (blockX << m_uBlockSideLengthPower);
const uint16 yOffset = uYPos - (blockY << m_uBlockSideLengthPower);
const uint16 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, uint16 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(uint32 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

@ -0,0 +1,138 @@
#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 "PolyVoxCStdInt.h"
#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);
uint16 getPosX(void) const;
uint16 getPosY(void) const;
uint16 getPosZ(void) const;
VoxelType getSubSampledVoxel(uint8 uLevel) const;
const BlockVolume<VoxelType>& getVolume(void) const;
VoxelType getVoxel(void) const;
void setPosition(const Vector3DInt16& v3dNewPos);
void setPosition(uint16 xPos, uint16 yPos, uint16 zPos);
void setValidRegion(const Region& region);
void setValidRegion(uint16 xFirst, uint16 yFirst, uint16 zFirst, uint16 xLast, uint16 yLast, uint16 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
uint16 mXPosInVolume;
uint16 mYPosInVolume;
uint16 mZPosInVolume;
//The position of the current block
uint16 mXBlock;
uint16 mYBlock;
uint16 mZBlock;
//The offset into the current block
uint16 mXPosInBlock;
uint16 mYPosInBlock;
uint16 mZPosInBlock;
//Other current position information
VoxelType* mCurrentVoxel;
uint32 mBlockIndexInVolume;
uint32 mVoxelIndexInBlock;
uint16 mXRegionFirst;
uint16 mYRegionFirst;
uint16 mZRegionFirst;
uint16 mXRegionLast;
uint16 mYRegionLast;
uint16 mZRegionLast;
uint16 mXRegionFirstBlock;
uint16 mYRegionFirstBlock;
uint16 mZRegionFirstBlock;
uint16 mXRegionLastBlock;
uint16 mYRegionLastBlock;
uint16 mZRegionLastBlock;
bool mIsValidForRegion;
};
}
#include "BlockVolumeIterator.inl"
#endif

View File

@ -0,0 +1,684 @@
#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>
uint16 BlockVolumeIterator<VoxelType>::getPosX(void) const
{
return mXPosInVolume;
}
template <typename VoxelType>
uint16 BlockVolumeIterator<VoxelType>::getPosY(void) const
{
return mYPosInVolume;
}
template <typename VoxelType>
uint16 BlockVolumeIterator<VoxelType>::getPosZ(void) const
{
return mZPosInVolume;
}
template <typename VoxelType>
VoxelType BlockVolumeIterator<VoxelType>::getSubSampledVoxel(uint8 uLevel) const
{
if(uLevel == 0)
{
return getVoxel();
}
else if(uLevel == 1)
{
VoxelType tValue = getVoxel();
tValue = (std::max)(tValue, peekVoxel1px0py0pz());
tValue = (std::max)(tValue, peekVoxel0px1py0pz());
tValue = (std::max)(tValue, peekVoxel1px1py0pz());
tValue = (std::max)(tValue, peekVoxel0px0py1pz());
tValue = (std::max)(tValue, peekVoxel1px0py1pz());
tValue = (std::max)(tValue, peekVoxel0px1py1pz());
tValue = (std::max)(tValue, peekVoxel1px1py1pz());
return tValue;
}
else
{
const uint8 uSize = 1 << uLevel;
VoxelType tValue = 0;
for(uint8 z = 0; z < uSize; ++z)
{
for(uint8 y = 0; y < uSize; ++y)
{
for(uint8 x = 0; x < uSize; ++x)
{
tValue = (std::max)(tValue, mVolume.getVoxelAt(mXPosInVolume + x, mYPosInVolume + y, mZPosInVolume + z));
}
}
}
return tValue;
}
}
template <typename VoxelType>
const BlockVolume<VoxelType>& BlockVolumeIterator<VoxelType>::getVolume(void) const
{
return mVolume;
}
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(uint16 xPos, uint16 yPos, uint16 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(uint16 xFirst, uint16 yFirst, uint16 zFirst, uint16 xLast, uint16 yLast, uint16 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 uint32 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(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(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(mXBlock * mVolume.m_uBlockSideLength));
mYPosInVolume = (std::max)(mYRegionFirst,uint16(mYBlock * mVolume.m_uBlockSideLength));
mZPosInVolume = (std::max)(mZRegionFirst,uint16(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

@ -0,0 +1,45 @@
#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 "PolyVoxForwardDeclarations.h"
namespace PolyVox
{
//FIXME - i think we can define mod using a bitmask which flattens the upper bits. Should define that here.
//const uint32 POLYVOX_BLOCK_SIDE_LENGTH_POWER = 5;
//const uint32 POLYVOX_BLOCK_SIDE_LENGTH = (0x0001 << POLYVOX_BLOCK_SIDE_LENGTH_POWER);
//const uint32 POLYVOX_NO_OF_VOXELS_IN_BLOCK = (POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH * POLYVOX_BLOCK_SIDE_LENGTH);
const uint16 POLYVOX_VOLUME_SIDE_LENGTH_POWER = 8;
const uint16 POLYVOX_VOLUME_SIDE_LENGTH = (0x0001 << POLYVOX_VOLUME_SIDE_LENGTH_POWER);
//const uint32 POLYVOX_VOLUME_SIDE_LENGTH_IN_BLOCKS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_BLOCK_SIDE_LENGTH_POWER);
//const uint32 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 uint32 POLYVOX_NO_OF_VOXELS_IN_VOLUME = (POLYVOX_VOLUME_SIDE_LENGTH * POLYVOX_VOLUME_SIDE_LENGTH * POLYVOX_VOLUME_SIDE_LENGTH);
const uint16 POLYVOX_REGION_SIDE_LENGTH_POWER = 4;
const uint16 POLYVOX_REGION_SIDE_LENGTH = (0x0001 << POLYVOX_REGION_SIDE_LENGTH_POWER);
const uint16 POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS = (POLYVOX_VOLUME_SIDE_LENGTH >> POLYVOX_REGION_SIDE_LENGTH_POWER);
}
#endif

View File

@ -0,0 +1,35 @@
#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

@ -0,0 +1,49 @@
#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"
#include <vector>
namespace PolyVox
{
template <typename VoxelType>
Vector3DFloat computeCentralDifferenceGradient(const BlockVolumeIterator<VoxelType>& volIter);
template <typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter);
template <typename VoxelType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter);
template <typename VoxelType>
Vector3DFloat computeSobelGradient(const BlockVolumeIterator<VoxelType>& volIter);
POLYVOX_API void computeNormalsForVertices(BlockVolume<uint8>* volumeData, RegionGeometry& regGeom, NormalGenerationMethod normalGenerationMethod);
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<uint8>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
}
#include "GradientEstimators.inl"
#endif //__PolyVox_GradientEstimators_H__

View File

@ -0,0 +1,185 @@
#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 "VoxelFilters.h"
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>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template <typename VoxelType>
Vector3DFloat computeDecimatedCentralDifferenceGradient(const BlockVolumeIterator<VoxelType>& volIter)
{
const uint16 x = volIter.getPosX();
const uint16 y = volIter.getPosY();
const uint16 z = volIter.getPosZ();
//FIXME - bitwise way of doing this?
VoxelType voxel1nx = volIter.getVoxelAt(x-2, y ,z ) > 0 ? 1: 0;
VoxelType voxel1px = volIter.getVoxelAt(x-2, y ,z ) > 0 ? 1: 0;
VoxelType voxel1ny = volIter.getVoxelAt(x , y-2,z ) > 0 ? 1: 0;
VoxelType voxel1py = volIter.getVoxelAt(x , y-2,z ) > 0 ? 1: 0;
VoxelType voxel1nz = volIter.getVoxelAt(x , y ,z-2) > 0 ? 1: 0;
VoxelType voxel1pz = volIter.getVoxelAt(x , y ,z-2) > 0 ? 1: 0;
return Vector3DFloat
(
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
);
}
template <typename VoxelType>
Vector3DFloat computeSmoothCentralDifferenceGradient(BlockVolumeIterator<VoxelType>& volIter)
{
uint16 initialX = volIter.getPosX();
uint16 initialY = volIter.getPosY();
uint16 initialZ = volIter.getPosZ();
//FIXME - bitwise way of doing this?
volIter.setPosition(initialX-1, initialY, initialZ);
float voxel1nx = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX+1, initialY, initialZ);
float voxel1px = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY-1, initialZ);
float voxel1ny = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY+1, initialZ);
float voxel1py = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY, initialZ-1);
float voxel1nz = computeSmoothedVoxel(volIter);
volIter.setPosition(initialX, initialY, initialZ+1);
float voxel1pz = computeSmoothedVoxel(volIter);
return Vector3DFloat
(
voxel1nx - voxel1px,
voxel1ny - voxel1py,
voxel1nz - voxel1pz
);
}
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);
//Note: The above actually give gradients going from low density to high density.
//For our normals we want the the other way around, so we switch the components as we return them.
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
}
}

View File

@ -0,0 +1,59 @@
#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 "PolyVoxCStdInt.h"
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "SurfaceVertex.h"
#include "TypeDef.h"
namespace PolyVox
{
class POLYVOX_API IndexedSurfacePatch
{
public:
IndexedSurfacePatch();
~IndexedSurfacePatch();
void addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2);
void fillVertexAndIndexData(std::vector<SurfaceVertex>& vecVertices, std::vector<uint32>& vecIndices);
const std::vector<SurfaceVertex>& getVertices(void) const;
std::vector<SurfaceVertex>& getVertices(void); //FIXME - non const version should be removed.
const std::vector<uint32>& getIndices(void) const;
unsigned short getNoNonUniformTrianges(void);
unsigned short getNoUniformTrianges(void);
public:
std::vector<uint32> m_vecTriangleIndices;
std::vector<SurfaceVertex> m_vecVertices;
};
}
#endif /* __IndexedSurfacePatch_H__ */

View File

@ -0,0 +1,64 @@
#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 "PolyVoxCStdInt.h"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class LinearVolume
{
public:
LinearVolume(uint8 uSideLengthPower);
LinearVolume(const LinearVolume& rhs);
~LinearVolume();
LinearVolume& operator=(const LinearVolume& rhs);
//bool isHomogeneous(void);
uint16 getSideLength(void);
VoxelType getVoxelAt(const uint16 xPosition, const uint16 yPosition, const uint16 zPosition) const;
void setVoxelAt(const uint16 xPosition, const uint16 yPosition, const uint16 zPosition, const VoxelType value);
//void fillWithValue(const VoxelType value);
private:
uint32 getNoOfVoxels(void);
uint8 m_uSideLengthPower;
uint16 m_uSideLength;
VoxelType* m_tData;
};
}
#include "LinearVolume.inl"
#endif

View File

@ -0,0 +1,102 @@
#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(uint8 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 uint16 xPosition, const uint16 yPosition, const uint16 zPosition) const
{
return m_tData
[
xPosition +
yPosition * m_uSideLength +
zPosition * m_uSideLength * m_uSideLength
];
}
template <typename VoxelType>
void LinearVolume<VoxelType>::setVoxelAt(const uint16 xPosition, const uint16 yPosition, const uint16 zPosition, const VoxelType value)
{
m_tData
[
xPosition +
yPosition * m_uSideLength +
zPosition * m_uSideLength * m_uSideLength
] = value;
}
template <typename VoxelType>
uint16 LinearVolume<VoxelType>::getSideLength(void)
{
return m_uSideLength;
}
template <typename VoxelType>
uint32 LinearVolume<VoxelType>::getNoOfVoxels(void)
{
return m_uSideLength * m_uSideLength * m_uSideLength;
}
}

View File

@ -0,0 +1,31 @@
#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

@ -0,0 +1,38 @@
#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_CStdInt_H__
#define __PolyVox_CStdInt_H__
//Adding things to the std namespace in not actually allowed, but Microsoft
//have still not added <cstdint> to thier standard library.
namespace PolyVox
{
typedef char int8;
typedef short int16;
typedef long int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
}
#endif

View File

@ -0,0 +1,61 @@
#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 "PolyVoxCStdInt.h"
namespace PolyVox
{
template <typename VoxelType> class Block;
//---------- BlockVolume ----------
template <typename VoxelType> class BlockVolume;
typedef BlockVolume<float> FloatBlockVolume;
typedef BlockVolume<uint8> UInt8BlockVolume;
typedef BlockVolume<uint16> UInt16BlockVolume;
//---------------------------------
class IndexedSurfacePatch;
class IntegrealVector3;
template <typename VoxelType> class LinearVolume;
class Region;
class RegionGeometry;
class SurfaceVertex;
//---------- Vector ----------
template <uint32 Size, typename Type> class Vector;
typedef Vector<3,float> Vector3DFloat;
typedef Vector<3,double> Vector3DDouble;
typedef Vector<3,int8> Vector3DInt8;
typedef Vector<3,uint8> Vector3DUint8;
typedef Vector<3,int16> Vector3DInt16;
typedef Vector<3,uint16> Vector3DUint16;
typedef Vector<3,int32> Vector3DInt32;
typedef Vector<3,uint32> Vector3DUint32;
//----------------------------
template <typename VoxelType> class BlockVolumeIterator;
}
#endif

View File

@ -0,0 +1,55 @@
#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, uint8 boundary) const;
void cropTo(const Region& other);
void shift(const Vector3DInt32& amount);
private:
Vector3DInt32 m_v3dLowerCorner;
Vector3DInt32 m_v3dUpperCorner;
};
}
#endif

View File

@ -0,0 +1,44 @@
#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

@ -0,0 +1,39 @@
#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_SurfaceAdjusters_H__
#define __PolyVox_SurfaceAdjusters_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "PolyVoxCStdInt.h"
#pragma endregion
namespace PolyVox
{
POLYVOX_API void smoothRegionGeometry(BlockVolume<uint8>* volumeData, RegionGeometry& regGeom);
POLYVOX_API void adjustDecimatedGeometry(BlockVolume<uint8>* volumeData, RegionGeometry& regGeom, uint8 val);
}
#endif

View File

@ -0,0 +1,65 @@
/******************************************************************************
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

@ -0,0 +1,51 @@
#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 "PolyVoxCStdInt.h"
#include <list>
#pragma endregion
namespace PolyVox
{
uint32 getIndex(uint32 x, uint32 y);
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API uint32 computeInitialRoughBitmaskForSlice(BlockVolumeIterator<uint8>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8 *bitmask);
POLYVOX_API uint32 computeRoughBitmaskForSliceFromPrevious(BlockVolumeIterator<uint8>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8 *bitmask, uint8 *previousBitmask);
POLYVOX_API void generateRoughIndicesForSlice(BlockVolumeIterator<uint8>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8* bitmask0, uint8* bitmask1, int32 vertexIndicesX0[],int32 vertexIndicesY0[],int32 vertexIndicesZ0[], int32 vertexIndicesX1[],int32 vertexIndicesY1[],int32 vertexIndicesZ1[]);
POLYVOX_API void generateRoughVerticesForSlice(BlockVolumeIterator<uint8>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8* bitmask, IndexedSurfacePatch* singleMaterialPatch,int32 vertexIndicesX[],int32 vertexIndicesY[],int32 vertexIndicesZ[]);
POLYVOX_API void generateReferenceMeshDataForRegion(BlockVolume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
int32 getIndexFor(const Vector3DFloat& pos, int32 vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1], int32 vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1], int32 vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1]);
void setIndexFor(const Vector3DFloat& pos, int32 newIndex, int32 vertexIndicesX[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1], int32 vertexIndicesY[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1], int32 vertexIndicesZ[POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1][POLYVOX_REGION_SIDE_LENGTH+1]);
}
#endif

View File

@ -0,0 +1,50 @@
#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_SurfaceExtractorsDecimated_H__
#define __PolyVox_SurfaceExtractorsDecimated_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#include "PolyVoxCStdInt.h"
#include <list>
#pragma endregion
namespace PolyVox
{
uint32 getDecimatedIndex(uint32 x, uint32 y);
POLYVOX_API void generateDecimatedMeshDataForRegion(BlockVolume<uint8>* volumeData, uint8 uLevel, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API uint32 computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<uint8>& volIter, uint8 uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8 *bitmask);
POLYVOX_API uint32 computeDecimatedBitmaskForSliceFromPrevious(BlockVolumeIterator<uint8>& volIter, uint8 uLevel, const Region& regSlice, const Vector3DFloat& offset, uint8 *bitmask, uint8 *previousBitmask);
POLYVOX_API void generateDecimatedIndicesForSlice(BlockVolumeIterator<uint8>& volIter, uint8 uLevel, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, uint8* bitmask0, uint8* bitmask1, int32 vertexIndicesX0[],int32 vertexIndicesY0[],int32 vertexIndicesZ0[], int32 vertexIndicesX1[],int32 vertexIndicesY1[],int32 vertexIndicesZ1[]);
POLYVOX_API void generateDecimatedVerticesForSlice(BlockVolumeIterator<uint8>& volIter, uint8 uLevel, Region& regSlice, const Vector3DFloat& offset, uint8* bitmask, IndexedSurfacePatch* singleMaterialPatch,int32 vertexIndicesX[],int32 vertexIndicesY[],int32 vertexIndicesZ[]);
POLYVOX_API void generateDecimatedMeshDataForRegionSlow(BlockVolume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
POLYVOX_API Vector3DFloat computeDecimatedNormal(BlockVolume<uint8>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
}
#endif

View File

@ -0,0 +1,50 @@
/******************************************************************************
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

@ -0,0 +1,19 @@
#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

@ -0,0 +1,60 @@
#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);
SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet);
float getMaterial(void) const;
const Vector3DFloat& getNormal(void) const;
const Vector3DFloat& getPosition(void) const;
void setMaterial(float materialToSet);
void setNormal(const Vector3DFloat& normalToSet);
void setPosition(const Vector3DFloat& positionToSet);
std::string tostring(void) const;
private:
Vector3DFloat position;
Vector3DFloat normal;
float material;
};
//bool operator < (const SurfaceVertexIterator& lhs, const SurfaceVertexIterator& rhs);
}
#endif

View File

@ -0,0 +1,37 @@
#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

@ -0,0 +1,60 @@
#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 "PolyVoxForwardDeclarations.h"
namespace PolyVox
{
POLYVOX_API uint8 logBase2(uint32 uInput);
POLYVOX_API bool isPowerOf2(uint32 uInput);
template <typename Type>
Type trilinearlyInterpolate(
const Type& v000,const Type& v100,const Type& v010,const Type& v110,
const Type& v001,const Type& v101,const Type& v011,const Type& v111,
const float x, const float y, const float z)
{
assert((x >= 0.0f) && (y >= 0.0f) && (z >= 0.0f) &&
(x <= 1.0f) && (y <= 1.0f) && (z <= 1.0f));
//Interpolate along X
Type v000_v100 = (v100 - v000) * x + v000;
Type v001_v101 = (v101 - v001) * x + v001;
Type v010_v110 = (v110 - v010) * x + v010;
Type v011_v111 = (v111 - v011) * x + v011;
//Interpolate along Y
Type v000_v100__v010_v110 = (v010_v110 - v000_v100) * y + v000_v100;
Type v001_v101__v011_v111 = (v011_v111 - v001_v101) * y + v001_v101;
//Interpolate along Z
Type v000_v100__v010_v110____v001_v101__v011_v111 = (v001_v101__v011_v111 - v000_v100__v010_v110) * z + v000_v100__v010_v110;
return v000_v100__v010_v110____v001_v101__v011_v111;
}
}
#endif

View File

@ -0,0 +1,150 @@
#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 "PolyVoxForwardDeclarations.h"
#include <iostream>
#pragma endregion
namespace PolyVox
{
///Represents a vector in space.
template <uint32 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(uint32 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(uint32 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 <uint32 Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Subtraction operator.
template <uint32 Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Multiplication operator.
template <uint32 Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Division operator.
template <uint32 Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Stream insertion operator.
template <uint32 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,int8> Vector3DInt8;
///A 3D Vector of unsigned 8-bit values.
typedef Vector<3,uint8> Vector3DUint8;
///A 3D Vector of signed 16-bit values.
typedef Vector<3,int16> Vector3DInt16;
///A 3D Vector of unsigned 16-bit values.
typedef Vector<3,uint16> Vector3DUint16;
///A 3D Vector of signed 32-bit values.
typedef Vector<3,int32> Vector3DInt32;
///A 3D Vector of unsigned 32-bit values.
typedef Vector<3,uint32> Vector3DUint32;
}//namespace Thermite
#include "Vector.inl"
#endif

View File

@ -0,0 +1,536 @@
#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 std::operators.
Lastly, note that for convienience a set of typedefs are included for 2 and 3 dimentionsal
vectors with type float, double, int32, and uint32. 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 <uint32 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 <uint32 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 <uint32 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 <uint32 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 <uint32 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 <uint32 Size, typename Type>
template <typename CastType>
Vector<Size, Type>::Vector(const Vector<Size, CastType>& vector) throw()
{
for(uint32 ct = 0; ct < Size; ++ct)
{
m_tElements[ct] = static_cast<CastType>(vector.getElement(ct));
}
}
/**
Destroys the Vector.
*/
template <uint32 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 <uint32 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 <uint32 Size, typename Type>
inline bool Vector<Size, Type>::operator==(const Vector<Size, Type> &rhs) const throw()
{
bool equal = true;
for(uint32 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 <uint32 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 <uint32 Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator+=(const Vector<Size, Type>& rhs) throw()
{
for(uint32 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 <uint32 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 <uint32 Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator-=(const Vector<Size, Type>& rhs) throw()
{
for(uint32 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 <uint32 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 <uint32 Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator*=(const Type& rhs) throw()
{
for(uint32 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 <uint32 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 <uint32 Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator/=(const Type& rhs) throw()
{
for(uint32 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 <uint32 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 <uint32 Size, typename Type>
std::ostream& operator<<(std::ostream& os, const Vector<Size, Type>& vector) throw()
{
os << "(";
for(uint32 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 <uint32 Size, typename Type>
inline Type Vector<Size, Type>::getElement(uint32 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 <uint32 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 <uint32 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 <uint32 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 <uint32 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 <uint32 Size, typename Type>
inline void Vector<Size, Type>::setElement(uint32 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 <uint32 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 <uint32 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 <uint32 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 <uint32 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 <uint32 Size, typename Type>
inline double Vector<Size, Type>::length(void) const throw()
{
return sqrt(lengthSquared());
}
/**
\return Squared length of the Vector.
*/
template <uint32 Size, typename Type>
inline double Vector<Size, Type>::lengthSquared(void) const throw()
{
double result = 0.0f;
for(uint32 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 <uint32 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 <uint32 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 <uint32 Size, typename Type>
inline Type Vector<Size, Type>::dot(const Vector<Size, Type>& rhs) const throw()
{
Type dotProduct = static_cast<Type>(0);
for(uint32 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 <uint32 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(uint32 ct = 0; ct < Size; ++ct)
{
m_tElements[ct] /= static_cast<Type>(length);
}
}
#pragma endregion
}//namespace Thermite

View File

@ -0,0 +1,36 @@
#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_VoxelFilters_H__
#define __PolyVox_VoxelFilters_H__
#pragma region Headers
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "TypeDef.h"
#pragma endregion
namespace PolyVox
{
float computeSmoothedVoxel(BlockVolumeIterator<uint8>& volIter);
}
#endif

View File

@ -0,0 +1,69 @@
#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 "PolyVoxCore/Constants.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/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;
uint16 getSideLength(void);
BlockVolume<uint8>* getVolumeData(void) const;
uint8 getVoxelAt(const Vector3DUint16& pos);
uint8 getVoxelAt(uint16 uX, uint16 uY, uint16 uZ);
//Setters
void setAllRegionsUpToDate(bool newUpToDateValue);
void setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value);
void setVolumeData(BlockVolume<uint8>* volumeDataToSet);
void setVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value);
//Others
void lockRegion(const Region& regToLock);
void unlockRegion(void);
//void markRegionChanged(uint16 firstX, uint16 firstY, uint16 firstZ, uint16 lastX, uint16 lastY, uint16 lastZ);
private:
bool m_bIsLocked;
Region m_regLastLocked;
BlockVolume<uint8>* volumeData;
LinearVolume<bool>* volRegionUpToDate;
};
}
#endif