From d06dbdf054a66330df8c745a36dac21bdfe1f5b3 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 24 Aug 2014 22:30:50 +0200 Subject: [PATCH] Bit renaming. Old Array class is gone, and is replaced by the Array2D class which has also been renamed to Array. --- library/PolyVoxCore/CMakeLists.txt | 8 - .../include/PolyVoxCore/AStarPathfinder.h | 2 - .../AmbientOcclusionCalculator.inl | 2 +- .../PolyVoxCore/include/PolyVoxCore/Array.h | 279 +++++++-------- .../PolyVoxCore/include/PolyVoxCore/Array.inl | 335 ------------------ .../include/PolyVoxCore/ArraySizes.h | 77 ---- .../PolyVoxCore/CubicSurfaceExtractor.inl | 14 +- .../include/PolyVoxCore/Impl/Array2D.h | 188 ---------- .../include/PolyVoxCore/Impl/ArraySizesImpl.h | 63 ---- .../PolyVoxCore/Impl/ArraySizesImpl.inl | 46 --- .../include/PolyVoxCore/Impl/SubArray.h | 90 ----- .../include/PolyVoxCore/Impl/SubArray.inl | 92 ----- .../MarchingCubesSurfaceExtractor.h | 2 +- library/PolyVoxCore/source/ArraySizes.cpp | 57 --- tests/TestAmbientOcclusionGenerator.cpp | 12 +- tests/TestArray.cpp | 41 +-- tests/TestArray.h | 1 - tests/TestVolumeSubclass.cpp | 4 +- 18 files changed, 155 insertions(+), 1158 deletions(-) delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Array.inl delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/ArraySizes.h delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/Array2D.h delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.h delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.inl delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.h delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl delete mode 100644 library/PolyVoxCore/source/ArraySizes.cpp diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index ed06c3c6..2f115630 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -24,7 +24,6 @@ PROJECT(PolyVoxCore) #Projects source files SET(CORE_SRC_FILES - source/ArraySizes.cpp source/AStarPathfinder.cpp source/Region.cpp ) @@ -34,8 +33,6 @@ SET(CORE_INC_FILES include/PolyVoxCore/AmbientOcclusionCalculator.h include/PolyVoxCore/AmbientOcclusionCalculator.inl include/PolyVoxCore/Array.h - include/PolyVoxCore/Array.inl - include/PolyVoxCore/ArraySizes.h include/PolyVoxCore/AStarPathfinder.h include/PolyVoxCore/AStarPathfinder.inl include/PolyVoxCore/BaseVolume.h @@ -108,9 +105,6 @@ SET(IMPL_SRC_FILES ) SET(IMPL_INC_FILES - include/PolyVoxCore/Impl/Array2D.h - include/PolyVoxCore/Impl/ArraySizesImpl.h - include/PolyVoxCore/Impl/ArraySizesImpl.inl include/PolyVoxCore/Impl/AStarPathfinderImpl.h include/PolyVoxCore/Impl/Config.h include/PolyVoxCore/Impl/ErrorHandling.h @@ -119,8 +113,6 @@ SET(IMPL_INC_FILES include/PolyVoxCore/Impl/MinizWrapper.h include/PolyVoxCore/Impl/RandomUnitVectors.h include/PolyVoxCore/Impl/RandomVectors.h - include/PolyVoxCore/Impl/SubArray.h - include/PolyVoxCore/Impl/SubArray.inl include/PolyVoxCore/Impl/Timer.h include/PolyVoxCore/Impl/TypeDef.h include/PolyVoxCore/Impl/Utility.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h index 7b86d8bc..88b22374 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h @@ -27,8 +27,6 @@ freely, subject to the following restrictions: #include "Impl/AStarPathfinderImpl.h" #include "Impl/TypeDef.h" -#include "PolyVoxCore/Array.h" - #include #include #include //For runtime_error diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index 82c266f3..c64c6d22 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -128,7 +128,7 @@ namespace PolyVox POLYVOX_ASSERT((fVisibility >= 0.0f) && (fVisibility <= 1.0f), "Visibility value out of range."); } - (*arrayResult)[z / iRatioZ][y / iRatioY][x / iRatioX] = static_cast(255.0f * fVisibility); + (*arrayResult)(z / iRatioZ, y / iRatioY, x / iRatioX) = static_cast(255.0f * fVisibility); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Array.h b/library/PolyVoxCore/include/PolyVoxCore/Array.h index 9ee935ba..4ec0f616 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Array.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Array.h @@ -1,5 +1,5 @@ /******************************************************************************* -Copyright (c) 2005-2009 David Williams +Copyright (c) 2005-20014 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 @@ -9,202 +9,185 @@ 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. +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. +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. +3. This notice may not be removed or altered from any source +distribution. *******************************************************************************/ #ifndef __PolyVox_Array_H__ #define __PolyVox_Array_H__ -#include "Impl/SubArray.h" +#include -#include "PolyVoxCore/ArraySizes.h" //Not strictly required, but convienient +#include namespace PolyVox { - ///Provides an efficient implementation of a multidimensional array. - //////////////////////////////////////////////////////////////////////////////// - /// While C++ provides one-dimensional arrays as a language feature, it does not - /// provide a simple and intuitive way of working with multidimensional arrays - /// whose sizes are specified at runtime. Such a construct is very useful within - /// the context of PolyVox, and this Array class provides such functionality - /// implemented via templates and partial specialisation. - /// - /// The following code snippet illustrates the basic usage of the class by writing - /// a different value into each element: - /// - /// \code - /// int width = 5; - /// int height = 10; - /// int depth = 20; - /// - /// //Creates a 3D array of integers with dimensions 5x10x20 - /// Array<3, int> myArray(ArraySizes(width)(height)(depth)); - /// - /// int ct = 1; - /// for(int z = 0; z < depth; z++) - /// { - /// for(int y = 0; y < height; y++) - /// { - /// for(int x = 0; x < width; x++) - /// { - /// myArray[x][y][z] = ct; - /// ct++; - /// } - /// } - /// } - /// \endcode - /// - /// Although the constructor and resize() functions both take the required dimensions - /// as an array of ints, note that the ArraySizes class can be used to build this - /// inline. This is a more convienient way of specifying these dimensions. - /// - /// Note also that this class has a private assignment operator and copy constructor - /// in order to prevent copying. This is because a deep copy is a potentially slow - /// operation and can often be performed inadvertently by functions such as std::swap, - /// while a shallow copy introduces confusion over memory ownership. - //////////////////////////////////////////////////////////////////////////////// template class Array { public: - ///Constructor - Array(); - ///Constructor - Array(const uint32_t (&pDimensions)[noOfDims]); - ///Destructor - ~Array(); - ///Subarray access - SubArray operator[](uint32_t uIndex); - ///Subarray access - const SubArray operator[](uint32_t uIndex) const; + Array(uint32_t width) + :m_pElements(0) + { + static_assert(noOfDims == 1, "This constructor can only be used with a one-dimensional array"); - ///Gets the total number of elements in this array - uint32_t getNoOfElements(void) const; - ///Gets a pointer to the first element of the array - ElementType* getRawData(void) const; + m_uDimensions[0] = width; - ///Resize the array to the specified dimensions - void resize(const uint32_t (&pDimensions)[noOfDims]); - ///Swaps the contents of this array with the one specified - void swap(Array& rhs); - ///Get the size of the Array along the specified dimension - uint32_t getDimension(uint32_t uDimension); + initialize(); + } + + Array(uint32_t width, uint32_t height) + :m_pElements(0) + { + static_assert(noOfDims == 2, "This constructor can only be used with a two-dimensional array"); + + m_uDimensions[0] = width; + m_uDimensions[1] = height; + + initialize(); + } + + Array(uint32_t width, uint32_t height, uint32_t depth) + :m_pElements(0) + { + static_assert(noOfDims == 3, "This constructor can only be used with a three-dimensional array"); + + m_uDimensions[0] = width; + m_uDimensions[1] = height; + m_uDimensions[2] = depth; + + initialize(); + } + + // These are deleted to avoid accidental copying. + Array(const Array&) = delete; + Array& operator=(const Array&) = delete; + + ~Array() + { + delete[] m_pElements; + } + + ElementType& operator()(uint32_t x) const + { + static_assert(noOfDims == 1, "This accessor can only be used with a one-dimensional array"); + POLYVOX_ASSERT(x < m_uDimensions[0], "Array access is out-of-range."); + return m_pElements[x]; + } + + ElementType& operator()(uint32_t x, uint32_t y) const + { + static_assert(noOfDims == 2, "This accessor can only be used with a two-dimensional array"); + POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1], "Array access is out-of-range."); + return m_pElements[y * m_uDimensions[0] + x]; + } + + ElementType& operator()(uint32_t x, uint32_t y, uint32_t z) const + { + static_assert(noOfDims == 3, "This accessor can only be used with a three-dimensional array"); + POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1] && z < m_uDimensions[2], "Array access is out-of-range."); + return m_pElements[z * m_uDimensions[1] * m_uDimensions[1] + y * m_uDimensions[0] + x]; + } + + uint32_t getDimension(uint32_t dimension) + { + return m_uDimensions[dimension]; + } + + ElementType* getRawData() + { + return m_pElements; + } + + uint32_t getNoOfElements() + { + return m_uNoOfElements; + } + + void swap(Array& other) + { + ElementType* temp = other.m_pElements; + other.m_pElements = m_pElements; + m_pElements = temp; + } private: - Array(const Array& rhs); - Array& operator=(const Array& rhs); + void initialize(void) + { + // Calculate the total number of elements in the array. + m_uNoOfElements = 1; + for (uint32_t i = 0; i < noOfDims; i++) + { + m_uNoOfElements *= m_uDimensions[i]; + } + m_pElements = new ElementType[m_uNoOfElements]; + } - void deallocate(void); - - uint32_t * m_pDimensions; - uint32_t * m_pOffsets; + uint32_t m_uDimensions[noOfDims]; uint32_t m_uNoOfElements; - ElementType * m_pElements; + ElementType* m_pElements; }; - template - class Array<1, ElementType> - { - public: - Array<1, ElementType>(); - - Array<1, ElementType>(const uint32_t (&pDimensions)[1]); - - ~Array<1, ElementType>(); - - ElementType& operator[] (uint32_t uIndex); - - const ElementType& operator[] (uint32_t uIndex) const; - - uint32_t getNoOfElements(void) const; - - ElementType* getRawData(void) const; - - void resize(const uint32_t (&pDimensions)[1]); - - void swap(Array<1, ElementType>& rhs); - - private: - Array<1, ElementType>(const Array<1, ElementType>& rhs); - - Array<1, ElementType>& operator=(const Array<1, ElementType>& rhs); - - void deallocate(void); - - uint32_t * m_pDimensions; - ElementType * m_pElements; - }; - - template - class Array<0, ElementType> - { - //Zero dimensional array is meaningless. - }; - - //Some handy typedefs ///A 1D Array of floats. - /*typedef Array<1,float> Array1DFloat; + typedef Array<1, float> Array1DFloat; ///A 1D Array of doubles. - typedef Array<1,double> Array1DDouble; + typedef Array<1, double> Array1DDouble; ///A 1D Array of signed 8-bit values. - typedef Array<1,int8_t> Array1DInt8; + typedef Array<1, int8_t> Array1DInt8; ///A 1D Array of unsigned 8-bit values. - typedef Array<1,uint8_t> Array1DUint8; + typedef Array<1, uint8_t> Array1DUint8; ///A 1D Array of signed 16-bit values. - typedef Array<1,int16_t> Array1DInt16; + typedef Array<1, int16_t> Array1DInt16; ///A 1D Array of unsigned 16-bit values. - typedef Array<1,uint16_t> Array1DUint16; + typedef Array<1, uint16_t> Array1DUint16; ///A 1D Array of signed 32-bit values. - typedef Array<1,int32_t> Array1DInt32; + typedef Array<1, int32_t> Array1DInt32; ///A 1D Array of unsigned 32-bit values. - typedef Array<1,uint32_t> Array1DUint32;*/ + typedef Array<1, uint32_t> Array1DUint32; ///A 2D Array of floats. - /*typedef Array<2,float> Array2DFloat; + typedef Array<2, float> Array2DFloat; ///A 2D Array of doubles. - typedef Array<2,double> Array2DDouble; + typedef Array<2, double> Array2DDouble; ///A 2D Array of signed 8-bit values. - typedef Array<2,int8_t> Array2DInt8; + typedef Array<2, int8_t> Array2DInt8; ///A 2D Array of unsigned 8-bit values. - typedef Array<2,uint8_t> Array2DUint8; + typedef Array<2, uint8_t> Array2DUint8; ///A 2D Array of signed 16-bit values. - typedef Array<2,int16_t> Array2DInt16; + typedef Array<2, int16_t> Array2DInt16; ///A 2D Array of unsigned 16-bit values. - typedef Array<2,uint16_t> Array2DUint16; + typedef Array<2, uint16_t> Array2DUint16; ///A 2D Array of signed 32-bit values. - typedef Array<2,int32_t> Array2DInt32; + typedef Array<2, int32_t> Array2DInt32; ///A 2D Array of unsigned 32-bit values. - typedef Array<2,uint32_t> Array2DUint32;*/ + typedef Array<2, uint32_t> Array2DUint32; ///A 3D Array of floats. - /*typedef Array<3,float> Array3DFloat; + typedef Array<3, float> Array3DFloat; ///A 3D Array of doubles. - typedef Array<3,double> Array3DDouble; + typedef Array<3, double> Array3DDouble; ///A 3D Array of signed 8-bit values. - typedef Array<3,int8_t> Array3DInt8; + typedef Array<3, int8_t> Array3DInt8; ///A 3D Array of unsigned 8-bit values. - typedef Array<3,uint8_t> Array3DUint8; + typedef Array<3, uint8_t> Array3DUint8; ///A 3D Array of signed 16-bit values. - typedef Array<3,int16_t> Array3DInt16; + typedef Array<3, int16_t> Array3DInt16; ///A 3D Array of unsigned 16-bit values. - typedef Array<3,uint16_t> Array3DUint16; + typedef Array<3, uint16_t> Array3DUint16; ///A 3D Array of signed 32-bit values. - typedef Array<3,int32_t> Array3DInt32; + typedef Array<3, int32_t> Array3DInt32; ///A 3D Array of unsigned 32-bit values. - typedef Array<3,uint32_t> Array3DUint32;*/ -}//namespace PolyVox + typedef Array<3, uint32_t> Array3DUint32; +} -#include "PolyVoxCore/Array.inl" - -#endif +#endif //__PolyVox_Array_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/Array.inl b/library/PolyVoxCore/include/PolyVoxCore/Array.inl deleted file mode 100644 index 53f428ac..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Array.inl +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* -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. -*******************************************************************************/ - -namespace PolyVox -{ - //////////////////////////////////////////////////////////////////////////////// - /// Creates an empty array with no elements. You will have to call resize() on this - /// array before it can be used. - //////////////////////////////////////////////////////////////////////////////// - template - Array::Array() - :m_pDimensions(0) - ,m_pOffsets(0) - ,m_uNoOfElements(0) - ,m_pElements(0) - { - } - - //////////////////////////////////////////////////////////////////////////////// - /// Creates an array with the specified dimensions. - /// \param pDimensions The dimensions of the array. You can also use the ArraySizes - /// class to construct this more easily. - /// \sa ArraySizes - //////////////////////////////////////////////////////////////////////////////// - template - Array::Array(const uint32_t (&pDimensions)[noOfDims]) - :m_pDimensions(0) - ,m_pOffsets(0) - ,m_uNoOfElements(0) - ,m_pElements(0) - { - resize(pDimensions); - } - - //////////////////////////////////////////////////////////////////////////////// - /// Destroys the array and releases all owned memory. - //////////////////////////////////////////////////////////////////////////////// - template - Array::~Array() - { - deallocate(); - } - - //////////////////////////////////////////////////////////////////////////////// - /// An N-dimensional array can be conceptually consists of N subarrays each of which - /// has N-1 dimensions. For example, a 3D array conceptually consists of three 2D - /// arrays. This operator is used to access the subarray at the specified index. - /// Crucially, the subarray defines a similar operator allowing them to be chained - /// together to convieniently access a particular element. - /// \param uIndex The zero-based index of the subarray to retrieve. - /// \return The requested SubArray - //////////////////////////////////////////////////////////////////////////////// - template - SubArray Array::operator[](uint32_t uIndex) - { - POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); - - return - SubArray(&m_pElements[uIndex*m_pOffsets[0]], - m_pDimensions+1, m_pOffsets+1); - } - - //////////////////////////////////////////////////////////////////////////////// - /// An N-dimensional array can be conceptually consists of N subarrays each of which - /// has N-1 dimensions. For example, a 3D array conceptually consists of three 2D - /// arrays. This operator is used to access the subarray at the specified index. - /// Crucially, the subarray defines a similar operator allowing them to be chained - /// together to convieniently access a particular element. - /// \param uIndex The zero-based index of the subarray to retrieve. - /// \return The requested SubArray - //////////////////////////////////////////////////////////////////////////////// - template - const SubArray Array::operator[](uint32_t uIndex) const - { - POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); - - return - SubArray(&m_pElements[uIndex*m_pOffsets[0]], - m_pDimensions+1, m_pOffsets+1); - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The number of elements in the array. - /// \sa getRawData() - //////////////////////////////////////////////////////////////////////////////// - template - uint32_t Array::getNoOfElements(void) const - { - return m_uNoOfElements; - } - - //////////////////////////////////////////////////////////////////////////////// - /// Sometimes it is useful to directly manipulate the underlying array without - /// going through this classes interface. Although this does not honour the principle - /// of encapsulation it can be done safely if you are careful and can sometimes be - /// useful. Use getNoOfElements() to determine how far you can safely write. - /// \return A pointer to the first element of the array - /// \sa getNoOfElements() - //////////////////////////////////////////////////////////////////////////////// - template - ElementType* Array::getRawData(void) const - { - return m_pElements; - } - - //////////////////////////////////////////////////////////////////////////////// - /// Please note that the existing contents of the array will be lost. - /// \param pDimensions The new dimensions of the array. You can also use the - /// ArraySizes class to specify this more easily. - /// \sa ArraySizes - //////////////////////////////////////////////////////////////////////////////// - template - void Array::resize(const uint32_t (&pDimensions)[noOfDims]) - { - deallocate(); - - m_pDimensions = new uint32_t[noOfDims]; - m_pOffsets = new uint32_t[noOfDims]; - - // Calculate all the information you need to use the array - m_uNoOfElements = 1; - for (uint32_t i = 0; ii; k--) - { - m_pOffsets[i] *= pDimensions[k]; - } - } - // Allocate new elements, let exception propagate - m_pElements = new ElementType[m_uNoOfElements]; - } - - //////////////////////////////////////////////////////////////////////////////// - /// Because this class does not have a public assignment operator or copy constructor - /// it cannot be used with the STL swap() function. This function provides an efficient - /// implementation of that feature. - /// \param rhs The array to swap this object with. - //////////////////////////////////////////////////////////////////////////////// - template - void Array::swap(Array& rhs) - { - //Implement this function without temporary 'Array' - //objects, as the destructors will free the memory... - uint32_t* m_pTempDimensions = m_pDimensions; - uint32_t* m_pTempOffsets = m_pOffsets; - uint32_t m_uTempNoOfElements = m_uNoOfElements; - ElementType* m_pTempElements = m_pElements; - - m_pDimensions = rhs.m_pDimensions; - m_pOffsets = rhs.m_pOffsets; - m_uNoOfElements = rhs.m_uNoOfElements; - m_pElements = rhs.m_pElements; - - rhs.m_pDimensions = m_pTempDimensions; - rhs.m_pOffsets = m_pTempOffsets; - rhs.m_uNoOfElements = m_uTempNoOfElements; - rhs.m_pElements = m_pTempElements; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \param uDimension The dimension to get the size of. - //////////////////////////////////////////////////////////////////////////////// - template - uint32_t Array::getDimension(uint32_t uDimension) - { - POLYVOX_THROW_IF(uDimension >= noOfDims, std::out_of_range, "Array dimension out of range"); - - return m_pDimensions[uDimension]; - } - - template - Array::Array(const Array& rhs) - :m_pElements(0) - ,m_pDimensions(0) - ,m_pOffsets(0) - ,m_uNoOfElements(0) - { - //Not implemented - POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); - } - - template - Array& Array::operator=(const Array& rhs) - { - //Not implemented - POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); - - return *this; - } - - template - void Array::deallocate(void) - { - delete[] m_pDimensions; - m_pDimensions = 0; - delete[] m_pOffsets; - m_pOffsets = 0; - delete[] m_pElements; - m_pElements = 0; - - m_uNoOfElements = 0; - } - - //****************************************************************************// - // One dimensional specialisation begins here // - //****************************************************************************// - - template - Array<1, ElementType>::Array() - : m_pElements(0) - ,m_pDimensions(0) - { - } - - template - Array<1, ElementType>::Array(const uint32_t (&pDimensions)[1]) - : m_pElements(0) - ,m_pDimensions(0) - { - resize(pDimensions); - } - - template - Array<1, ElementType>::~Array() - { - deallocate(); - } - - template - ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) - { - POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); - - return m_pElements[uIndex]; - } - - template - const ElementType& Array<1, ElementType>::operator[] (uint32_t uIndex) const - { - POLYVOX_THROW_IF(uIndex >= m_pDimensions[0], std::out_of_range, "Array index out of range"); - - return m_pElements[uIndex]; - } - - template - uint32_t Array<1, ElementType>::getNoOfElements(void) const - { - return m_pDimensions[0]; - } - - template - ElementType* Array<1, ElementType>::getRawData(void) const - { - return m_pElements; - } - - template - void Array<1, ElementType>::resize(const uint32_t (&pDimensions)[1]) - { - deallocate(); - - m_pDimensions = new uint32_t[1]; - m_pDimensions[0] = pDimensions[0]; - - // Allocate new elements, let exception propagate - m_pElements = new ElementType[m_pDimensions[0]]; - } - - template - void Array<1, ElementType>::swap(Array<1, ElementType>& rhs) - { - //Implement this function without temporary 'Array' - //objects, as the destructors will free the memory... - uint32_t* m_pTempDimensions = m_pDimensions; - ElementType* m_pTempElements = m_pElements; - - m_pDimensions = rhs.m_pDimensions; - m_pElements = rhs.m_pElements; - - rhs.m_pDimensions = m_pTempDimensions; - rhs.m_pElements = m_pTempElements; - } - - template - Array<1, ElementType>::Array(const Array<1, ElementType>& rhs) - : m_pElements(0) - ,m_pDimensions(0) - { - //Not implemented - POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); - } - - template - Array<1, ElementType>& Array<1, ElementType>::operator=(const Array<1, ElementType>& rhs) - { - //Not implemented - POLYVOX_THROW(not_implemented, "This function is not implemented and should never be called!"); - - return *this; - } - - template - void Array<1, ElementType>::deallocate(void) - { - delete[] m_pDimensions; - m_pDimensions = 0; - delete[] m_pElements; - m_pElements = 0; - } -}//namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/ArraySizes.h b/library/PolyVoxCore/include/PolyVoxCore/ArraySizes.h deleted file mode 100644 index 93bd6d0c..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/ArraySizes.h +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* -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_ArraySizes_H__ -#define __PolyVox_ArraySizes_H__ - -#include "Impl/ArraySizesImpl.h" -#include "Impl/TypeDef.h" - -namespace PolyVox -{ - ///The ArraySizes class provide a convienient way to specify the dimensions of an Array. - //////////////////////////////////////////////////////////////////////////////// - /// The Array class requires an array of integers to be passed to the constructor - /// to specify the dimensions of the Array to be built. C++ does not allow this to - /// be done in place, and so it typically requires an extra line of code - something - /// like this: - /// - /// \code - /// uint32_t dimensions[3] = {10, 20, 30}; // Array dimensions - /// Array<3,float> array(dimensions); - /// \endcode - /// - /// The ArraySizes class can be constructed in place, and also provides implicit - /// conversion to an array of integers. Hence it is now possible to declare the - /// above Array as follows: - /// - /// \code - /// Array<3,float> array(ArraySizes(10)(20)(30)); - /// \endcode - /// - /// Usage of this class is therefore very simple, although the template code - /// behind it may appear complex. For reference, it is based upon the article here: - /// http://www.drdobbs.com/cpp/184401319/ - //////////////////////////////////////////////////////////////////////////////// - class POLYVOX_API ArraySizes - { - typedef const uint32_t (&UIntArray1)[1]; - - public: - /// Constructor - explicit ArraySizes(uint32_t uSize); - - /// Duplicates this object but with an extra dimension - ArraySizesImpl<2> operator () (uint32_t uSize); - - /// Converts this object to an array of integers - operator UIntArray1 () const; - - private: - // This class is only one dimensional. Higher dimensions - // are implemented via the ArraySizesImpl class. - uint32_t m_pSizes[1]; - }; -}//namespace PolyVox - -#endif //__PolyVox_ArraySizes_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index edf8ea7a..bcf4247d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -43,6 +43,8 @@ namespace PolyVox ,m_bMergeQuads(bMergeQuads) ,m_eWrapMode(eWrapMode) ,m_tBorderValue(tBorderValue) + ,m_previousSliceVertices(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2, m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2, MaxVerticesPerPosition) + ,m_currentSliceVertices(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2, m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2, MaxVerticesPerPosition) { m_funcIsQuadNeededCallback = isQuadNeeded; @@ -59,12 +61,12 @@ namespace PolyVox Timer timer; m_meshCurrent->clear(); - uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2; - uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2; + //uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2; + //uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2; - uint32_t arraySize[3]= {uArrayWidth, uArrayHeight, MaxVerticesPerPosition}; - m_previousSliceVertices.resize(arraySize); - m_currentSliceVertices.resize(arraySize); + //uint32_t arraySize[3]= {uArrayWidth, uArrayHeight, MaxVerticesPerPosition}; + //m_previousSliceVertices.resize(arraySize); + //m_currentSliceVertices.resize(arraySize); memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial)); memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial)); @@ -209,7 +211,7 @@ namespace PolyVox { for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++) { - IndexAndMaterial& rEntry = existingVertices[uX][uY][ct]; + IndexAndMaterial& rEntry = existingVertices(uX, uY, ct); if(rEntry.iIndex == -1) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Array2D.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Array2D.h deleted file mode 100644 index 6eaeace4..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Array2D.h +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* -Copyright (c) 2005-20014 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_Array2D_H__ -#define __PolyVox_Array2D_H__ - -#include - -#include - -namespace PolyVox -{ - template - class Array2D - { - public: - - Array2D(uint32_t width) - :m_pElements(0) - { - static_assert(noOfDims == 1, "This constructor can only be used with a one-dimensional array"); - - m_uDimensions[0] = width; - - initialize(); - } - - Array2D(uint32_t width, uint32_t height) - :m_pElements(0) - { - static_assert(noOfDims == 2, "This constructor can only be used with a two-dimensional array"); - - m_uDimensions[0] = width; - m_uDimensions[1] = height; - - initialize(); - } - - Array2D(uint32_t width, uint32_t height, uint32_t depth) - :m_pElements(0) - { - static_assert(noOfDims == 3, "This constructor can only be used with a three-dimensional array"); - - m_uDimensions[0] = width; - m_uDimensions[1] = height; - m_uDimensions[2] = depth; - - initialize(); - } - - // These are deleted to avoid accidental copying. - Array2D(const Array2D&) = delete; - Array2D& operator=(const Array2D&) = delete; - - ~Array2D() - { - delete[] m_pElements; - } - - ElementType& operator()(uint32_t x) const - { - static_assert(noOfDims == 1, "This accessor can only be used with a one-dimensional array"); - POLYVOX_ASSERT(x < m_uDimensions[0], "Array access is out-of-range."); - return m_pElements[x]; - } - - ElementType& operator()(uint32_t x, uint32_t y) const - { - static_assert(noOfDims == 2, "This accessor can only be used with a two-dimensional array"); - POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1], "Array access is out-of-range."); - return m_pElements[y * m_uDimensions[0] + x]; - } - - ElementType& operator()(uint32_t x, uint32_t y, uint32_t z) const - { - static_assert(noOfDims == 3, "This accessor can only be used with a three-dimensional array"); - POLYVOX_ASSERT(x < m_uDimensions[0] && y < m_uDimensions[1] && z < m_uDimensions[2], "Array access is out-of-range."); - return m_pElements[z * m_uDimensions[1] * m_uDimensions[1] + y * m_uDimensions[0] + x]; - } - - ElementType* getRawData() - { - return m_pElements; - } - - uint32_t getNoOfElements() - { - return m_uNoOfElements; - } - - void swap(Array2D& other) - { - ElementType* temp = other.m_pElements; - other.m_pElements = m_pElements; - m_pElements = temp; - } - - private: - - void initialize(void) - { - // Calculate the total number of elements in the array. - m_uNoOfElements = 1; - for (uint32_t i = 0; i < noOfDims; i++) - { - m_uNoOfElements *= m_uDimensions[i]; - } - m_pElements = new ElementType[m_uNoOfElements]; - } - - uint32_t m_uDimensions[noOfDims]; - uint32_t m_uNoOfElements; - ElementType* m_pElements; - }; - - ///A 1D Array of floats. - typedef Array2D<1, float> Array1DFloat; - ///A 1D Array of doubles. - typedef Array2D<1, double> Array1DDouble; - ///A 1D Array of signed 8-bit values. - typedef Array2D<1, int8_t> Array1DInt8; - ///A 1D Array of unsigned 8-bit values. - typedef Array2D<1, uint8_t> Array1DUint8; - ///A 1D Array of signed 16-bit values. - typedef Array2D<1, int16_t> Array1DInt16; - ///A 1D Array of unsigned 16-bit values. - typedef Array2D<1, uint16_t> Array1DUint16; - ///A 1D Array of signed 32-bit values. - typedef Array2D<1, int32_t> Array1DInt32; - ///A 1D Array of unsigned 32-bit values. - typedef Array2D<1, uint32_t> Array1DUint32; - - ///A 2D Array of floats. - typedef Array2D<2, float> Array2DFloat; - ///A 2D Array of doubles. - typedef Array2D<2, double> Array2DDouble; - ///A 2D Array of signed 8-bit values. - typedef Array2D<2, int8_t> Array2DInt8; - ///A 2D Array of unsigned 8-bit values. - typedef Array2D<2, uint8_t> Array2DUint8; - ///A 2D Array of signed 16-bit values. - typedef Array2D<2, int16_t> Array2DInt16; - ///A 2D Array of unsigned 16-bit values. - typedef Array2D<2, uint16_t> Array2DUint16; - ///A 2D Array of signed 32-bit values. - typedef Array2D<2, int32_t> Array2DInt32; - ///A 2D Array of unsigned 32-bit values. - typedef Array2D<2, uint32_t> Array2DUint32; - - ///A 3D Array of floats. - typedef Array2D<3, float> Array3DFloat; - ///A 3D Array of doubles. - typedef Array2D<3, double> Array3DDouble; - ///A 3D Array of signed 8-bit values. - typedef Array2D<3, int8_t> Array3DInt8; - ///A 3D Array of unsigned 8-bit values. - typedef Array2D<3, uint8_t> Array3DUint8; - ///A 3D Array of signed 16-bit values. - typedef Array2D<3, int16_t> Array3DInt16; - ///A 3D Array of unsigned 16-bit values. - typedef Array2D<3, uint16_t> Array3DUint16; - ///A 3D Array of signed 32-bit values. - typedef Array2D<3, int32_t> Array3DInt32; - ///A 3D Array of unsigned 32-bit values. - typedef Array2D<3, uint32_t> Array3DUint32; -} - -#endif //__PolyVox_Array2D_H__ \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.h deleted file mode 100644 index 3a65c217..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.h +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* -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 "PolyVoxCore/Impl/TypeDef.h" - -#include - -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 "PolyVoxCore/Impl/ArraySizesImpl.inl" - -#endif //__PolyVox_ArraySizesImpl_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.inl deleted file mode 100644 index 13836476..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ArraySizesImpl.inl +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* -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/PolyVoxCore/Impl/SubArray.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.h deleted file mode 100644 index 3e70a02c..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.h +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* -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 "PolyVoxCore/Impl/TypeDef.h" - -#include - -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 "PolyVoxCore/Impl/SubArray.inl" - -#endif //__PolyVox_SubArray_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl deleted file mode 100644 index 81c526c3..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/SubArray.inl +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* -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 "PolyVoxCore/Impl/ErrorHandling.h" - -namespace PolyVox -{ - template - SubArray SubArray::operator[](uint32_t uIndex) - { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } - - return - SubArray(&m_pElements[uIndex*m_pOffsets[0]], - m_pDimensions+1, m_pOffsets+1); - } - - template - const SubArray SubArray::operator[](uint32_t uIndex) const - { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } - - return - SubArray(&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) - { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } - - return m_pElements[uIndex]; - } - - template - const ElementType& SubArray<1, ElementType>::operator[] (uint32_t uIndex) const - { - if(uIndex >= m_pDimensions[0]) - { - POLYVOX_THROW(std::out_of_range, "Array index out of range"); - } - - return m_pElements[uIndex]; - } - - template - 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/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index 62ccbff6..cf42800e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -27,7 +27,7 @@ freely, subject to the following restrictions: #include "Impl/MarchingCubesTables.h" #include "Impl/TypeDef.h" -#include "PolyVoxCore/Impl/Array2D.h" +#include "PolyVoxCore/Array.h" #include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/Mesh.h" #include "PolyVoxCore/DefaultMarchingCubesController.h" diff --git a/library/PolyVoxCore/source/ArraySizes.cpp b/library/PolyVoxCore/source/ArraySizes.cpp deleted file mode 100644 index 52755a73..00000000 --- a/library/PolyVoxCore/source/ArraySizes.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* -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 "PolyVoxCore/ArraySizes.h" - -#include - -namespace PolyVox -{ - /** - \param uSize The size of the first dimension. - */ - ArraySizes::ArraySizes(uint32_t uSize) - { - m_pSizes[0]=uSize; - } - - /** - This class only directly implements one dimensional sizes. Higher numbers - of dimensions are implemented via the ArraySisesImpl class. This function - create an object of the next dimensionality up. - \param uSize The size of the next dimension. - \return A higher dimension version of this class. - */ - ArraySizesImpl<2> ArraySizes::operator () (uint32_t uSize) - { - return ArraySizesImpl<2>(m_pSizes, uSize); - } - - /** - \return The array of integers corresponding to this object. - */ - ArraySizes::operator UIntArray1 () const - { - return m_pSizes; - } -} diff --git a/tests/TestAmbientOcclusionGenerator.cpp b/tests/TestAmbientOcclusionGenerator.cpp index 667acce4..cb077ec2 100644 --- a/tests/TestAmbientOcclusionGenerator.cpp +++ b/tests/TestAmbientOcclusionGenerator.cpp @@ -68,7 +68,7 @@ void TestAmbientOcclusionGenerator::testExecute() //Create an array to store the result. Array can be smaller than the volume by an integer amount. const int32_t g_uArraySideLength = g_uVolumeSideLength / 2; - Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength)); + Array<3, uint8_t> ambientOcclusionResult(g_uArraySideLength, g_uArraySideLength, g_uArraySideLength); // Calculate the ambient occlusion values IsVoxelTransparent isVoxelTransparent; @@ -78,11 +78,11 @@ void TestAmbientOcclusionGenerator::testExecute() //Check the results by sampling along a line though the centre of the volume. Because //of the two walls we added, samples in the middle are darker than those at the edge. - QCOMPARE(static_cast(ambientOcclusionResult[16][ 0][16]), 178); - QCOMPARE(static_cast(ambientOcclusionResult[16][ 8][16]), 109); - QCOMPARE(static_cast(ambientOcclusionResult[16][16][16]), 103); - QCOMPARE(static_cast(ambientOcclusionResult[16][24][16]), 123); - QCOMPARE(static_cast(ambientOcclusionResult[16][31][16]), 173); + QCOMPARE(static_cast(ambientOcclusionResult(16, 0, 16)), 178); + QCOMPARE(static_cast(ambientOcclusionResult(16, 8, 16)), 109); + QCOMPARE(static_cast(ambientOcclusionResult(16, 16, 16)), 103); + QCOMPARE(static_cast(ambientOcclusionResult(16, 24, 16)), 123); + QCOMPARE(static_cast(ambientOcclusionResult(16, 31, 16)), 173); //Just run a quick test to make sure that it compiles when taking a function pointer calculateAmbientOcclusion(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 8, &isVoxelTransparentFunction); diff --git a/tests/TestArray.cpp b/tests/TestArray.cpp index 84d4bf14..359a2abf 100644 --- a/tests/TestArray.cpp +++ b/tests/TestArray.cpp @@ -25,8 +25,6 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Array.h" -#include "PolyVoxCore/Impl/Array2D.h" - #include using namespace PolyVox; @@ -64,34 +62,7 @@ void TestArray::testPolyVoxArraySpeed() const int height = 32; const int depth = 32; - Array<3, int> polyvoxArray(ArraySizes(width)(height)(depth)); - - QBENCHMARK - { - int ct = 1; - int expectedTotal = 0; - for (int z = 0; z < depth; z++) - { - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - polyvoxArray[x][y][z] = ct; - expectedTotal += polyvoxArray[x][y][z]; - ct++; - } - } - } - } -} - -void TestArray::testPolyVoxArray2DSpeed() -{ - const int width = 32; - const int height = 32; - const int depth = 32; - - Array2D<3, int> polyvoxArray(width, height, depth); + Array<3, int> polyvoxArray(width, height, depth); QBENCHMARK { @@ -118,7 +89,7 @@ void TestArray::testReadWrite() int height = 10; int depth = 20; - Array<3, int> myArray(ArraySizes(width)(height)(depth)); + Array<3, int> myArray(width, height, depth); int ct = 1; int expectedTotal = 0; @@ -128,8 +99,8 @@ void TestArray::testReadWrite() { for(int x = 0; x < width; x++) { - myArray[x][y][z] = ct; - expectedTotal += myArray[x][y][z]; + myArray(x, y, z) = ct; + expectedTotal += myArray(x, y, z); ct++; } } @@ -143,8 +114,8 @@ void TestArray::testReadWrite() { for(int x = 0; x < width; x++) { - QCOMPARE(myArray[x][y][z], ct); - total += myArray[x][y][z]; + QCOMPARE(myArray(x, y, z), ct); + total += myArray(x, y, z); ct++; } } diff --git a/tests/TestArray.h b/tests/TestArray.h index bd5425a6..2d3e5951 100644 --- a/tests/TestArray.h +++ b/tests/TestArray.h @@ -33,7 +33,6 @@ class TestArray: public QObject private slots: void testCArraySpeed(); void testPolyVoxArraySpeed(); - void testPolyVoxArray2DSpeed(); void testReadWrite(); }; diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index b8848c11..1db0065e 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -23,7 +23,7 @@ freely, subject to the following restrictions: #include "TestVolumeSubclass.h" -#include "PolyVoxCore/Impl/Array2D.h" +#include "PolyVoxCore/Array.h" #include "PolyVoxCore/BaseVolume.h" #include "PolyVoxCore/CubicSurfaceExtractor.h" @@ -167,7 +167,7 @@ public: //void resize(const Region& regValidRegion); private: - Array2D<3, VoxelType> mVolumeData; + Array<3, VoxelType> mVolumeData; }; void TestVolumeSubclass::testExtractSurface()