Added support for non-cubic volumes.

This commit is contained in:
David Williams
2009-04-19 22:48:56 +00:00
parent 1f6a3231c1
commit c627c90cd0
9 changed files with 150 additions and 69 deletions

View File

@ -42,7 +42,9 @@ namespace PolyVox
int32_t getCurrentTime(void) const;
Region getEnclosingRegion(void) const;
int32_t getLastModifiedTimeForRegion(uint16_t uX, uint16_t uY, uint16_t uZ);
uint16_t getSideLength(void);
uint16_t getWidth(void);
uint16_t getHeight(void);
uint16_t getDepth(void);
Volume<uint8_t>* getVolumeData(void) const;
uint8_t getVoxelAt(const Vector3DUint16& pos);
uint8_t getVoxelAt(uint16_t uX, uint16_t uY, uint16_t uZ);
@ -64,7 +66,9 @@ namespace PolyVox
uint16_t m_uRegionSideLength;
uint8_t m_uRegionSideLengthPower;
uint16_t m_uVolumeSideLengthInRegions;
uint16_t m_uVolumeWidthInRegions;
uint16_t m_uVolumeHeightInRegions;
uint16_t m_uVolumeDepthInRegions;
//It's not what the block class was designed for, but it

View File

@ -25,7 +25,7 @@ namespace PolyVox
uint16_t volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
Volume<uint8_t>* volume = new Volume<uint8_t>(volumeWidth);
Volume<uint8_t>* volume = new Volume<uint8_t>(volumeWidth, volumeHeight, volumeDepth);
//Read data
for(uint16_t z = 0; z < volumeDepth; ++z)
@ -48,9 +48,9 @@ namespace PolyVox
void saveVolumeRaw(std::ostream& stream, Volume<uint8_t>& volume)
{
//Write volume dimensions
uint16_t volumeWidth = volume.getSideLength();
uint16_t volumeHeight = volume.getSideLength();
uint16_t volumeDepth = volume.getSideLength();
uint16_t volumeWidth = volume.getWidth();
uint16_t volumeHeight = volume.getHeight();
uint16_t volumeDepth = volume.getDepth();
uint8_t volumeWidthPower = logBase2(volumeWidth);
uint8_t volumeHeightPower = logBase2(volumeHeight);
@ -93,7 +93,7 @@ namespace PolyVox
uint16_t volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
Volume<uint8_t>* volume = new Volume<uint8_t>(volumeWidth);
Volume<uint8_t>* volume = new Volume<uint8_t>(volumeWidth, volumeHeight, volumeDepth);
//Read data
bool firstTime = true;
@ -130,9 +130,9 @@ namespace PolyVox
void saveVolumeRle(std::ostream& stream, Volume<uint8_t>& volume)
{
//Write volume dimensions
uint16_t volumeWidth = volume.getSideLength();
uint16_t volumeHeight = volume.getSideLength();
uint16_t volumeDepth = volume.getSideLength();
uint16_t volumeWidth = volume.getWidth();
uint16_t volumeHeight = volume.getHeight();
uint16_t volumeDepth = volume.getDepth();
uint8_t volumeWidthPower = logBase2(volumeWidth);
uint8_t volumeHeightPower = logBase2(volumeHeight);

View File

@ -46,10 +46,14 @@ namespace PolyVox
,m_uRegionSideLength(regionSideLength)
{
volumeData = volumeDataToSet;
m_uVolumeSideLengthInRegions = volumeData->getSideLength() / m_uRegionSideLength;
m_uVolumeWidthInRegions = volumeData->getWidth() / m_uRegionSideLength;
m_uVolumeHeightInRegions = volumeData->getHeight() / m_uRegionSideLength;
m_uVolumeDepthInRegions = volumeData->getDepth() / m_uRegionSideLength;
m_uRegionSideLengthPower = PolyVox::logBase2(m_uRegionSideLength);
volRegionLastModified = new BlockData<int32_t>(m_uRegionSideLength);
uint16_t uLongestSideLength = (std::max)((std::max)(m_uVolumeWidthInRegions,m_uVolumeHeightInRegions),m_uVolumeDepthInRegions);
volRegionLastModified = new BlockData<int32_t>(uLongestSideLength); //FIXME - Maybe using a block here isn't optimal as it must always be cubic...
}
VolumeChangeTracker::~VolumeChangeTracker()
@ -58,11 +62,11 @@ namespace PolyVox
void VolumeChangeTracker::setAllRegionsModified(void)
{
for(uint16_t blockZ = 0; blockZ < m_uVolumeSideLengthInRegions; ++blockZ)
for(uint16_t blockZ = 0; blockZ < m_uVolumeDepthInRegions; ++blockZ)
{
for(uint16_t blockY = 0; blockY < m_uVolumeSideLengthInRegions; ++blockY)
for(uint16_t blockY = 0; blockY < m_uVolumeHeightInRegions; ++blockY)
{
for(uint16_t blockX = 0; blockX < m_uVolumeSideLengthInRegions; ++blockX)
for(uint16_t blockX = 0; blockX < m_uVolumeWidthInRegions; ++blockX)
{
volRegionLastModified->setVoxelAt(blockX, blockY, blockZ, m_iCurrentTime);
++m_iCurrentTime;
@ -76,9 +80,19 @@ namespace PolyVox
return m_iCurrentTime;
}
uint16_t VolumeChangeTracker::getSideLength(void)
uint16_t VolumeChangeTracker::getWidth(void)
{
return volumeData->getSideLength();
return volumeData->getWidth();
}
uint16_t VolumeChangeTracker::getHeight(void)
{
return volumeData->getHeight();
}
uint16_t VolumeChangeTracker::getDepth(void)
{
return volumeData->getDepth();
}
Region VolumeChangeTracker::getEnclosingRegion(void) const
@ -98,9 +112,9 @@ namespace PolyVox
uint8_t VolumeChangeTracker::getVoxelAt(uint16_t uX, uint16_t uY, uint16_t uZ)
{
assert(uX < volumeData->getSideLength());
assert(uY < volumeData->getSideLength());
assert(uZ < volumeData->getSideLength());
assert(uX < volumeData->getWidth());
assert(uY < volumeData->getHeight());
assert(uZ < volumeData->getDepth());
VolumeIterator<uint8_t> volIter(*volumeData);
volIter.setPosition(uX,uY,uZ);
@ -143,9 +157,9 @@ namespace PolyVox
const uint16_t minRegionY = (std::max)(uint16_t(0),uint16_t(regionY-1));
const uint16_t minRegionZ = (std::max)(uint16_t(0),uint16_t(regionZ-1));
const uint16_t maxRegionX = (std::min)(uint16_t(m_uVolumeSideLengthInRegions-1),uint16_t(regionX+1));
const uint16_t maxRegionY = (std::min)(uint16_t(m_uVolumeSideLengthInRegions-1),uint16_t(regionY+1));
const uint16_t maxRegionZ = (std::min)(uint16_t(m_uVolumeSideLengthInRegions-1),uint16_t(regionZ+1));
const uint16_t maxRegionX = (std::min)(uint16_t(m_uVolumeWidthInRegions-1),uint16_t(regionX+1));
const uint16_t maxRegionY = (std::min)(uint16_t(m_uVolumeHeightInRegions-1),uint16_t(regionY+1));
const uint16_t maxRegionZ = (std::min)(uint16_t(m_uVolumeDepthInRegions-1),uint16_t(regionZ+1));
for(uint16_t zCt = minRegionZ; zCt <= maxRegionZ; zCt++)
{