Removed RLECompressor as the code is now in RLEBlockCompressor.

Things are starting to get back under control. All tests pass, and all examples except PagingExample work.
This commit is contained in:
David Williams 2013-07-30 17:01:27 +02:00
parent fa8813ba86
commit 4478e365c9
7 changed files with 7 additions and 176 deletions

View File

@ -21,11 +21,12 @@ freely, subject to the following restrictions:
distribution.
*******************************************************************************/
#include "PolyVoxCore/FilePager.h"
#include "PolyVoxCore/MaterialDensityPair.h"
#include "PolyVoxCore/LargeVolume.h"
#include "PolyVoxCore/LowPassFilter.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/RLECompressor.h"
#include "PolyVoxCore/RLEBlockCompressor.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/Impl/Utility.h"
@ -49,8 +50,9 @@ using namespace std;
int main(int argc, char *argv[])
{
RLECompressor<MaterialDensityPair44, uint16_t>* compressor = new RLECompressor<MaterialDensityPair44, uint16_t>();
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, 0);
RLEBlockCompressor<MaterialDensityPair44>* compressor = new RLEBlockCompressor<MaterialDensityPair44>();
FilePager<MaterialDensityPair44>* pager = new FilePager<MaterialDensityPair44>("./");
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, pager);
//Make our volume contain a sphere in the center.
int32_t minPos = 0;

View File

@ -28,7 +28,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h"
#include "PolyVoxCore/MarchingCubesSurfaceExtractor.h"
#include "PolyVoxCore/Pager.h"
#include "PolyVoxCore/RLECompressor.h"
#include "PolyVoxCore/RLEBlockCompressor.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/LargeVolume.h"
@ -150,7 +150,7 @@ int main(int argc, char *argv[])
OpenGLWidget openGLWidget(0);
openGLWidget.show();
RLECompressor<MaterialDensityPair44, uint16_t>* compressor = new RLECompressor<MaterialDensityPair44, uint16_t>();
RLEBlockCompressor<MaterialDensityPair44>* compressor = new RLEBlockCompressor<MaterialDensityPair44>();
PerlinNoisePager* pager = new PerlinNoisePager();
LargeVolume<MaterialDensityPair44> volData(PolyVox::Region::MaxRegion, compressor, pager, 256);
volData.setMaxNumberOfBlocksInMemory(4096);

View File

@ -87,8 +87,6 @@ SET(CORE_INC_FILES
include/PolyVoxCore/Region.h
include/PolyVoxCore/RLEBlockCompressor.h
include/PolyVoxCore/RLEBlockCompressor.inl
include/PolyVoxCore/RLECompressor.h
include/PolyVoxCore/RLECompressor.inl
include/PolyVoxCore/SimpleVolume.h
include/PolyVoxCore/SimpleVolume.inl
include/PolyVoxCore/SimpleVolumeBlock.inl

View File

@ -23,8 +23,6 @@ freely, subject to the following restrictions:
#include <vector>
#include "RLECompressor.h"
namespace PolyVox
{
template <typename VoxelType>

View File

@ -1,40 +0,0 @@
#ifndef __PolyVox_RLECompressor_H__
#define __PolyVox_RLECompressor_H__
#include "PolyVoxCore/Compressor.h"
namespace PolyVox
{
/**
* Performs compression of data using Run Length Encoding (RLE).
*
* This compressor is designed for voxel data which contains long runs of the same value. Minecraft-style terrain and other
* cubic-style terrains are likely to fall under this category, whereas density fields for Marching Cubes terrain will not. Please
* see the following article if you want more details of how RLE compression works: http://en.wikipedia.org/wiki/Run-length_encoding
*
* \sa MinizCompressor
*/
template<typename ValueType, typename LengthType>
class RLECompressor : public Compressor
{
struct Run
{
ValueType value;
LengthType length;
};
public:
/// Constructor
RLECompressor();
/// Destructor
~RLECompressor();
// API documentation is in base class and gets inherited by Doxygen.
uint32_t getMaxCompressedSize(uint32_t uUncompressedInputSize);
uint32_t compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
uint32_t decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
};
}
#include "RLECompressor.inl"
#endif //__PolyVox_RLECompressor_H__

View File

@ -1,126 +0,0 @@
#include <algorithm>
#include <cassert>
#include <limits>
namespace PolyVox
{
template<typename ValueType, typename LengthType>
RLECompressor<ValueType, LengthType>::RLECompressor()
{
}
template<typename ValueType, typename LengthType>
RLECompressor<ValueType, LengthType>::~RLECompressor()
{
}
template<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::getMaxCompressedSize(uint32_t uUncompressedInputSize)
{
// In the worst case we will have a seperate Run (of length one) for each element of the input data.
return uUncompressedInputSize * sizeof(Run);
}
template<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::compress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
{
if(uSrcLength % sizeof(ValueType) != 0)
{
POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the ValueType size");
}
// Lengths provided are in bytes, so convert them to be in terms of our types.
uSrcLength /= sizeof(ValueType);
uDstLength /= sizeof(Run);
// Get data pointers in the appropriate type
const ValueType* pSrcDataAsType = reinterpret_cast<const ValueType*>(pSrcData);
Run* pDstDataAsRun = reinterpret_cast<Run*>(pDstData);
// Pointers to just past the end of the data
const ValueType* pSrcDataEnd = pSrcDataAsType + uSrcLength;
Run* pDstDataEnd = pDstDataAsRun + uDstLength;
//Counter for the output length
uint32_t uDstLengthInBytes = 0;
// Read the first element of the source and set up the first run based on it.
pDstDataAsRun->value = *pSrcDataAsType;
pSrcDataAsType++;
pDstDataAsRun->length = 1;
uDstLengthInBytes += sizeof(Run);
//Now process all remaining elements of the source.
while(pSrcDataAsType < pSrcDataEnd)
{
// If the value is the same as the current run (and we have not
// reached the maximum run length) then extend the current run.
if((*pSrcDataAsType == pDstDataAsRun->value) && (pDstDataAsRun->length < (std::numeric_limits<LengthType>::max)()))
{
pDstDataAsRun->length++;
}
// Otherwise we need to start a new Run.
else
{
pDstDataAsRun++;
// Check if we have enough space in the destination buffer.
if(pDstDataAsRun >= pDstDataEnd)
{
POLYVOX_THROW(std::runtime_error, "Insufficient space in destination buffer.");
}
// Create the new run.
pDstDataAsRun->value = *pSrcDataAsType;
pDstDataAsRun->length = 1;
uDstLengthInBytes += sizeof(Run);
}
pSrcDataAsType++;
}
return uDstLengthInBytes;
}
template<typename ValueType, typename LengthType>
uint32_t RLECompressor<ValueType, LengthType>::decompress(const void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength)
{
if(uSrcLength % sizeof(Run) != 0)
{
POLYVOX_THROW(std::length_error, "Source length must be a integer multiple of the Run size");
}
// Lengths provided are in bytes, so convert them to be in terms of our types.
uSrcLength /= sizeof(Run);
uDstLength /= sizeof(ValueType);
// Get data pointers in the appropriate type
const Run* pSrcDataAsRun = reinterpret_cast<const Run*>(pSrcData);
ValueType* pDstDataAsType = reinterpret_cast<ValueType*>(pDstData);
// Pointers to just past the end of the data
const Run* pSrcDataEnd = pSrcDataAsRun + uSrcLength;
ValueType* pDstDataEnd = pDstDataAsType + uDstLength;
//Counter for the output length
uint32_t uDstLengthInBytes = 0;
while(pSrcDataAsRun < pSrcDataEnd)
{
// Check if we have enough space in the destination buffer.
if(pDstDataAsType + pSrcDataAsRun->length > pDstDataEnd)
{
POLYVOX_THROW(std::runtime_error, "Insufficient space in destination buffer.");
}
// Write the run into the destination
std::fill(pDstDataAsType, pDstDataAsType + pSrcDataAsRun->length, pSrcDataAsRun->value);
pDstDataAsType += pSrcDataAsRun->length;
uDstLengthInBytes += pSrcDataAsRun->length * sizeof(ValueType);
pSrcDataAsRun++;
}
return uDstLengthInBytes;
}
}

View File

@ -27,7 +27,6 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/LargeVolume.h"
#include "PolyVoxCore/MinizBlockCompressor.h"
#include "PolyVoxCore/RawVolume.h"
#include "PolyVoxCore/RLECompressor.h"
#include "PolyVoxCore/SimpleVolume.h"
#include <QtGlobal>