Moved PolyVoxImpl inside of PolyVoxCore. This is the first stage of some tidying to better hide implementation details from the user.

This commit is contained in:
unknown 2012-11-05 16:40:02 +01:00
parent 29e656145e
commit 3c69bb651f
22 changed files with 1054 additions and 1054 deletions

View File

@ -31,7 +31,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/LargeVolume.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxImpl/Utility.h"
#include "PolyVoxCore/PolyVoxImpl/Utility.h"
#include "OpenGLImmediateModeSupport.h"
#include "OpenGLVertexBufferObjectSupport.h"

View File

@ -27,7 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/LowPassFilter.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxImpl/Utility.h"
#include "PolyVoxCore/PolyVoxImpl/Utility.h"
#include "OpenGLImmediateModeSupport.h"
#include "OpenGLVertexBufferObjectSupport.h"

View File

@ -104,18 +104,18 @@ SET(IMPL_SRC_FILES
)
SET(IMPL_INC_FILES
include/PolyVoxImpl/ArraySizesImpl.h
include/PolyVoxImpl/ArraySizesImpl.inl
include/PolyVoxImpl/AStarPathfinderImpl.h
include/PolyVoxImpl/Block.h
include/PolyVoxImpl/Block.inl
include/PolyVoxImpl/MarchingCubesTables.h
include/PolyVoxImpl/RandomUnitVectors.h
include/PolyVoxImpl/RandomVectors.h
include/PolyVoxImpl/SubArray.h
include/PolyVoxImpl/SubArray.inl
include/PolyVoxImpl/TypeDef.h
include/PolyVoxImpl/Utility.h
include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.h
include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.inl
include/PolyVoxCore/PolyVoxImpl/AStarPathfinderImpl.h
include/PolyVoxCore/PolyVoxImpl/Block.h
include/PolyVoxCore/PolyVoxImpl/Block.inl
include/PolyVoxCore/PolyVoxImpl/MarchingCubesTables.h
include/PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h
include/PolyVoxCore/PolyVoxImpl/RandomVectors.h
include/PolyVoxCore/PolyVoxImpl/SubArray.h
include/PolyVoxCore/PolyVoxImpl/SubArray.inl
include/PolyVoxCore/PolyVoxImpl/TypeDef.h
include/PolyVoxCore/PolyVoxImpl/Utility.h
)
#NOTE: The following line should be uncommented when building shared libs.

View File

@ -1,223 +1,223 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_AStarPathfinderImpl_H__
#define __PolyVox_AStarPathfinderImpl_H__
#include "PolyVoxCore/Vector.h"
#include <algorithm>
#include <limits> //For numeric_limits
#include <set>
#include <vector>
namespace PolyVox
{
class OpenNodesContainer;
class ClosedNodesContainer;
class ThermiteGameLogic;
/// The Connectivity of a voxel determines how many neighbours it has.
enum Connectivity
{
/// Each voxel has six neighbours, which are those sharing a face.
SixConnected,
/// Each voxel has 18 neighbours, which are those sharing a face or an edge.
EighteenConnected,
/// Each voxel has 26 neighbours, which are those sharing a face, edge, or corner.
TwentySixConnected
};
struct Node
{
Node(int x, int y, int z)
:gVal(std::numeric_limits<float>::quiet_NaN()) //Initilise with NaNs so that we will
,hVal(std::numeric_limits<float>::quiet_NaN()) //know if we forget to set these properly.
,parent(0)
{
position.setX(x);
position.setY(y);
position.setZ(z);
}
bool operator==(const Node& rhs) const
{
return position == rhs.position;
}
bool operator<(const Node& rhs) const
{
if (position.getX() < rhs.position.getX())
return true;
if (rhs.position.getX() < position.getX())
return false;
if (position.getY() < rhs.position.getY())
return true;
if (rhs.position.getY() < position.getY())
return false;
if (position.getZ() < rhs.position.getZ())
return true;
if (rhs.position.getZ() < position.getZ())
return false;
return false;
}
PolyVox::Vector3DInt32 position;
float gVal;
float hVal;
Node* parent;
float f(void) const
{
return gVal + hVal;
}
};
typedef std::set<Node> AllNodesContainer;
class AllNodesContainerIteratorComparator
{
public:
bool operator() (const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs) const
{
return (&(*lhs)) < (&(*rhs));
}
};
class NodeSort
{
public:
bool operator() (const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs) const
{
return lhs->f() > rhs->f();
}
};
class OpenNodesContainer
{
public:
typedef std::vector<AllNodesContainer::iterator>::iterator iterator;
public:
void clear(void)
{
open.clear();
}
bool empty(void) const
{
return open.empty();
}
void insert(AllNodesContainer::iterator node)
{
open.push_back(node);
push_heap(open.begin(), open.end(), NodeSort());
}
AllNodesContainer::iterator getFirst(void)
{
return open[0];
}
void removeFirst(void)
{
pop_heap(open.begin(), open.end(), NodeSort());
open.pop_back();
}
void remove(iterator iterToRemove)
{
open.erase(iterToRemove);
make_heap(open.begin(), open.end(), NodeSort());
}
iterator begin(void)
{
return open.begin();
}
iterator end(void)
{
return open.end();
}
iterator find(AllNodesContainer::iterator node)
{
std::vector<AllNodesContainer::iterator>::iterator openIter = std::find(open.begin(), open.end(), node);
return openIter;
}
private:
std::vector<AllNodesContainer::iterator> open;
};
class ClosedNodesContainer
{
public:
typedef std::set<AllNodesContainer::iterator, AllNodesContainerIteratorComparator>::iterator iterator;
public:
void clear(void)
{
closed.clear();
}
void insert(AllNodesContainer::iterator node)
{
closed.insert(node);
}
void remove(iterator iterToRemove)
{
closed.erase(iterToRemove);
}
iterator begin(void)
{
return closed.begin();
}
iterator end(void)
{
return closed.end();
}
iterator find(AllNodesContainer::iterator node)
{
iterator iter = std::find(closed.begin(), closed.end(), node);
return iter;
}
private:
std::set<AllNodesContainer::iterator, AllNodesContainerIteratorComparator> closed;
};
//bool operator<(const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs);
}
#endif //__PolyVox_AStarPathfinderImpl_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_AStarPathfinderImpl_H__
#define __PolyVox_AStarPathfinderImpl_H__
#include "PolyVoxCore/Vector.h"
#include <algorithm>
#include <limits> //For numeric_limits
#include <set>
#include <vector>
namespace PolyVox
{
class OpenNodesContainer;
class ClosedNodesContainer;
class ThermiteGameLogic;
/// The Connectivity of a voxel determines how many neighbours it has.
enum Connectivity
{
/// Each voxel has six neighbours, which are those sharing a face.
SixConnected,
/// Each voxel has 18 neighbours, which are those sharing a face or an edge.
EighteenConnected,
/// Each voxel has 26 neighbours, which are those sharing a face, edge, or corner.
TwentySixConnected
};
struct Node
{
Node(int x, int y, int z)
:gVal(std::numeric_limits<float>::quiet_NaN()) //Initilise with NaNs so that we will
,hVal(std::numeric_limits<float>::quiet_NaN()) //know if we forget to set these properly.
,parent(0)
{
position.setX(x);
position.setY(y);
position.setZ(z);
}
bool operator==(const Node& rhs) const
{
return position == rhs.position;
}
bool operator<(const Node& rhs) const
{
if (position.getX() < rhs.position.getX())
return true;
if (rhs.position.getX() < position.getX())
return false;
if (position.getY() < rhs.position.getY())
return true;
if (rhs.position.getY() < position.getY())
return false;
if (position.getZ() < rhs.position.getZ())
return true;
if (rhs.position.getZ() < position.getZ())
return false;
return false;
}
PolyVox::Vector3DInt32 position;
float gVal;
float hVal;
Node* parent;
float f(void) const
{
return gVal + hVal;
}
};
typedef std::set<Node> AllNodesContainer;
class AllNodesContainerIteratorComparator
{
public:
bool operator() (const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs) const
{
return (&(*lhs)) < (&(*rhs));
}
};
class NodeSort
{
public:
bool operator() (const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs) const
{
return lhs->f() > rhs->f();
}
};
class OpenNodesContainer
{
public:
typedef std::vector<AllNodesContainer::iterator>::iterator iterator;
public:
void clear(void)
{
open.clear();
}
bool empty(void) const
{
return open.empty();
}
void insert(AllNodesContainer::iterator node)
{
open.push_back(node);
push_heap(open.begin(), open.end(), NodeSort());
}
AllNodesContainer::iterator getFirst(void)
{
return open[0];
}
void removeFirst(void)
{
pop_heap(open.begin(), open.end(), NodeSort());
open.pop_back();
}
void remove(iterator iterToRemove)
{
open.erase(iterToRemove);
make_heap(open.begin(), open.end(), NodeSort());
}
iterator begin(void)
{
return open.begin();
}
iterator end(void)
{
return open.end();
}
iterator find(AllNodesContainer::iterator node)
{
std::vector<AllNodesContainer::iterator>::iterator openIter = std::find(open.begin(), open.end(), node);
return openIter;
}
private:
std::vector<AllNodesContainer::iterator> open;
};
class ClosedNodesContainer
{
public:
typedef std::set<AllNodesContainer::iterator, AllNodesContainerIteratorComparator>::iterator iterator;
public:
void clear(void)
{
closed.clear();
}
void insert(AllNodesContainer::iterator node)
{
closed.insert(node);
}
void remove(iterator iterToRemove)
{
closed.erase(iterToRemove);
}
iterator begin(void)
{
return closed.begin();
}
iterator end(void)
{
return closed.end();
}
iterator find(AllNodesContainer::iterator node)
{
iterator iter = std::find(closed.begin(), closed.end(), node);
return iter;
}
private:
std::set<AllNodesContainer::iterator, AllNodesContainerIteratorComparator> closed;
};
//bool operator<(const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs);
}
#endif //__PolyVox_AStarPathfinderImpl_H__

View File

@ -1,61 +1,61 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_ArraySizesImpl_H__
#define __PolyVox_ArraySizesImpl_H__
#include "PolyVoxImpl/TypeDef.h"
namespace PolyVox
{
/*
This class provides the implementation details behind ArraySizes. It is actually
quite similar to ArraySizes, but an important difference is that it is templatised
whereas ArraySizes is not. This allows us to use a recursive template pattern without
exposing the use of templates to the user.
It is based on the following article: http://www.drdobbs.com/cpp/184401319
*/
template <uint32_t N>
class ArraySizesImpl
{
typedef const uint32_t (&UIntArrayN)[N];
friend class ArraySizes;
friend class ArraySizesImpl<N-1>;
public:
ArraySizesImpl<N+1> operator () (uint32_t uSize);
operator UIntArrayN () const;
private:
ArraySizesImpl(const uint32_t (&pSizes)[N-1], uint32_t uSize);
uint32_t m_pSizes[N];
};
}//namespace PolyVox
#include "PolyVoxImpl/ArraySizesImpl.inl"
#endif //__PolyVox_ArraySizesImpl_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_ArraySizesImpl_H__
#define __PolyVox_ArraySizesImpl_H__
#include "PolyVoxImpl/TypeDef.h"
namespace PolyVox
{
/*
This class provides the implementation details behind ArraySizes. It is actually
quite similar to ArraySizes, but an important difference is that it is templatised
whereas ArraySizes is not. This allows us to use a recursive template pattern without
exposing the use of templates to the user.
It is based on the following article: http://www.drdobbs.com/cpp/184401319
*/
template <uint32_t N>
class ArraySizesImpl
{
typedef const uint32_t (&UIntArrayN)[N];
friend class ArraySizes;
friend class ArraySizesImpl<N-1>;
public:
ArraySizesImpl<N+1> operator () (uint32_t uSize);
operator UIntArrayN () const;
private:
ArraySizesImpl(const uint32_t (&pSizes)[N-1], uint32_t uSize);
uint32_t m_pSizes[N];
};
}//namespace PolyVox
#include "PolyVoxImpl/ArraySizesImpl.inl"
#endif //__PolyVox_ArraySizesImpl_H__

View File

@ -1,46 +1,46 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include <algorithm>
namespace PolyVox
{
template <uint32_t N>
ArraySizesImpl<N+1> ArraySizesImpl<N>::operator () (uint32_t uSize)
{
return ArraySizesImpl<N+1>(m_pSizes, uSize);
}
template <uint32_t N>
ArraySizesImpl<N>::operator UIntArrayN () const
{
return m_pSizes;
}
template <uint32_t N>
ArraySizesImpl<N>::ArraySizesImpl(const uint32_t (&pSizes)[N-1], uint32_t uSize)
{
std::copy(&pSizes[0],&pSizes[N-1],m_pSizes);
m_pSizes[N-1]=uSize;
}
}//namespace PolyVox
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include <algorithm>
namespace PolyVox
{
template <uint32_t N>
ArraySizesImpl<N+1> ArraySizesImpl<N>::operator () (uint32_t uSize)
{
return ArraySizesImpl<N+1>(m_pSizes, uSize);
}
template <uint32_t N>
ArraySizesImpl<N>::operator UIntArrayN () const
{
return m_pSizes;
}
template <uint32_t N>
ArraySizesImpl<N>::ArraySizesImpl(const uint32_t (&pSizes)[N-1], uint32_t uSize)
{
std::copy(&pSizes[0],&pSizes[N-1],m_pSizes);
m_pSizes[N-1]=uSize;
}
}//namespace PolyVox

View File

@ -1,78 +1,78 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Block_H__
#define __PolyVox_Block_H__
#include "PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
#include <limits>
#include <vector>
namespace PolyVox
{
template <typename VoxelType>
class Block
{
template <typename LengthType>
struct RunlengthEntry
{
LengthType length;
VoxelType value;
//We can parametise the length on anything up to uint32_t.
//This lets us experiment with the optimal size in the future.
static uint32_t maxRunlength(void) {return (std::numeric_limits<LengthType>::max)();}
};
public:
Block(uint16_t uSideLength = 0);
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);
void initialise(uint16_t uSideLength);
uint32_t calculateSizeInBytes(void);
public:
void compress(void);
void uncompress(void);
std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData;
VoxelType* m_tUncompressedData;
uint16_t m_uSideLength;
uint8_t m_uSideLengthPower;
bool m_bIsCompressed;
bool m_bIsUncompressedDataModified;
};
}
#include "PolyVoxImpl/Block.inl"
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Block_H__
#define __PolyVox_Block_H__
#include "PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
#include <limits>
#include <vector>
namespace PolyVox
{
template <typename VoxelType>
class Block
{
template <typename LengthType>
struct RunlengthEntry
{
LengthType length;
VoxelType value;
//We can parametise the length on anything up to uint32_t.
//This lets us experiment with the optimal size in the future.
static uint32_t maxRunlength(void) {return (std::numeric_limits<LengthType>::max)();}
};
public:
Block(uint16_t uSideLength = 0);
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);
void initialise(uint16_t uSideLength);
uint32_t calculateSizeInBytes(void);
public:
void compress(void);
void uncompress(void);
std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData;
VoxelType* m_tUncompressedData;
uint16_t m_uSideLength;
uint8_t m_uSideLengthPower;
bool m_bIsCompressed;
bool m_bIsUncompressedDataModified;
};
}
#include "PolyVoxImpl/Block.inl"
#endif

View File

@ -1,214 +1,214 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxImpl/Utility.h"
#include "PolyVoxCore/Vector.h"
#include <cassert>
#include <cstring> //For memcpy
#include <limits>
#include <stdexcept> //for std::invalid_argument
namespace PolyVox
{
template <typename VoxelType>
Block<VoxelType>::Block(uint16_t uSideLength)
:m_tUncompressedData(0)
,m_uSideLength(0)
,m_uSideLengthPower(0)
,m_bIsCompressed(true)
,m_bIsUncompressedDataModified(true)
{
if(uSideLength != 0)
{
initialise(uSideLength);
}
}
template <typename VoxelType>
uint16_t Block<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
{
assert(uXPos < m_uSideLength);
assert(uYPos < m_uSideLength);
assert(uZPos < m_uSideLength);
assert(m_tUncompressedData);
return m_tUncompressedData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
];
}
template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
{
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
template <typename VoxelType>
void Block<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);
assert(m_tUncompressedData);
m_tUncompressedData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
] = tValue;
m_bIsUncompressedDataModified = true;
}
template <typename VoxelType>
void Block<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
{
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
template <typename VoxelType>
void Block<VoxelType>::fill(VoxelType tValue)
{
if(!m_bIsCompressed)
{
//The memset *may* be faster than the std::fill(), but it doesn't compile nicely
//in 64-bit mode as casting the pointer to an int causes a loss of precision.
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
m_bIsUncompressedDataModified = true;
}
else
{
RunlengthEntry<uint16_t> rle;
rle.length = m_uSideLength*m_uSideLength*m_uSideLength;
rle.value = tValue;
m_vecCompressedData.clear();
m_vecCompressedData.push_back(rle);
}
}
template <typename VoxelType>
void Block<VoxelType>::initialise(uint16_t uSideLength)
{
//Debug mode validation
assert(isPowerOf2(uSideLength));
//Release mode validation
if(!isPowerOf2(uSideLength))
{
throw std::invalid_argument("Block side length must be a power of two.");
}
//Compute the side length
m_uSideLength = uSideLength;
m_uSideLengthPower = logBase2(uSideLength);
Block<VoxelType>::fill(VoxelType());
}
template <typename VoxelType>
uint32_t Block<VoxelType>::calculateSizeInBytes(void)
{
uint32_t uSizeInBytes = sizeof(Block<VoxelType>);
uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry<uint16_t>);
return uSizeInBytes;
}
template <typename VoxelType>
void Block<VoxelType>::compress(void)
{
assert(m_bIsCompressed == false);
assert(m_tUncompressedData != 0);
//If the uncompressed data hasn't actually been
//modified then we don't need to redo the compression.
if(m_bIsUncompressedDataModified)
{
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
m_vecCompressedData.clear();
RunlengthEntry<uint16_t> entry;
entry.length = 1;
entry.value = m_tUncompressedData[0];
for(uint32_t ct = 1; ct < uNoOfVoxels; ++ct)
{
VoxelType value = m_tUncompressedData[ct];
if((value == entry.value) && (entry.length < entry.maxRunlength()))
{
entry.length++;
}
else
{
m_vecCompressedData.push_back(entry);
entry.value = value;
entry.length = 1;
}
}
m_vecCompressedData.push_back(entry);
//Shrink the vectors to their contents (maybe slow?):
//http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector
//C++0x may have a shrink_to_fit() function?
std::vector< RunlengthEntry<uint16_t> >(m_vecCompressedData).swap(m_vecCompressedData);
}
//Flag the uncompressed data as no longer being used.
delete[] m_tUncompressedData;
m_tUncompressedData = 0;
m_bIsCompressed = true;
}
template <typename VoxelType>
void Block<VoxelType>::uncompress(void)
{
assert(m_bIsCompressed == true);
assert(m_tUncompressedData == 0);
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
VoxelType* pUncompressedData = m_tUncompressedData;
for(uint32_t ct = 0; ct < m_vecCompressedData.size(); ++ct)
{
std::fill(pUncompressedData, pUncompressedData + m_vecCompressedData[ct].length, m_vecCompressedData[ct].value);
pUncompressedData += m_vecCompressedData[ct].length;
}
m_bIsCompressed = false;
m_bIsUncompressedDataModified = false;
}
}
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxImpl/Utility.h"
#include "PolyVoxCore/Vector.h"
#include <cassert>
#include <cstring> //For memcpy
#include <limits>
#include <stdexcept> //for std::invalid_argument
namespace PolyVox
{
template <typename VoxelType>
Block<VoxelType>::Block(uint16_t uSideLength)
:m_tUncompressedData(0)
,m_uSideLength(0)
,m_uSideLengthPower(0)
,m_bIsCompressed(true)
,m_bIsUncompressedDataModified(true)
{
if(uSideLength != 0)
{
initialise(uSideLength);
}
}
template <typename VoxelType>
uint16_t Block<VoxelType>::getSideLength(void) const
{
return m_uSideLength;
}
template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
{
assert(uXPos < m_uSideLength);
assert(uYPos < m_uSideLength);
assert(uZPos < m_uSideLength);
assert(m_tUncompressedData);
return m_tUncompressedData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
];
}
template <typename VoxelType>
VoxelType Block<VoxelType>::getVoxelAt(const Vector3DUint16& v3dPos) const
{
return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ());
}
template <typename VoxelType>
void Block<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);
assert(m_tUncompressedData);
m_tUncompressedData
[
uXPos +
uYPos * m_uSideLength +
uZPos * m_uSideLength * m_uSideLength
] = tValue;
m_bIsUncompressedDataModified = true;
}
template <typename VoxelType>
void Block<VoxelType>::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue)
{
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
}
template <typename VoxelType>
void Block<VoxelType>::fill(VoxelType tValue)
{
if(!m_bIsCompressed)
{
//The memset *may* be faster than the std::fill(), but it doesn't compile nicely
//in 64-bit mode as casting the pointer to an int causes a loss of precision.
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
m_bIsUncompressedDataModified = true;
}
else
{
RunlengthEntry<uint16_t> rle;
rle.length = m_uSideLength*m_uSideLength*m_uSideLength;
rle.value = tValue;
m_vecCompressedData.clear();
m_vecCompressedData.push_back(rle);
}
}
template <typename VoxelType>
void Block<VoxelType>::initialise(uint16_t uSideLength)
{
//Debug mode validation
assert(isPowerOf2(uSideLength));
//Release mode validation
if(!isPowerOf2(uSideLength))
{
throw std::invalid_argument("Block side length must be a power of two.");
}
//Compute the side length
m_uSideLength = uSideLength;
m_uSideLengthPower = logBase2(uSideLength);
Block<VoxelType>::fill(VoxelType());
}
template <typename VoxelType>
uint32_t Block<VoxelType>::calculateSizeInBytes(void)
{
uint32_t uSizeInBytes = sizeof(Block<VoxelType>);
uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry<uint16_t>);
return uSizeInBytes;
}
template <typename VoxelType>
void Block<VoxelType>::compress(void)
{
assert(m_bIsCompressed == false);
assert(m_tUncompressedData != 0);
//If the uncompressed data hasn't actually been
//modified then we don't need to redo the compression.
if(m_bIsUncompressedDataModified)
{
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
m_vecCompressedData.clear();
RunlengthEntry<uint16_t> entry;
entry.length = 1;
entry.value = m_tUncompressedData[0];
for(uint32_t ct = 1; ct < uNoOfVoxels; ++ct)
{
VoxelType value = m_tUncompressedData[ct];
if((value == entry.value) && (entry.length < entry.maxRunlength()))
{
entry.length++;
}
else
{
m_vecCompressedData.push_back(entry);
entry.value = value;
entry.length = 1;
}
}
m_vecCompressedData.push_back(entry);
//Shrink the vectors to their contents (maybe slow?):
//http://stackoverflow.com/questions/1111078/reduce-the-capacity-of-an-stl-vector
//C++0x may have a shrink_to_fit() function?
std::vector< RunlengthEntry<uint16_t> >(m_vecCompressedData).swap(m_vecCompressedData);
}
//Flag the uncompressed data as no longer being used.
delete[] m_tUncompressedData;
m_tUncompressedData = 0;
m_bIsCompressed = true;
}
template <typename VoxelType>
void Block<VoxelType>::uncompress(void)
{
assert(m_bIsCompressed == true);
assert(m_tUncompressedData == 0);
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
VoxelType* pUncompressedData = m_tUncompressedData;
for(uint32_t ct = 0; ct < m_vecCompressedData.size(); ++ct)
{
std::fill(pUncompressedData, pUncompressedData + m_vecCompressedData[ct].length, m_vecCompressedData[ct].value);
pUncompressedData += m_vecCompressedData[ct].length;
}
m_bIsCompressed = false;
m_bIsUncompressedDataModified = false;
}
}

View File

@ -1,35 +1,35 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_MarchingCubeTables_H__
#define __PolyVox_MarchingCubeTables_H__
#include "PolyVoxImpl/TypeDef.h"
namespace PolyVox
{
extern const POLYVOX_API int edgeTable[256];
extern const POLYVOX_API int triTable[256][16];
}
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_MarchingCubeTables_H__
#define __PolyVox_MarchingCubeTables_H__
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
namespace PolyVox
{
extern const POLYVOX_API int edgeTable[256];
extern const POLYVOX_API int triTable[256][16];
}
#endif

View File

@ -1,36 +1,36 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_RandomUnitVectors_H__
#define __PolyVox_RandomUnitVectors_H__
#include "PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
extern POLYVOX_API const Vector3DFloat randomUnitVectors[];
}
#endif //__PolyVox_RandomUnitVectors_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_RandomUnitVectors_H__
#define __PolyVox_RandomUnitVectors_H__
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
extern POLYVOX_API const Vector3DFloat randomUnitVectors[];
}
#endif //__PolyVox_RandomUnitVectors_H__

View File

@ -1,36 +1,36 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_RandomVectors_H__
#define __PolyVox_RandomVectors_H__
#include "PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
extern POLYVOX_API const Vector3DFloat randomVectors[];
}
#endif //__PolyVox_RandomVectors_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_RandomVectors_H__
#define __PolyVox_RandomVectors_H__
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
extern POLYVOX_API const Vector3DFloat randomVectors[];
}
#endif //__PolyVox_RandomVectors_H__

View File

@ -1,88 +1,88 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_SubArray_H__
#define __PolyVox_SubArray_H__
#include "PolyVoxImpl/TypeDef.h"
namespace PolyVox
{
template <uint32_t noOfDims, typename ElementType> class Array;
/*
This class forms part of the implementation of the Array class. The operator[]
return a SubArray of the next size down, so that multiple []'s can be chained
together. It is a seperate class from Array so that it can have a reduced interface,
and also so that it never takes ownership of the memory to which it points.
It is based on the following article: http://www.drdobbs.com/cpp/184401319
*/
template <uint32_t noOfDims, typename ElementType>
class SubArray
{
friend class Array<noOfDims+1, ElementType>;
friend class SubArray<noOfDims+1, ElementType>;
public:
SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex);
const SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex) const;
private:
SubArray<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets);
uint32_t * m_pDimensions;
uint32_t * m_pOffsets;
uint32_t m_uNoOfElements;
ElementType * m_pElements;
};
template <typename ElementType>
class SubArray<1, ElementType>
{
friend class Array<2, ElementType>;
friend class SubArray<2, ElementType>;
public:
ElementType & operator [] (uint32_t uIndex);
const ElementType & operator [] (uint32_t uIndex) const;
private:
SubArray<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/);
uint32_t * m_pDimensions;
ElementType * m_pElements;
};
template <typename ElementType>
class SubArray<0, ElementType>
{
//Zero dimensional subarray is meaningless.
};
}//namespace PolyVox
#include "PolyVoxImpl/SubArray.inl"
#endif //__PolyVox_SubArray_H__
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_SubArray_H__
#define __PolyVox_SubArray_H__
#include "PolyVoxImpl/TypeDef.h"
namespace PolyVox
{
template <uint32_t noOfDims, typename ElementType> class Array;
/*
This class forms part of the implementation of the Array class. The operator[]
return a SubArray of the next size down, so that multiple []'s can be chained
together. It is a seperate class from Array so that it can have a reduced interface,
and also so that it never takes ownership of the memory to which it points.
It is based on the following article: http://www.drdobbs.com/cpp/184401319
*/
template <uint32_t noOfDims, typename ElementType>
class SubArray
{
friend class Array<noOfDims+1, ElementType>;
friend class SubArray<noOfDims+1, ElementType>;
public:
SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex);
const SubArray<noOfDims-1, ElementType> operator [](uint32_t uIndex) const;
private:
SubArray<noOfDims, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets);
uint32_t * m_pDimensions;
uint32_t * m_pOffsets;
uint32_t m_uNoOfElements;
ElementType * m_pElements;
};
template <typename ElementType>
class SubArray<1, ElementType>
{
friend class Array<2, ElementType>;
friend class SubArray<2, ElementType>;
public:
ElementType & operator [] (uint32_t uIndex);
const ElementType & operator [] (uint32_t uIndex) const;
private:
SubArray<1, ElementType>(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/);
uint32_t * m_pDimensions;
ElementType * m_pElements;
};
template <typename ElementType>
class SubArray<0, ElementType>
{
//Zero dimensional subarray is meaningless.
};
}//namespace PolyVox
#include "PolyVoxImpl/SubArray.inl"
#endif //__PolyVox_SubArray_H__

View File

@ -1,76 +1,76 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include <cassert>
namespace PolyVox
{
template <uint32_t noOfDims, typename ElementType>
SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex)
{
assert(uIndex<m_pDimensions[0]);
return
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
m_pDimensions+1, m_pOffsets+1);
}
template <uint32_t noOfDims, typename ElementType>
const SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex) const
{
assert(uIndex<m_pDimensions[0]);
return
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
m_pDimensions+1, m_pOffsets+1);
}
template <uint32_t noOfDims, typename ElementType>
SubArray<noOfDims, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
:m_pDimensions(pDimensions)
,m_pOffsets(pOffsets)
,m_uNoOfElements(0)
,m_pElements(pElements)
{
}
template <typename ElementType>
ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex)
{
assert(uIndex<m_pDimensions[0]);
return m_pElements[uIndex];
}
template <typename ElementType>
const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const
{
assert(uIndex<m_pDimensions[0]);
return m_pElements[uIndex];
}
template <typename ElementType>
SubArray<1, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
:m_pDimensions(pDimensions)
,m_pElements(pElements)
{
}
}//namespace PolyVox
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include <cassert>
namespace PolyVox
{
template <uint32_t noOfDims, typename ElementType>
SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex)
{
assert(uIndex<m_pDimensions[0]);
return
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
m_pDimensions+1, m_pOffsets+1);
}
template <uint32_t noOfDims, typename ElementType>
const SubArray<noOfDims-1, ElementType> SubArray<noOfDims, ElementType>::operator[](uint32_t uIndex) const
{
assert(uIndex<m_pDimensions[0]);
return
SubArray<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
m_pDimensions+1, m_pOffsets+1);
}
template <uint32_t noOfDims, typename ElementType>
SubArray<noOfDims, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets)
:m_pDimensions(pDimensions)
,m_pOffsets(pOffsets)
,m_uNoOfElements(0)
,m_pElements(pElements)
{
}
template <typename ElementType>
ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex)
{
assert(uIndex<m_pDimensions[0]);
return m_pElements[uIndex];
}
template <typename ElementType>
const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const
{
assert(uIndex<m_pDimensions[0]);
return m_pElements[uIndex];
}
template <typename ElementType>
SubArray<1, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/)
:m_pDimensions(pDimensions)
,m_pElements(pElements)
{
}
}//namespace PolyVox

View File

@ -1,103 +1,103 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_TypeDef_H__
#define __PolyVox_TypeDef_H__
//Definitions needed to make library functions accessable
// See http://gcc.gnu.org/wiki/Visibility for more info.
#if defined _WIN32 || defined __CYGWIN__
#define POLYVOX_HELPER_IMPORT __declspec(dllimport)
#define POLYVOX_HELPER_EXPORT __declspec(dllexport)
#define POLYVOX_HELPER_LOCAL
#else
#if __GNUC__ >= 4
#define POLYVOX_HELPER_IMPORT __attribute__ ((visibility("default")))
#define POLYVOX_HELPER_EXPORT __attribute__ ((visibility("default")))
#define POLYVOX_HELPER_LOCAL __attribute__ ((visibility("hidden")))
#else
#define POLYVOX_HELPER_IMPORT
#define POLYVOX_HELPER_EXPORT
#define POLYVOX_HELPER_LOCAL
#endif
#endif
// Now we use the generic helper definitions above to define POLYVOX_API and POLYVOX_LOCAL.
// POLYVOX_API is used for the public API symbols. It either imports or exports (or does nothing for static build)
// POLYVOX_LOCAL is used for non-api symbols.
#ifdef POLYVOX_SHARED // defined if PolyVox is compiled as a shared library
#ifdef POLYVOX_SHARED_EXPORTS // defined if we are building the PolyVox shared library (instead of using it)
#define POLYVOX_API POLYVOX_HELPER_EXPORT
#else
#define POLYVOX_API POLYVOX_HELPER_IMPORT
#endif // POLYVOX_SHARED_EXPORTS
#define POLYVOX_LOCAL POLYVOX_HELPER_LOCAL
#else // POLYVOX_SHARED is not defined: this means PolyVox is a static library.
#define POLYVOX_API
#define POLYVOX_LOCAL
#endif // POLYVOX_SHARED
//Check which compiler we are using and work around unsupported features as necessary.
#if defined(_MSC_VER) && (_MSC_VER < 1600)
//To support old (pre-vc2010) Microsoft compilers we use boost to replace the
//std::shared_ptr and potentially other C++0x features. To use this capability you
//will need to make sure you have boost installed on your system.
#include <boost/smart_ptr.hpp>
#define polyvox_shared_ptr boost::shared_ptr
#include <boost/function.hpp>
#define polyvox_function boost::function
#include <boost/bind.hpp>
#define polyvox_bind boost::bind
#define polyvox_placeholder_1 _1
#define polyvox_placeholder_2 _2
#include <boost/static_assert.hpp>
#define static_assert BOOST_STATIC_ASSERT
//As long as we're requiring boost, we'll use it to compensate
//for the missing cstdint header too.
#include <boost/cstdint.hpp>
using boost::int8_t;
using boost::int16_t;
using boost::int32_t;
using boost::uint8_t;
using boost::uint16_t;
using boost::uint32_t;
#else
//We have a decent compiler - use real C++0x features
#include <cstdint>
#include <functional>
#include <memory>
#define polyvox_shared_ptr std::shared_ptr
#define polyvox_function std::function
#define polyvox_bind std::bind
#define polyvox_placeholder_1 std::placeholders::_1
#define polyvox_placeholder_2 std::placeholders::_2
//#define static_assert static_assert //we can use this
#endif
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_TypeDef_H__
#define __PolyVox_TypeDef_H__
//Definitions needed to make library functions accessable
// See http://gcc.gnu.org/wiki/Visibility for more info.
#if defined _WIN32 || defined __CYGWIN__
#define POLYVOX_HELPER_IMPORT __declspec(dllimport)
#define POLYVOX_HELPER_EXPORT __declspec(dllexport)
#define POLYVOX_HELPER_LOCAL
#else
#if __GNUC__ >= 4
#define POLYVOX_HELPER_IMPORT __attribute__ ((visibility("default")))
#define POLYVOX_HELPER_EXPORT __attribute__ ((visibility("default")))
#define POLYVOX_HELPER_LOCAL __attribute__ ((visibility("hidden")))
#else
#define POLYVOX_HELPER_IMPORT
#define POLYVOX_HELPER_EXPORT
#define POLYVOX_HELPER_LOCAL
#endif
#endif
// Now we use the generic helper definitions above to define POLYVOX_API and POLYVOX_LOCAL.
// POLYVOX_API is used for the public API symbols. It either imports or exports (or does nothing for static build)
// POLYVOX_LOCAL is used for non-api symbols.
#ifdef POLYVOX_SHARED // defined if PolyVox is compiled as a shared library
#ifdef POLYVOX_SHARED_EXPORTS // defined if we are building the PolyVox shared library (instead of using it)
#define POLYVOX_API POLYVOX_HELPER_EXPORT
#else
#define POLYVOX_API POLYVOX_HELPER_IMPORT
#endif // POLYVOX_SHARED_EXPORTS
#define POLYVOX_LOCAL POLYVOX_HELPER_LOCAL
#else // POLYVOX_SHARED is not defined: this means PolyVox is a static library.
#define POLYVOX_API
#define POLYVOX_LOCAL
#endif // POLYVOX_SHARED
//Check which compiler we are using and work around unsupported features as necessary.
#if defined(_MSC_VER) && (_MSC_VER < 1600)
//To support old (pre-vc2010) Microsoft compilers we use boost to replace the
//std::shared_ptr and potentially other C++0x features. To use this capability you
//will need to make sure you have boost installed on your system.
#include <boost/smart_ptr.hpp>
#define polyvox_shared_ptr boost::shared_ptr
#include <boost/function.hpp>
#define polyvox_function boost::function
#include <boost/bind.hpp>
#define polyvox_bind boost::bind
#define polyvox_placeholder_1 _1
#define polyvox_placeholder_2 _2
#include <boost/static_assert.hpp>
#define static_assert BOOST_STATIC_ASSERT
//As long as we're requiring boost, we'll use it to compensate
//for the missing cstdint header too.
#include <boost/cstdint.hpp>
using boost::int8_t;
using boost::int16_t;
using boost::int32_t;
using boost::uint8_t;
using boost::uint16_t;
using boost::uint32_t;
#else
//We have a decent compiler - use real C++0x features
#include <cstdint>
#include <functional>
#include <memory>
#define polyvox_shared_ptr std::shared_ptr
#define polyvox_function std::function
#define polyvox_bind std::bind
#define polyvox_placeholder_1 std::placeholders::_1
#define polyvox_placeholder_2 std::placeholders::_2
//#define static_assert static_assert //we can use this
#endif
#endif

View File

@ -1,37 +1,37 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Utility_H__
#define __PolyVox_Utility_H__
#include "PolyVoxImpl/TypeDef.h"
#include <cassert>
namespace PolyVox
{
POLYVOX_API uint8_t logBase2(uint32_t uInput);
POLYVOX_API bool isPowerOf2(uint32_t uInput);
}
#endif
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Utility_H__
#define __PolyVox_Utility_H__
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include <cassert>
namespace PolyVox
{
POLYVOX_API uint8_t logBase2(uint32_t uInput);
POLYVOX_API bool isPowerOf2(uint32_t uInput);
}
#endif

View File

@ -21,7 +21,7 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/GradientEstimators.h"

View File

@ -26,7 +26,7 @@ freely, subject to the following restrictions:
// http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/index.html
#include "PolyVoxImpl/MarchingCubesTables.h"
#include "PolyVoxCore/PolyVoxImpl/MarchingCubesTables.h"
namespace PolyVox
{

View File

@ -21,7 +21,7 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxImpl/RandomUnitVectors.h"
#include "PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h"
namespace PolyVox
{

View File

@ -21,7 +21,7 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxImpl/RandomVectors.h"
#include "PolyVoxCore/PolyVoxImpl/RandomVectors.h"
namespace PolyVox
{

View File

@ -21,7 +21,7 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxImpl/Utility.h"
#include "PolyVoxCore/PolyVoxImpl/Utility.h"
#include <cassert>
#include <stdexcept>

View File

@ -1,4 +1,4 @@
#include "PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
namespace PolyVox
{

View File

@ -27,7 +27,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/Raycast.h"
#include "PolyVoxCore/SimpleVolume.h"
#include "PolyVoxImpl/RandomUnitVectors.h"
#include "PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h"
#include <QtTest>