Start of actual RLE compression.
This commit is contained in:
parent
7be083a243
commit
4621ef8091
@ -421,7 +421,7 @@ int main(int argc, char *argv[])
|
||||
openGLWidget.show();
|
||||
|
||||
//Create an empty volume and then place a sphere in it
|
||||
Volume<MaterialDensityPair44> volData(128, 128, 128);
|
||||
Volume<MaterialDensityPair44> volData(256, 256, 256);
|
||||
//createSphereInVolume(volData, 30);
|
||||
createPerlinVolume(volData);
|
||||
|
||||
@ -439,12 +439,12 @@ int main(int argc, char *argv[])
|
||||
}*/
|
||||
|
||||
//Extract the surface
|
||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
/*SurfaceMesh<PositionMaterialNormal> mesh;
|
||||
CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
|
||||
surfaceExtractor.execute();
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
||||
openGLWidget.setSurfaceMeshToRender(mesh);*/
|
||||
|
||||
//Run the message pump.
|
||||
return app.exec();
|
||||
|
@ -26,6 +26,8 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
@ -61,6 +63,9 @@ namespace PolyVox
|
||||
VoxelType* m_tUncompressedData;
|
||||
bool m_bIsCompressed;
|
||||
uint32_t m_uTimestamp;
|
||||
|
||||
std::vector<uint32_t> runlengths;
|
||||
std::vector<VoxelType> values;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,13 @@ namespace PolyVox
|
||||
m_uSideLengthPower = rhs.m_uSideLengthPower;
|
||||
memcpy(m_tCompressedData, rhs.m_tCompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
||||
|
||||
m_bIsCompressed = rhs.m_bIsCompressed;
|
||||
if(m_bIsCompressed == false)
|
||||
{
|
||||
memcpy(m_tUncompressedData, rhs.m_tUncompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
||||
}
|
||||
m_uTimestamp = rhs.m_uTimestamp;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -186,7 +193,43 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void Block<VoxelType>::compress(void)
|
||||
{
|
||||
memcpy(m_tCompressedData, m_tUncompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength);
|
||||
//memcpy(m_tCompressedData, m_tUncompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength);
|
||||
VoxelType current;
|
||||
uint32_t runLength = 0;
|
||||
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
bool firstTime = true;
|
||||
//uint32_t runlengthCounter = 0;
|
||||
runlengths.clear();
|
||||
values.clear();
|
||||
|
||||
for(uint32_t ct = 0; ct < uNoOfVoxels; ++ct)
|
||||
{
|
||||
VoxelType value = *(m_tUncompressedData + ct);
|
||||
if(firstTime)
|
||||
{
|
||||
current = value;
|
||||
runLength = 1;
|
||||
firstTime = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(value == current)
|
||||
{
|
||||
runLength++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//stream.write(reinterpret_cast<char*>(¤t), sizeof(current));
|
||||
//stream.write(reinterpret_cast<char*>(&runLength), sizeof(runLength));
|
||||
runlengths.push_back(runLength);
|
||||
values.push_back(current);
|
||||
current = value;
|
||||
runLength = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete[] m_tUncompressedData;
|
||||
m_tUncompressedData = 0;
|
||||
m_bIsCompressed = true;
|
||||
@ -196,7 +239,20 @@ namespace PolyVox
|
||||
void Block<VoxelType>::uncompress(void)
|
||||
{
|
||||
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||
memcpy(m_tUncompressedData, m_tCompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength);
|
||||
|
||||
|
||||
//memcpy(m_tUncompressedData, m_tCompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength);
|
||||
VoxelType* pUncompressedData = m_tUncompressedData;
|
||||
for(uint32_t ct = 0; ct < runlengths.size(); ++ct)
|
||||
{
|
||||
for(uint32_t i = 0; i < runlengths[ct]; ++i)
|
||||
{
|
||||
*pUncompressedData = values[ct];
|
||||
++pUncompressedData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_bIsCompressed = false;
|
||||
}
|
||||
}
|
||||
|
@ -388,10 +388,10 @@ namespace PolyVox
|
||||
return block;
|
||||
}
|
||||
|
||||
const uint32_t MaxUncompressedBlocks = 4;
|
||||
const uint32_t MaxUncompressedBlocks = 10;
|
||||
if(m_pUncompressedBlocks.size() == MaxUncompressedBlocks)
|
||||
{
|
||||
Block<VoxelType>* pLeastRecentlyUsedBlock;
|
||||
Block<VoxelType>* pLeastRecentlyUsedBlock = 0;
|
||||
uint32_t uLeastRecentTimestamp = 100000000;
|
||||
for(std::set<Block<VoxelType>*>::iterator iter = m_pUncompressedBlocks.begin(); iter != m_pUncompressedBlocks.end(); iter++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user