Moved various files from PolyVoxCore to PolyVoxImpl.

This commit is contained in:
David Williams
2009-04-01 22:51:13 +00:00
parent a719aec2e7
commit bd1d2b2244
32 changed files with 33 additions and 77 deletions

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_BlockData_H__
#define __PolyVox_BlockData_H__
#pragma region Headers
#include "PolyVoxForwardDeclarations.h"
#include "PolyVoxImpl/CPlusPlusZeroXSupport.h"
#pragma endregion
namespace PolyVox
{
template <typename VoxelType>
class BlockData
{
//Make VolumeIterator a friend
friend class VolumeIterator<VoxelType>;
public:
BlockData(uint8_t uSideLength);
BlockData(const BlockData& rhs);
~BlockData();
BlockData& operator=(const BlockData& rhs);
uint16_t getSideLength(void) const;
VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const;
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
void fill(VoxelType tValue);
bool isHomogeneous(void);
private:
uint16_t m_uSideLength;
uint8_t m_uSideLengthPower;
VoxelType* m_tData;
};
}
#include "BlockData.inl"
#endif

View File

@ -0,0 +1,165 @@
#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 "Utility.h"
#include "Vector.h"
#include "Volume.h"
#include <cassert>
#include <cstring> //For memcpy
#include <stdexcept> //for std::invalid_argument
#pragma endregion
namespace PolyVox
{
#pragma region Constructors/Destructors
template <typename VoxelType>
BlockData<VoxelType>::BlockData(uint8_t uSideLength)
:m_tData(0)
{
//Debug mode validation
assert(isPowerOf2(uSideLength));
//Release mode validation
if(!isPowerOf2(uSideLength))
{
throw std::invalid_argument("BlockData side length must be a power of two.");
}
//Compute the side length
m_uSideLength = uSideLength;
m_uSideLengthPower = logBase2(uSideLength);
//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>
BlockData<VoxelType>::BlockData(const BlockData<VoxelType>& rhs)
{
*this = rhs;
}
template <typename VoxelType>
BlockData<VoxelType>::~BlockData()
{
delete[] m_tData;
m_tData = 0;
}
#pragma endregion
#pragma region Operators
template <typename VoxelType>
BlockData<VoxelType>& BlockData<VoxelType>::operator=(const BlockData<VoxelType>& rhs)
{
if (this == &rhs)
{
return *this;
}
m_uSideLength = rhs.m_uSideLength;
m_uSideLengthPower = rhs.m_uSideLengthPower;
memcpy(m_tData, rhs.m_tData, m_uSideLength * m_uSideLength * m_uSideLength);
return *this;
}
#pragma endregion
#pragma region Getters
template <typename VoxelType>
uint16_t BlockData<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType BlockData<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
{
assert(uXPos < m_uSideLength);
assert(uYPos < m_uSideLength);
assert(uZPos < m_uSideLength);
return m_tData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
];
}
template <typename VoxelType>
VoxelType BlockData<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
{
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
#pragma endregion
#pragma region Setters
template <typename VoxelType>
void BlockData<VoxelType>::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue)
{
assert(uXPos < m_uSideLength);
assert(uYPos < m_uSideLength);
assert(uZPos < m_uSideLength);
m_tData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
] = tValue;
}
template <typename VoxelType>
void BlockData<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
{
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
#pragma endregion
#pragma region Other
template <typename VoxelType>
void BlockData<VoxelType>::fill(VoxelType tValue)
{
memset(m_tData, tValue, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
}
template <typename VoxelType>
bool BlockData<VoxelType>::isHomogeneous(void)
{
VoxelType currentVoxel = m_tData;
VoxelType firstVal = *currentVoxel;
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
for(uint32_t ct = 1; ct < uNoOfVoxels; ++ct)
{
++currentVoxel;
if(*currentVoxel != firstVal)
{
return false;
}
}
return true;
}
#pragma endregion
}

View File

@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define __PolyVoxImpl_DecimatedSurfaceExtractor_H__
#pragma region Headers
#include "PolyVoxCore/Constants.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/TypeDef.h"
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "CPlusPlusZeroXSupport.h"
#pragma endregion

View File

@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define __PolyVoxImpl_FastSurfaceExtractor_H__
#pragma region Headers
#include "PolyVoxCore/Constants.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/TypeDef.h"
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "CPlusPlusZeroXSupport.h"
#pragma endregion

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

@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define __PolyVoxImpl_ReferenceSurfaceExtractor_H__
#pragma region Headers
#include "PolyVoxCore/Constants.h"
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/TypeDef.h"
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "CPlusPlusZeroXSupport.h"
#pragma endregion

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,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_Utility_H__
#define __PolyVox_Utility_H__
#include "CPlusPlusZeroXSupport.h"
#include "TypeDef.h"
#include <cassert>
namespace PolyVox
{
POLYVOX_API uint8_t logBase2(uint32_t uInput);
POLYVOX_API bool isPowerOf2(uint32_t 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