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/LargeVolume.h"
#include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxImpl/Utility.h" #include "PolyVoxCore/PolyVoxImpl/Utility.h"
#include "OpenGLImmediateModeSupport.h" #include "OpenGLImmediateModeSupport.h"
#include "OpenGLVertexBufferObjectSupport.h" #include "OpenGLVertexBufferObjectSupport.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ freely, subject to the following restrictions:
distribution. distribution.
*******************************************************************************/ *******************************************************************************/
#include "PolyVoxImpl/TypeDef.h" #include "PolyVoxCore/PolyVoxImpl/TypeDef.h"
#include "PolyVoxCore/GradientEstimators.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 // http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/index.html
#include "PolyVoxImpl/MarchingCubesTables.h" #include "PolyVoxCore/PolyVoxImpl/MarchingCubesTables.h"
namespace PolyVox namespace PolyVox
{ {

View File

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

View File

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

View File

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

View File

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

View File

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