Split Block, CompressedBlock and UncompressedBlock into separate files. It's tidier, and maybe better for SWIG?

This commit is contained in:
David Williams 2013-08-01 15:32:12 +02:00
parent 6f17e0faa6
commit dcf86a905c
8 changed files with 227 additions and 148 deletions

View File

@ -49,8 +49,9 @@ SET(CORE_INC_FILES
include/PolyVoxCore/BaseVolume.inl
include/PolyVoxCore/BaseVolumeSampler.inl
include/PolyVoxCore/Block.h
include/PolyVoxCore/Block.inl
include/PolyVoxCore/BlockCompressor.h
include/PolyVoxCore/CompressedBlock.h
include/PolyVoxCore/CompressedBlock.inl
include/PolyVoxCore/Compressor.h
include/PolyVoxCore/CubicSurfaceExtractor.h
include/PolyVoxCore/CubicSurfaceExtractor.inl
@ -95,6 +96,8 @@ SET(CORE_INC_FILES
include/PolyVoxCore/SimpleVolumeSampler.inl
include/PolyVoxCore/SurfaceMesh.h
include/PolyVoxCore/SurfaceMesh.inl
include/PolyVoxCore/UncompressedBlock.h
include/PolyVoxCore/UncompressedBlock.inl
include/PolyVoxCore/Vector.h
include/PolyVoxCore/Vector.inl
include/PolyVoxCore/VertexTypes.h

View File

@ -1,5 +1,5 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
Copyright (c) 2005-2013 David Williams and Matthew 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
@ -61,71 +61,6 @@ namespace PolyVox
/// Private assignment operator to prevent accisdental copying
Block& operator=(const Block& /*rhs*/) {};
};
template <typename VoxelType>
class CompressedBlock : public Block<VoxelType>
{
friend class LargeVolume<VoxelType>;
public:
CompressedBlock();
~CompressedBlock();
const uint8_t* getData(void) const;
uint32_t getDataSizeInBytes(void) const;
void setData(const uint8_t* const pData, uint32_t uDataSizeInBytes);
private:
/// Private copy constructor to prevent accisdental copying
CompressedBlock(const CompressedBlock& /*rhs*/) {};
/// Private assignment operator to prevent accisdental copying
CompressedBlock& operator=(const CompressedBlock& /*rhs*/) {};
// Made this private to avoid any confusion with getDataSizeInBytes().
// Users shouldn't really need this for CompressedBlock anyway.
uint32_t calculateSizeInBytes(void);
uint8_t* m_pData;
uint32_t m_uDataSizeInBytes;
};
template <typename VoxelType>
class UncompressedBlock : public Block<VoxelType>
{
friend class LargeVolume<VoxelType>;
public:
UncompressedBlock(uint16_t uSideLength);
~UncompressedBlock();
VoxelType* getData(void) const;
uint32_t getDataSizeInBytes(void) const;
VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
VoxelType getVoxel(const Vector3DUint16& v3dPos) const;
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
private:
/// Private copy constructor to prevent accisdental copying
UncompressedBlock(const UncompressedBlock& /*rhs*/) {};
/// Private assignment operator to prevent accisdental copying
UncompressedBlock& operator=(const UncompressedBlock& /*rhs*/) {};
// Made this private for consistancy with CompressedBlock.
// Users shouldn't really need this for UncompressedBlock anyway.
uint32_t calculateSizeInBytes(void);
VoxelType* m_tData;
uint16_t m_uSideLength;
uint8_t m_uSideLengthPower;
};
}
#include "PolyVoxCore/Block.inl"
#endif

View File

@ -25,7 +25,8 @@ freely, subject to the following restrictions:
#define __PolyVox_BlockCompressor_H__
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
#include "PolyVoxCore/Block.h"
#include "PolyVoxCore/CompressedBlock.h"
#include "PolyVoxCore/UncompressedBlock.h"
namespace PolyVox
{

View File

@ -0,0 +1,63 @@
/*******************************************************************************
Copyright (c) 2005-2013 David Williams and Matthew 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_CompressedBlock_H__
#define __PolyVox_CompressedBlock_H__
#include "PolyVoxCore/Block.h"
namespace PolyVox
{
template <typename VoxelType>
class CompressedBlock : public Block<VoxelType>
{
friend class LargeVolume<VoxelType>;
public:
CompressedBlock();
~CompressedBlock();
const uint8_t* getData(void) const;
uint32_t getDataSizeInBytes(void) const;
void setData(const uint8_t* const pData, uint32_t uDataSizeInBytes);
private:
/// Private copy constructor to prevent accisdental copying
CompressedBlock(const CompressedBlock& /*rhs*/) {};
/// Private assignment operator to prevent accisdental copying
CompressedBlock& operator=(const CompressedBlock& /*rhs*/) {};
// Made this private to avoid any confusion with getDataSizeInBytes().
// Users shouldn't really need this for CompressedBlock anyway.
uint32_t calculateSizeInBytes(void);
uint8_t* m_pData;
uint32_t m_uDataSizeInBytes;
};
}
#include "PolyVoxCore/CompressedBlock.inl"
#endif

View File

@ -0,0 +1,79 @@
/*******************************************************************************
Copyright (c) 2005-2013 David Williams and Matthew 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
{
template <typename VoxelType>
CompressedBlock<VoxelType>::CompressedBlock()
:m_pData(0)
,m_uDataSizeInBytes(0)
{
}
template <typename VoxelType>
CompressedBlock<VoxelType>::~CompressedBlock()
{
delete[] m_pData;
m_pData = 0;
}
template <typename VoxelType>
const uint8_t* CompressedBlock<VoxelType>::getData(void) const
{
return m_pData;
}
template <typename VoxelType>
uint32_t CompressedBlock<VoxelType>::getDataSizeInBytes(void) const
{
return m_uDataSizeInBytes;
}
template <typename VoxelType>
void CompressedBlock<VoxelType>::setData(const uint8_t* const pData, uint32_t uDataSizeInBytes)
{
POLYVOX_THROW_IF(pData == 0, std::invalid_argument, "Pointer to data cannot be null");
POLYVOX_THROW_IF(m_pData == pData, std::invalid_argument, "Attempting to copy data onto itself");
// Delete any existing data
delete[] m_pData;
// Allocate new data
m_uDataSizeInBytes = uDataSizeInBytes;
m_pData = new uint8_t[uDataSizeInBytes];
// Copy the data across
memcpy(m_pData, pData, uDataSizeInBytes);
// Flag as modified
this->m_bDataModified = true;
}
template <typename VoxelType>
uint32_t CompressedBlock<VoxelType>::calculateSizeInBytes(void)
{
// Returns the size of this class plus the size of the compressed data.
uint32_t uSizeInBytes = sizeof(CompressedBlock<VoxelType>) + m_uDataSizeInBytes;
return uSizeInBytes;
}
}

View File

@ -24,7 +24,7 @@ freely, subject to the following restrictions:
#ifndef __PolyVox_Pager_H__
#define __PolyVox_Pager_H__
#include "PolyVoxCore/Block.h"
#include "PolyVoxCore/CompressedBlock.h"
#include "PolyVoxCore/Impl/TypeDef.h"
namespace PolyVox

View File

@ -0,0 +1,68 @@
/*******************************************************************************
Copyright (c) 2005-2013 David Williams and Matthew 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_UncompressedBlock_H__
#define __PolyVox_UncompressedBlock_H__
#include "PolyVoxCore/Block.h"
namespace PolyVox
{
template <typename VoxelType>
class UncompressedBlock : public Block<VoxelType>
{
friend class LargeVolume<VoxelType>;
public:
UncompressedBlock(uint16_t uSideLength);
~UncompressedBlock();
VoxelType* getData(void) const;
uint32_t getDataSizeInBytes(void) const;
VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const;
VoxelType getVoxel(const Vector3DUint16& v3dPos) const;
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
private:
/// Private copy constructor to prevent accisdental copying
UncompressedBlock(const UncompressedBlock& /*rhs*/) {};
/// Private assignment operator to prevent accisdental copying
UncompressedBlock& operator=(const UncompressedBlock& /*rhs*/) {};
// Made this private for consistancy with CompressedBlock.
// Users shouldn't really need this for UncompressedBlock anyway.
uint32_t calculateSizeInBytes(void);
VoxelType* m_tData;
uint16_t m_uSideLength;
uint8_t m_uSideLengthPower;
};
}
#include "PolyVoxCore/UncompressedBlock.inl"
#endif

View File

@ -1,5 +1,5 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
Copyright (c) 2005-2013 David Williams and Matthew 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,90 +9,20 @@ 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.
*******************************************************************************/
#include "PolyVoxCore/Impl/ErrorHandling.h"
#include "PolyVoxCore/Impl/Utility.h"
#include "PolyVoxCore/Compressor.h"
#include "PolyVoxCore/Vector.h"
#include "PolyVoxCore/Impl/ErrorHandling.h"
#include <cstring> //For memcpy
#include <limits>
#include <stdexcept> //for std::invalid_argument
namespace PolyVox
{
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
CompressedBlock<VoxelType>::CompressedBlock()
:m_pData(0)
,m_uDataSizeInBytes(0)
{
}
template <typename VoxelType>
CompressedBlock<VoxelType>::~CompressedBlock()
{
delete[] m_pData;
m_pData = 0;
}
template <typename VoxelType>
const uint8_t* CompressedBlock<VoxelType>::getData(void) const
{
return m_pData;
}
template <typename VoxelType>
uint32_t CompressedBlock<VoxelType>::getDataSizeInBytes(void) const
{
return m_uDataSizeInBytes;
}
template <typename VoxelType>
void CompressedBlock<VoxelType>::setData(const uint8_t* const pData, uint32_t uDataSizeInBytes)
{
POLYVOX_THROW_IF(pData == 0, std::invalid_argument, "Pointer to data cannot be null");
POLYVOX_THROW_IF(m_pData == pData, std::invalid_argument, "Attempting to copy data onto itself");
// Delete any existing data
delete[] m_pData;
// Allocate new data
m_uDataSizeInBytes = uDataSizeInBytes;
m_pData = new uint8_t[uDataSizeInBytes];
// Copy the data across
memcpy(m_pData, pData, uDataSizeInBytes);
// Flag as modified
this->m_bDataModified = true;
}
template <typename VoxelType>
uint32_t CompressedBlock<VoxelType>::calculateSizeInBytes(void)
{
// Returns the size of this class plus the size of the compressed data.
uint32_t uSizeInBytes = sizeof(CompressedBlock<VoxelType>) + m_uDataSizeInBytes;
return uSizeInBytes;
}
////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
UncompressedBlock<VoxelType>::UncompressedBlock(uint16_t uSideLength)
:m_tData(0)