diff --git a/examples/OpenGL/OpenGLWidget.h b/examples/OpenGL/OpenGLWidget.h index 2a808b4b..20d108aa 100644 --- a/examples/OpenGL/OpenGLWidget.h +++ b/examples/OpenGL/OpenGLWidget.h @@ -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" diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 3766f808..e7501c41 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -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" diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 5ba8bc68..175fca8d 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -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. diff --git a/library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/AStarPathfinderImpl.h similarity index 95% rename from library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/AStarPathfinderImpl.h index 0fbf2e96..f37bbfa8 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/AStarPathfinderImpl.h @@ -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 -#include //For numeric_limits -#include -#include - -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::quiet_NaN()) //Initilise with NaNs so that we will - ,hVal(std::numeric_limits::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 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::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::iterator openIter = std::find(open.begin(), open.end(), node); - return openIter; - } - - private: - std::vector open; - }; - - class ClosedNodesContainer - { - public: - typedef std::set::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 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 +#include //For numeric_limits +#include +#include + +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::quiet_NaN()) //Initilise with NaNs so that we will + ,hVal(std::numeric_limits::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 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::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::iterator openIter = std::find(open.begin(), open.end(), node); + return openIter; + } + + private: + std::vector open; + }; + + class ClosedNodesContainer + { + public: + typedef std::set::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 closed; + }; + + + //bool operator<(const AllNodesContainer::iterator& lhs, const AllNodesContainer::iterator& rhs); +} + +#endif //__PolyVox_AStarPathfinderImpl_H__ diff --git a/library/PolyVoxCore/include/PolyVoxImpl/ArraySizesImpl.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.h similarity index 97% rename from library/PolyVoxCore/include/PolyVoxImpl/ArraySizesImpl.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.h index 884cdf6a..ced5b002 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/ArraySizesImpl.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.h @@ -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 - class ArraySizesImpl - { - typedef const uint32_t (&UIntArrayN)[N]; - - friend class ArraySizes; - friend class ArraySizesImpl; - - public: - ArraySizesImpl 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 + class ArraySizesImpl + { + typedef const uint32_t (&UIntArrayN)[N]; + + friend class ArraySizes; + friend class ArraySizesImpl; + + public: + ArraySizesImpl 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__ diff --git a/library/PolyVoxCore/include/PolyVoxImpl/ArraySizesImpl.inl b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.inl similarity index 97% rename from library/PolyVoxCore/include/PolyVoxImpl/ArraySizesImpl.inl rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.inl index 99f6ef67..13836476 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/ArraySizesImpl.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/ArraySizesImpl.inl @@ -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 - -namespace PolyVox -{ - template - ArraySizesImpl ArraySizesImpl::operator () (uint32_t uSize) - { - return ArraySizesImpl(m_pSizes, uSize); - } - - template - ArraySizesImpl::operator UIntArrayN () const - { - return m_pSizes; - } - - template - ArraySizesImpl::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 + +namespace PolyVox +{ + template + ArraySizesImpl ArraySizesImpl::operator () (uint32_t uSize) + { + return ArraySizesImpl(m_pSizes, uSize); + } + + template + ArraySizesImpl::operator UIntArrayN () const + { + return m_pSizes; + } + + template + ArraySizesImpl::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 diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Block.h similarity index 96% rename from library/PolyVoxCore/include/PolyVoxImpl/Block.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Block.h index c102ffa7..7aa8ebd4 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Block.h @@ -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 -#include - -namespace PolyVox -{ - template - class Block - { - template - 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::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 > 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 +#include + +namespace PolyVox +{ + template + class Block + { + template + 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::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 > m_vecCompressedData; + VoxelType* m_tUncompressedData; + uint16_t m_uSideLength; + uint8_t m_uSideLengthPower; + bool m_bIsCompressed; + bool m_bIsUncompressedDataModified; + }; +} + +#include "PolyVoxImpl/Block.inl" + +#endif diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Block.inl similarity index 96% rename from library/PolyVoxCore/include/PolyVoxImpl/Block.inl rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Block.inl index 6e5d942d..77ef83df 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Block.inl @@ -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 -#include //For memcpy -#include -#include //for std::invalid_argument - -namespace PolyVox -{ - template - Block::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 - uint16_t Block::getSideLength(void) const - { - return m_uSideLength; - } - - template - VoxelType Block::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 - VoxelType Block::getVoxelAt(const Vector3DUint16& v3dPos) const - { - return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); - } - - template - void Block::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 - void Block::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue) - { - setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); - } - - template - void Block::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 rle; - rle.length = m_uSideLength*m_uSideLength*m_uSideLength; - rle.value = tValue; - m_vecCompressedData.clear(); - m_vecCompressedData.push_back(rle); - } - } - - template - void Block::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::fill(VoxelType()); - } - - template - uint32_t Block::calculateSizeInBytes(void) - { - uint32_t uSizeInBytes = sizeof(Block); - uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry); - return uSizeInBytes; - } - - template - void Block::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 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 >(m_vecCompressedData).swap(m_vecCompressedData); - } - - //Flag the uncompressed data as no longer being used. - delete[] m_tUncompressedData; - m_tUncompressedData = 0; - m_bIsCompressed = true; - } - - template - void Block::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 +#include //For memcpy +#include +#include //for std::invalid_argument + +namespace PolyVox +{ + template + Block::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 + uint16_t Block::getSideLength(void) const + { + return m_uSideLength; + } + + template + VoxelType Block::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 + VoxelType Block::getVoxelAt(const Vector3DUint16& v3dPos) const + { + return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); + } + + template + void Block::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 + void Block::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue) + { + setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); + } + + template + void Block::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 rle; + rle.length = m_uSideLength*m_uSideLength*m_uSideLength; + rle.value = tValue; + m_vecCompressedData.clear(); + m_vecCompressedData.push_back(rle); + } + } + + template + void Block::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::fill(VoxelType()); + } + + template + uint32_t Block::calculateSizeInBytes(void) + { + uint32_t uSizeInBytes = sizeof(Block); + uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry); + return uSizeInBytes; + } + + template + void Block::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 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 >(m_vecCompressedData).swap(m_vecCompressedData); + } + + //Flag the uncompressed data as no longer being used. + delete[] m_tUncompressedData; + m_tUncompressedData = 0; + m_bIsCompressed = true; + } + + template + void Block::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; + } +} diff --git a/library/PolyVoxCore/include/PolyVoxImpl/MarchingCubesTables.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/MarchingCubesTables.h similarity index 94% rename from library/PolyVoxCore/include/PolyVoxImpl/MarchingCubesTables.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/MarchingCubesTables.h index da199fcd..d1e2dc52 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/MarchingCubesTables.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/MarchingCubesTables.h @@ -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 diff --git a/library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h similarity index 94% rename from library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h index 7e1c237d..36bbc4fd 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h @@ -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__ diff --git a/library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/RandomVectors.h similarity index 94% rename from library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/RandomVectors.h index 6df39f08..1d9244a6 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/RandomVectors.h @@ -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__ diff --git a/library/PolyVoxCore/include/PolyVoxImpl/SubArray.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/SubArray.h similarity index 96% rename from library/PolyVoxCore/include/PolyVoxImpl/SubArray.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/SubArray.h index 06b235a9..23e5d262 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/SubArray.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/SubArray.h @@ -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 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 - class SubArray - { - friend class Array; - friend class SubArray; - - public: - SubArray operator [](uint32_t uIndex); - - const SubArray operator [](uint32_t uIndex) const; - - private: - SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets); - - uint32_t * m_pDimensions; - uint32_t * m_pOffsets; - uint32_t m_uNoOfElements; - ElementType * m_pElements; - }; - - template - 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 - 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 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 + class SubArray + { + friend class Array; + friend class SubArray; + + public: + SubArray operator [](uint32_t uIndex); + + const SubArray operator [](uint32_t uIndex) const; + + private: + SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets); + + uint32_t * m_pDimensions; + uint32_t * m_pOffsets; + uint32_t m_uNoOfElements; + ElementType * m_pElements; + }; + + template + 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 + class SubArray<0, ElementType> + { + //Zero dimensional subarray is meaningless. + }; +}//namespace PolyVox + +#include "PolyVoxImpl/SubArray.inl" + +#endif //__PolyVox_SubArray_H__ diff --git a/library/PolyVoxCore/include/PolyVoxImpl/SubArray.inl b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/SubArray.inl similarity index 97% rename from library/PolyVoxCore/include/PolyVoxImpl/SubArray.inl rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/SubArray.inl index 398c060b..49ae1ea0 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/SubArray.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/SubArray.inl @@ -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 - -namespace PolyVox -{ - template - SubArray SubArray::operator[](uint32_t uIndex) - { - assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], - m_pDimensions+1, m_pOffsets+1); - } - - template - const SubArray SubArray::operator[](uint32_t uIndex) const - { - assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], - m_pDimensions+1, m_pOffsets+1); - } - - template - SubArray::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets) - :m_pDimensions(pDimensions) - ,m_pOffsets(pOffsets) - ,m_uNoOfElements(0) - ,m_pElements(pElements) - { - } - - - template - ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) - { - assert(uIndex - const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const - { - assert(uIndex - 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 + +namespace PolyVox +{ + template + SubArray SubArray::operator[](uint32_t uIndex) + { + assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], + m_pDimensions+1, m_pOffsets+1); + } + + template + const SubArray SubArray::operator[](uint32_t uIndex) const + { + assert(uIndex(&m_pElements[uIndex*m_pOffsets[0]], + m_pDimensions+1, m_pOffsets+1); + } + + template + SubArray::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * pOffsets) + :m_pDimensions(pDimensions) + ,m_pOffsets(pOffsets) + ,m_uNoOfElements(0) + ,m_pElements(pElements) + { + } + + + template + ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) + { + assert(uIndex + const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const + { + assert(uIndex + SubArray<1, ElementType>::SubArray(ElementType * pElements, uint32_t * pDimensions, uint32_t * /*pOffsets*/) + :m_pDimensions(pDimensions) + ,m_pElements(pElements) + { + } +}//namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxImpl/TypeDef.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/TypeDef.h similarity index 97% rename from library/PolyVoxCore/include/PolyVoxImpl/TypeDef.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/TypeDef.h index 5720b126..d02c62c0 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/TypeDef.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/TypeDef.h @@ -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 - #define polyvox_shared_ptr boost::shared_ptr - - #include - #define polyvox_function boost::function - - #include - #define polyvox_bind boost::bind - #define polyvox_placeholder_1 _1 - #define polyvox_placeholder_2 _2 - - #include - #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 - 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 - #include - #include - #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 + #define polyvox_shared_ptr boost::shared_ptr + + #include + #define polyvox_function boost::function + + #include + #define polyvox_bind boost::bind + #define polyvox_placeholder_1 _1 + #define polyvox_placeholder_2 _2 + + #include + #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 + 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 + #include + #include + #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 diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Utility.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Utility.h similarity index 94% rename from library/PolyVoxCore/include/PolyVoxImpl/Utility.h rename to library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Utility.h index d2ad594a..98f4e0a9 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Utility.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxImpl/Utility.h @@ -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 - -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 + +namespace PolyVox +{ + POLYVOX_API uint8_t logBase2(uint32_t uInput); + POLYVOX_API bool isPowerOf2(uint32_t uInput); +} + +#endif diff --git a/library/PolyVoxCore/source/GradientEstimators.cpp b/library/PolyVoxCore/source/GradientEstimators.cpp index 74417667..a998627b 100644 --- a/library/PolyVoxCore/source/GradientEstimators.cpp +++ b/library/PolyVoxCore/source/GradientEstimators.cpp @@ -21,7 +21,7 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/PolyVoxImpl/TypeDef.h" #include "PolyVoxCore/GradientEstimators.h" diff --git a/library/PolyVoxCore/source/PolyVoxImpl/MarchingCubesTables.cpp b/library/PolyVoxCore/source/PolyVoxImpl/MarchingCubesTables.cpp index c0e069f6..6c4318f2 100644 --- a/library/PolyVoxCore/source/PolyVoxImpl/MarchingCubesTables.cpp +++ b/library/PolyVoxCore/source/PolyVoxImpl/MarchingCubesTables.cpp @@ -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 { diff --git a/library/PolyVoxCore/source/PolyVoxImpl/RandomUnitVectors.cpp b/library/PolyVoxCore/source/PolyVoxImpl/RandomUnitVectors.cpp index ee8a6416..276eaf20 100644 --- a/library/PolyVoxCore/source/PolyVoxImpl/RandomUnitVectors.cpp +++ b/library/PolyVoxCore/source/PolyVoxImpl/RandomUnitVectors.cpp @@ -21,7 +21,7 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/RandomUnitVectors.h" +#include "PolyVoxCore/PolyVoxImpl/RandomUnitVectors.h" namespace PolyVox { diff --git a/library/PolyVoxCore/source/PolyVoxImpl/RandomVectors.cpp b/library/PolyVoxCore/source/PolyVoxImpl/RandomVectors.cpp index 532adf14..672e9920 100644 --- a/library/PolyVoxCore/source/PolyVoxImpl/RandomVectors.cpp +++ b/library/PolyVoxCore/source/PolyVoxImpl/RandomVectors.cpp @@ -21,7 +21,7 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/RandomVectors.h" +#include "PolyVoxCore/PolyVoxImpl/RandomVectors.h" namespace PolyVox { diff --git a/library/PolyVoxCore/source/PolyVoxImpl/Utility.cpp b/library/PolyVoxCore/source/PolyVoxImpl/Utility.cpp index 34cf5651..a99e87dd 100644 --- a/library/PolyVoxCore/source/PolyVoxImpl/Utility.cpp +++ b/library/PolyVoxCore/source/PolyVoxImpl/Utility.cpp @@ -21,7 +21,7 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Utility.h" +#include "PolyVoxCore/PolyVoxImpl/Utility.h" #include #include diff --git a/library/PolyVoxUtil/source/Dummy.cpp b/library/PolyVoxUtil/source/Dummy.cpp index b5bbf04f..6b81afcb 100644 --- a/library/PolyVoxUtil/source/Dummy.cpp +++ b/library/PolyVoxUtil/source/Dummy.cpp @@ -1,4 +1,4 @@ -#include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/PolyVoxImpl/TypeDef.h" namespace PolyVox { diff --git a/tests/TestRaycast.cpp b/tests/TestRaycast.cpp index 80e74b61..3e6faf70 100644 --- a/tests/TestRaycast.cpp +++ b/tests/TestRaycast.cpp @@ -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