diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index ccae9941..e6ae33d7 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -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* compressor = new RLECompressor(); - LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, 0); + RLEBlockCompressor* compressor = new RLEBlockCompressor(); + FilePager* pager = new FilePager("./"); + LargeVolume 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; diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 117145b7..f28c54e6 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -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* compressor = new RLECompressor(); + RLEBlockCompressor* compressor = new RLEBlockCompressor(); PerlinNoisePager* pager = new PerlinNoisePager(); LargeVolume volData(PolyVox::Region::MaxRegion, compressor, pager, 256); volData.setMaxNumberOfBlocksInMemory(4096); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 018efe2d..f618c9ae 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -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 diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLEBlockCompressor.inl b/library/PolyVoxCore/include/PolyVoxCore/RLEBlockCompressor.inl index 4fc90b2e..aba87809 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RLEBlockCompressor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RLEBlockCompressor.inl @@ -23,8 +23,6 @@ freely, subject to the following restrictions: #include -#include "RLECompressor.h" - namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h deleted file mode 100644 index 03fd3318..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.h +++ /dev/null @@ -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 - 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__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl b/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl deleted file mode 100644 index cf65bc03..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/RLECompressor.inl +++ /dev/null @@ -1,126 +0,0 @@ -#include -#include -#include - -namespace PolyVox -{ - template - RLECompressor::RLECompressor() - { - } - - template - RLECompressor::~RLECompressor() - { - } - - template - uint32_t RLECompressor::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 - uint32_t RLECompressor::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(pSrcData); - Run* pDstDataAsRun = reinterpret_cast(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::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 - uint32_t RLECompressor::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(pSrcData); - ValueType* pDstDataAsType = reinterpret_cast(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; - } -} diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index d15e1fcc..f879f1bf 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -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