More work on compression and bug fixes.
This commit is contained in:
parent
4621ef8091
commit
f13e9161f8
@ -421,7 +421,7 @@ int main(int argc, char *argv[])
|
|||||||
openGLWidget.show();
|
openGLWidget.show();
|
||||||
|
|
||||||
//Create an empty volume and then place a sphere in it
|
//Create an empty volume and then place a sphere in it
|
||||||
Volume<MaterialDensityPair44> volData(256, 256, 256);
|
Volume<MaterialDensityPair44> volData(1024, 1024, 1024);
|
||||||
//createSphereInVolume(volData, 30);
|
//createSphereInVolume(volData, 30);
|
||||||
createPerlinVolume(volData);
|
createPerlinVolume(volData);
|
||||||
|
|
||||||
|
@ -59,10 +59,9 @@ namespace PolyVox
|
|||||||
|
|
||||||
uint16_t m_uSideLength;
|
uint16_t m_uSideLength;
|
||||||
uint8_t m_uSideLengthPower;
|
uint8_t m_uSideLengthPower;
|
||||||
VoxelType* m_tCompressedData;
|
|
||||||
VoxelType* m_tUncompressedData;
|
VoxelType* m_tUncompressedData;
|
||||||
bool m_bIsCompressed;
|
bool m_bIsCompressed;
|
||||||
uint32_t m_uTimestamp;
|
uint64_t m_uTimestamp;
|
||||||
|
|
||||||
std::vector<uint32_t> runlengths;
|
std::vector<uint32_t> runlengths;
|
||||||
std::vector<VoxelType> values;
|
std::vector<VoxelType> values;
|
||||||
|
@ -35,7 +35,6 @@ namespace PolyVox
|
|||||||
Block<VoxelType>::Block(uint16_t uSideLength)
|
Block<VoxelType>::Block(uint16_t uSideLength)
|
||||||
:m_uSideLength(0)
|
:m_uSideLength(0)
|
||||||
,m_uSideLengthPower(0)
|
,m_uSideLengthPower(0)
|
||||||
,m_tCompressedData(0)
|
|
||||||
,m_tUncompressedData(0)
|
,m_tUncompressedData(0)
|
||||||
,m_bIsCompressed(true)
|
,m_bIsCompressed(true)
|
||||||
,m_uTimestamp(0)
|
,m_uTimestamp(0)
|
||||||
@ -55,33 +54,37 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
Block<VoxelType>::~Block()
|
Block<VoxelType>::~Block()
|
||||||
{
|
{
|
||||||
delete[] m_tCompressedData;
|
delete[] m_tUncompressedData;
|
||||||
m_tCompressedData = 0;
|
m_tUncompressedData = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
|
Block<VoxelType>& Block<VoxelType>::operator=(const Block<VoxelType>& rhs)
|
||||||
{
|
{
|
||||||
|
//We don't often need to assign blocks as they should be passed around by pointer.
|
||||||
|
//And I'm pretty sure we don't want to be passing around uncompressed ones becauses
|
||||||
|
//it means duplicating the uncompressed data which is expensive. This assert is to
|
||||||
|
//make sure that uncompressed blocks don't get assigned by accident.
|
||||||
|
assert(rhs.m_bIsCompressed == true);
|
||||||
|
|
||||||
if (this == &rhs)
|
if (this == &rhs)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If this fails an exception will be thrown. Memory is not
|
|
||||||
//allocated and there is nothing else in this class to clean up
|
|
||||||
m_tCompressedData = new VoxelType[rhs.m_uSideLength * rhs.m_uSideLength * rhs.m_uSideLength];
|
|
||||||
|
|
||||||
//Copy the data
|
//Copy the data
|
||||||
m_uSideLength = rhs.m_uSideLength;
|
m_uSideLength = rhs.m_uSideLength;
|
||||||
m_uSideLengthPower = rhs.m_uSideLengthPower;
|
m_uSideLengthPower = rhs.m_uSideLengthPower;
|
||||||
memcpy(m_tCompressedData, rhs.m_tCompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
|
||||||
|
|
||||||
m_bIsCompressed = rhs.m_bIsCompressed;
|
m_bIsCompressed = rhs.m_bIsCompressed;
|
||||||
|
m_uTimestamp = rhs.m_uTimestamp;
|
||||||
|
runlengths = rhs.runlengths;
|
||||||
|
values = rhs.values;
|
||||||
|
|
||||||
if(m_bIsCompressed == false)
|
if(m_bIsCompressed == false)
|
||||||
{
|
{
|
||||||
|
m_tUncompressedData = new VoxelType[rhs.m_uSideLength * rhs.m_uSideLength * rhs.m_uSideLength];
|
||||||
memcpy(m_tUncompressedData, rhs.m_tUncompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
memcpy(m_tUncompressedData, rhs.m_tUncompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
||||||
}
|
}
|
||||||
m_uTimestamp = rhs.m_uTimestamp;
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -146,7 +149,6 @@ namespace PolyVox
|
|||||||
|
|
||||||
assert(m_tUncompressedData);
|
assert(m_tUncompressedData);
|
||||||
|
|
||||||
//memset(m_tCompressedData, (int)tValue, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType));
|
|
||||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||||
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
|
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
|
||||||
}
|
}
|
||||||
@ -167,13 +169,17 @@ namespace PolyVox
|
|||||||
m_uSideLength = uSideLength;
|
m_uSideLength = uSideLength;
|
||||||
m_uSideLengthPower = logBase2(uSideLength);
|
m_uSideLengthPower = logBase2(uSideLength);
|
||||||
|
|
||||||
|
|
||||||
|
if(m_bIsCompressed == false)
|
||||||
|
{
|
||||||
//Delete the old data
|
//Delete the old data
|
||||||
delete[] m_tCompressedData;
|
delete[] m_tUncompressedData;
|
||||||
m_tCompressedData = 0;
|
m_tUncompressedData = 0;
|
||||||
|
|
||||||
//If this fails an exception will be thrown. Memory is not
|
//If this fails an exception will be thrown. Memory is not
|
||||||
//allocated and there is nothing else in this class to clean up
|
//allocated and there is nothing else in this class to clean up
|
||||||
m_tCompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
@ -181,7 +187,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
uint32_t uSizeInChars = sizeof(Block<VoxelType>);
|
uint32_t uSizeInChars = sizeof(Block<VoxelType>);
|
||||||
|
|
||||||
if(m_tCompressedData != 0)
|
if(m_tUncompressedData != 0)
|
||||||
{
|
{
|
||||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||||
uSizeInChars += uNoOfVoxels * sizeof(VoxelType);
|
uSizeInChars += uNoOfVoxels * sizeof(VoxelType);
|
||||||
@ -193,7 +199,6 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void Block<VoxelType>::compress(void)
|
void Block<VoxelType>::compress(void)
|
||||||
{
|
{
|
||||||
//memcpy(m_tCompressedData, m_tUncompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength);
|
|
||||||
VoxelType current;
|
VoxelType current;
|
||||||
uint32_t runLength = 0;
|
uint32_t runLength = 0;
|
||||||
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||||
@ -241,7 +246,6 @@ namespace PolyVox
|
|||||||
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
|
||||||
|
|
||||||
|
|
||||||
//memcpy(m_tUncompressedData, m_tCompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength);
|
|
||||||
VoxelType* pUncompressedData = m_tUncompressedData;
|
VoxelType* pUncompressedData = m_tUncompressedData;
|
||||||
for(uint32_t ct = 0; ct < runlengths.size(); ++ct)
|
for(uint32_t ct = 0; ct < runlengths.size(); ++ct)
|
||||||
{
|
{
|
||||||
|
@ -179,7 +179,7 @@ namespace PolyVox
|
|||||||
uint16_t m_uLongestSideLength;
|
uint16_t m_uLongestSideLength;
|
||||||
uint16_t m_uShortestSideLength;
|
uint16_t m_uShortestSideLength;
|
||||||
float m_fDiagonalLength;
|
float m_fDiagonalLength;
|
||||||
mutable uint32_t m_uTimestamper;
|
mutable uint64_t m_uTimestamper;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Some handy typedefs
|
//Some handy typedefs
|
||||||
|
@ -388,11 +388,11 @@ namespace PolyVox
|
|||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t MaxUncompressedBlocks = 10;
|
const uint32_t MaxUncompressedBlocks = 1000;
|
||||||
if(m_pUncompressedBlocks.size() == MaxUncompressedBlocks)
|
if(m_pUncompressedBlocks.size() == MaxUncompressedBlocks)
|
||||||
{
|
{
|
||||||
Block<VoxelType>* pLeastRecentlyUsedBlock = 0;
|
Block<VoxelType>* pLeastRecentlyUsedBlock = 0;
|
||||||
uint32_t uLeastRecentTimestamp = 100000000;
|
uint32_t uLeastRecentTimestamp = 1000000000000000;
|
||||||
for(std::set<Block<VoxelType>*>::iterator iter = m_pUncompressedBlocks.begin(); iter != m_pUncompressedBlocks.end(); iter++)
|
for(std::set<Block<VoxelType>*>::iterator iter = m_pUncompressedBlocks.begin(); iter != m_pUncompressedBlocks.end(); iter++)
|
||||||
{
|
{
|
||||||
if((*iter)->m_uTimestamp < uLeastRecentTimestamp)
|
if((*iter)->m_uTimestamp < uLeastRecentTimestamp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user