Removed features which were deprecated in release 0.2.

This commit is contained in:
David Williams
2012-12-03 21:22:57 +01:00
parent e7f4c69102
commit 7e38fc135e
13 changed files with 6 additions and 1618 deletions

View File

@ -0,0 +1 @@
I don't think Git allows empty directories, so this is just a placeholder until we decide what to do with PolyVoxUtil.

View File

@ -1,77 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_Serialization_H__
#define __PolyVox_Serialization_H__
#include "PolyVoxCore/Impl/Utility.h"
#include "PolyVoxCore/Region.h"
#include <iostream>
#include <memory>
namespace PolyVox
{
/// \deprecated
class POLYVOX_DEPRECATED VolumeSerializationProgressListener
{
public:
virtual void onProgressUpdated(float fProgress) = 0;
};
////////////////////////////////////////////////////////////////////////////////
// THESE FUNCTIONS ARE DEPRECATED.
////////////////////////////////////////////////////////////////////////////////
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED polyvox_shared_ptr< VolumeType > loadVolumeRaw(std::istream& stream, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED void saveVolumeRaw(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED polyvox_shared_ptr< VolumeType > loadVolumeRle(std::istream& stream, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED void saveVolumeRle(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED bool loadVolume(std::istream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED bool saveVolume(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED bool loadVersion0(std::istream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener = 0);
/// \deprecated
template< typename VolumeType >
POLYVOX_DEPRECATED bool saveVersion0(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener = 0);
}
#include "PolyVoxUtil/Serialization.inl"
#endif

View File

@ -1,433 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
//Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller.
//FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow
template< typename VolumeType >
polyvox_shared_ptr< VolumeType > loadVolumeRaw(std::istream& stream, VolumeSerializationProgressListener* progressListener)
{
assert(false); //THIS FUNCTION IS DEPRECATED. REMOVE THIS ASSERT TO CONTINUE, BUT SWITCH TO 'loadVolume()' ASAP.
//Read volume dimensions
uint8_t volumeWidthPower = 0;
uint8_t volumeHeightPower = 0;
uint8_t volumeDepthPower = 0;
stream.read(reinterpret_cast<char*>(&volumeWidthPower), sizeof(volumeWidthPower));
stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower));
stream.read(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower));
uint16_t volumeWidth = 0x0001 << volumeWidthPower;
uint16_t volumeHeight = 0x0001 << volumeHeightPower;
uint16_t volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
polyvox_shared_ptr< VolumeType > volume(new LargeVolume<VolumeType::VoxelType>(volumeWidth, volumeHeight, volumeDepth));
//Read data
for(uint16_t z = 0; z < volumeDepth; ++z)
{
//Update progress once per slice.
if(progressListener)
{
float fProgress = static_cast<float>(z) / static_cast<float>(volumeDepth);
progressListener->onProgressUpdated(fProgress);
}
for(uint16_t y = 0; y < volumeHeight; ++y)
{
for(uint16_t x = 0; x < volumeWidth; ++x)
{
VolumeType::VoxelType value;
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
volume->setVoxelAt(x,y,z,value);
}
}
}
//Finished
if(progressListener)
{
progressListener->onProgressUpdated(1.0f);
}
return volume;
}
template< typename VolumeType >
void saveVolumeRaw(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener)
{
assert(false); //THIS FUNCTION IS DEPRECATED. REMOVE THIS ASSERT TO CONTINUE, BUT SWITCH TO 'saveVolume()' ASAP.
//Write volume dimensions
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);
uint8_t volumeDepthPower = logBase2(volumeDepth);
stream.write(reinterpret_cast<char*>(&volumeWidthPower), sizeof(volumeWidthPower));
stream.write(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower));
stream.write(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower));
//Write data
VolumeType::Sampler volIter(&volume);
for(uint16_t z = 0; z < volumeDepth; ++z)
{
//Update progress once per slice.
if(progressListener)
{
float fProgress = static_cast<float>(z) / static_cast<float>(volumeDepth);
progressListener->onProgressUpdated(fProgress);
}
for(uint16_t y = 0; y < volumeHeight; ++y)
{
for(uint16_t x = 0; x < volumeWidth; ++x)
{
volIter.setPosition(x,y,z);
VolumeType::VoxelType value = volIter.getVoxel();
stream.write(reinterpret_cast<char*>(&value), sizeof(value));
}
}
}
//Finished
if(progressListener)
{
progressListener->onProgressUpdated(1.0f);
}
}
//Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller.
//FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow
template< typename VolumeType >
polyvox_shared_ptr< VolumeType > loadVolumeRle(std::istream& stream, VolumeSerializationProgressListener* progressListener)
{
assert(false); //THIS FUNCTION IS DEPRECATED. REMOVE THIS ASSERT TO CONTINUE, BUT SWITCH TO 'loadVolume()' ASAP.
//Read volume dimensions
uint8_t volumeWidthPower = 0;
uint8_t volumeHeightPower = 0;
uint8_t volumeDepthPower = 0;
stream.read(reinterpret_cast<char*>(&volumeWidthPower), sizeof(volumeWidthPower));
stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower));
stream.read(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower));
uint16_t volumeWidth = 0x0001 << volumeWidthPower;
uint16_t volumeHeight = 0x0001 << volumeHeightPower;
uint16_t volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
polyvox_shared_ptr< VolumeType > volume(new LargeVolume<VolumeType::VoxelType>(volumeWidth, volumeHeight, volumeDepth));
//Read data
bool firstTime = true;
uint32_t runLength = 0;
VolumeType::VoxelType value;
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
stream.read(reinterpret_cast<char*>(&runLength), sizeof(runLength));
for(uint16_t z = 0; z < volumeDepth; ++z)
{
//Update progress once per slice.
if(progressListener)
{
float fProgress = static_cast<float>(z) / static_cast<float>(volumeDepth);
progressListener->onProgressUpdated(fProgress);
}
for(uint16_t y = 0; y < volumeHeight; ++y)
{
for(uint16_t x = 0; x < volumeWidth; ++x)
{
if(runLength != 0)
{
volume->setVoxelAt(x,y,z,value);
runLength--;
}
else
{
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
stream.read(reinterpret_cast<char*>(&runLength), sizeof(runLength));
volume->setVoxelAt(x,y,z,value);
runLength--;
}
}
}
}
//Finished
if(progressListener)
{
progressListener->onProgressUpdated(1.0f);
}
return volume;
}
template< typename VolumeType >
void saveVolumeRle(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener)
{
assert(false); //THIS FUNCTION IS DEPRECATED. REMOVE THIS ASSERT TO CONTINUE, BUT SWITCH TO 'saveVolume()' ASAP.
//Write volume dimensions
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);
uint8_t volumeDepthPower = logBase2(volumeDepth);
stream.write(reinterpret_cast<char*>(&volumeWidthPower), sizeof(volumeWidthPower));
stream.write(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower));
stream.write(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower));
//Write data
VolumeType::Sampler volIter(&volume);
VolumeType::VoxelType current;
uint32_t runLength = 0;
bool firstTime = true;
for(uint16_t z = 0; z < volumeDepth; ++z)
{
//Update progress once per slice.
if(progressListener)
{
float fProgress = static_cast<float>(z) / static_cast<float>(volumeDepth);
progressListener->onProgressUpdated(fProgress);
}
for(uint16_t y = 0; y < volumeHeight; ++y)
{
for(uint16_t x = 0; x < volumeWidth; ++x)
{
volIter.setPosition(x,y,z);
VolumeType::VoxelType value = volIter.getVoxel();
if(firstTime)
{
current = value;
runLength = 1;
firstTime = false;
}
else
{
if(value == current)
{
runLength++;
}
else
{
stream.write(reinterpret_cast<char*>(&current), sizeof(current));
stream.write(reinterpret_cast<char*>(&runLength), sizeof(runLength));
current = value;
runLength = 1;
}
}
}
}
}
stream.write(reinterpret_cast<char*>(&current), sizeof(current));
stream.write(reinterpret_cast<char*>(&runLength), sizeof(runLength));
//Finished
if(progressListener)
{
progressListener->onProgressUpdated(1.0f);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// New version of load/save code with versioning
////////////////////////////////////////////////////////////////////////////////////////////////////
template< typename VolumeType >
bool loadVolume(std::istream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener)
{
char pIdentifier[8];
stream.read(pIdentifier, 7);
pIdentifier[7] = '\0'; //Set the null terminator
if(strcmp(pIdentifier, "PolyVox") != 0)
{
return false;
}
uint16_t uVersion;
stream.read(reinterpret_cast<char*>(&uVersion), sizeof(uVersion));
switch(uVersion)
{
case 0:
return loadVersion0(stream, volume, progressListener);
//Return means no need to break...
default:
return false;
}
}
template< typename VolumeType >
bool saveVolume(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener)
{
char pIdentifier[] = "PolyVox";
stream.write(pIdentifier, 7);
uint16_t uVersion = 0;
stream.write(reinterpret_cast<const char*>(&uVersion), sizeof(uVersion));
return saveVersion0(stream, volume, progressListener);
}
//Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller.
//FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow
template< typename VolumeType >
bool loadVersion0(std::istream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener)
{
//Read volume dimensions
uint16_t volumeWidth = 0;
uint16_t volumeHeight = 0;
uint16_t volumeDepth = 0;
stream.read(reinterpret_cast<char*>(&volumeWidth), sizeof(volumeWidth));
stream.read(reinterpret_cast<char*>(&volumeHeight), sizeof(volumeHeight));
stream.read(reinterpret_cast<char*>(&volumeDepth), sizeof(volumeDepth));
//Resize the volume
//HACK - Forces block size to 32. This functions needs reworking anyway due to large volume support.
volume.resize(Region(Vector3DInt32(0,0,0), Vector3DInt32(volumeWidth-1, volumeHeight-1, volumeDepth-1)), 32);
//Read data
bool firstTime = true;
uint32_t runLength = 0;
VolumeType::VoxelType value;
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
stream.read(reinterpret_cast<char*>(&runLength), sizeof(runLength));
for(uint16_t z = 0; z < volumeDepth; ++z)
{
//Update progress once per slice.
if(progressListener)
{
float fProgress = static_cast<float>(z) / static_cast<float>(volumeDepth);
progressListener->onProgressUpdated(fProgress);
}
for(uint16_t y = 0; y < volumeHeight; ++y)
{
for(uint16_t x = 0; x < volumeWidth; ++x)
{
if(runLength != 0)
{
volume.setVoxelAt(x,y,z,value);
runLength--;
}
else
{
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
stream.read(reinterpret_cast<char*>(&runLength), sizeof(runLength));
volume.setVoxelAt(x,y,z,value);
runLength--;
}
}
}
}
//Finished
if(progressListener)
{
progressListener->onProgressUpdated(1.0f);
}
return true;
}
template< typename VolumeType >
bool saveVersion0(std::ostream& stream, VolumeType& volume, VolumeSerializationProgressListener* progressListener)
{
//Write volume dimensions
uint16_t volumeWidth = volume.getWidth();
uint16_t volumeHeight = volume.getHeight();
uint16_t volumeDepth = volume.getDepth();
stream.write(reinterpret_cast<char*>(&volumeWidth), sizeof(volumeWidth));
stream.write(reinterpret_cast<char*>(&volumeHeight), sizeof(volumeHeight));
stream.write(reinterpret_cast<char*>(&volumeDepth), sizeof(volumeDepth));
//Write data
VolumeType::Sampler volIter(&volume);
VolumeType::VoxelType current;
uint32_t runLength = 0;
bool firstTime = true;
for(uint16_t z = 0; z < volumeDepth; ++z)
{
//Update progress once per slice.
if(progressListener)
{
float fProgress = static_cast<float>(z) / static_cast<float>(volumeDepth);
progressListener->onProgressUpdated(fProgress);
}
for(uint16_t y = 0; y < volumeHeight; ++y)
{
for(uint16_t x = 0; x < volumeWidth; ++x)
{
volIter.setPosition(x,y,z);
VolumeType::VoxelType value = volIter.getVoxel();
if(firstTime)
{
current = value;
runLength = 1;
firstTime = false;
}
else
{
if(value == current)
{
runLength++;
}
else
{
stream.write(reinterpret_cast<char*>(&current), sizeof(current));
stream.write(reinterpret_cast<char*>(&runLength), sizeof(runLength));
current = value;
runLength = 1;
}
}
}
}
}
stream.write(reinterpret_cast<char*>(&current), sizeof(current));
stream.write(reinterpret_cast<char*>(&runLength), sizeof(runLength));
//Finished
if(progressListener)
{
progressListener->onProgressUpdated(1.0f);
}
return true;
}
}

View File

@ -1,83 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __PolyVox_VolumeChangeTracker_H__
#define __PolyVox_VolumeChangeTracker_H__
#include "Impl/Utility.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/SurfaceMesh.h"
#include "PolyVoxCore/Vector.h"
namespace PolyVox
{
/// Voxel scene manager
/// \deprecated
template <typename VoxelType>
class POLYVOX_DEPRECATED VolumeChangeTracker
{
public:
//Constructors, etc
VolumeChangeTracker(LargeVolume<VoxelType>* volumeDataToSet, uint16_t regionSideLength);
~VolumeChangeTracker();
//Getters
int32_t getCurrentTime(void) const;
int32_t getLastModifiedTimeForRegion(uint16_t uX, uint16_t uY, uint16_t uZ);
LargeVolume<VoxelType>* getWrappedVolume(void) const;
//Setters
void setAllRegionsModified(void);
void setLockedVoxelAt(uint16_t x, uint16_t y, uint16_t z, VoxelType value);
void setVoxelAt(uint16_t x, uint16_t y, uint16_t z, VoxelType value);
//Others
void lockRegion(const Region& regToLock);
void unlockRegion(void);
//void markRegionChanged(uint16_t firstX, uint16_t firstY, uint16_t firstZ, uint16_t lastX, uint16_t lastY, uint16_t lastZ);
public:
void incrementCurrentTime(void);
bool m_bIsLocked;
Region m_regLastLocked;
LargeVolume<VoxelType>* volumeData;
uint16_t m_uRegionSideLength;
uint8_t m_uRegionSideLengthPower;
uint16_t m_uVolumeWidthInRegions;
uint16_t m_uVolumeHeightInRegions;
uint16_t m_uVolumeDepthInRegions;
//It's not what the block class was designed for, but it
//provides a handy way of storing a 3D grid of values.
LargeVolume<int32_t>* volRegionLastModified;
static uint32_t m_uCurrentTime;
};
}
#include "PolyVoxUtil/VolumeChangeTracker.inl"
#endif

View File

@ -1,212 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
namespace PolyVox
{
template <typename VoxelType>
uint32_t VolumeChangeTracker<VoxelType>::m_uCurrentTime = 0;
//////////////////////////////////////////////////////////////////////////
// VolumeChangeTracker
//////////////////////////////////////////////////////////////////////////
template <typename VoxelType>
VolumeChangeTracker<VoxelType>::VolumeChangeTracker(LargeVolume<VoxelType>* volumeDataToSet, uint16_t regionSideLength)
:m_bIsLocked(false)
,volumeData(0)
,m_uRegionSideLength(regionSideLength)
{
volumeData = volumeDataToSet;
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 LargeVolume<int32_t>(m_uVolumeWidthInRegions, m_uVolumeHeightInRegions, m_uVolumeDepthInRegions, 0);
}
template <typename VoxelType>
VolumeChangeTracker<VoxelType>::~VolumeChangeTracker()
{
}
template <typename VoxelType>
void VolumeChangeTracker<VoxelType>::setAllRegionsModified(void)
{
incrementCurrentTime();
for(uint16_t blockZ = 0; blockZ < m_uVolumeDepthInRegions; ++blockZ)
{
for(uint16_t blockY = 0; blockY < m_uVolumeHeightInRegions; ++blockY)
{
for(uint16_t blockX = 0; blockX < m_uVolumeWidthInRegions; ++blockX)
{
volRegionLastModified->setVoxelAt(blockX, blockY, blockZ, m_uCurrentTime);
}
}
}
}
template <typename VoxelType>
int32_t VolumeChangeTracker<VoxelType>::getCurrentTime(void) const
{
return m_uCurrentTime;
}
template <typename VoxelType>
int32_t VolumeChangeTracker<VoxelType>::getLastModifiedTimeForRegion(uint16_t uX, uint16_t uY, uint16_t uZ)
{
return volRegionLastModified->getVoxelAt(uX, uY, uZ);
}
template <typename VoxelType>
LargeVolume<VoxelType>* VolumeChangeTracker<VoxelType>::getWrappedVolume(void) const
{
return volumeData;
}
template <typename VoxelType>
void VolumeChangeTracker<VoxelType>::setVoxelAt(uint16_t x, uint16_t y, uint16_t z, VoxelType value)
{
//Note: We increase the time stamp both at the start and the end
//to avoid ambiguity about whether the timestamp comparison should
//be '<' vs '<=' or '>' vs '>=' in the users code.
incrementCurrentTime();
volumeData->setVoxelAt(x,y,z,value);
//If we are not on a boundary, just mark one region.
if((x % m_uRegionSideLength != 0) &&
(x % m_uRegionSideLength != m_uRegionSideLength-1) &&
(y % m_uRegionSideLength != 0) &&
(y % m_uRegionSideLength != m_uRegionSideLength-1) &&
(z % m_uRegionSideLength != 0) &&
(z % m_uRegionSideLength != m_uRegionSideLength-1))
{
volRegionLastModified->setVoxelAt(x >> m_uRegionSideLengthPower, y >> m_uRegionSideLengthPower, z >> m_uRegionSideLengthPower, m_uCurrentTime);
}
else //Mark surrounding regions as well
{
const uint16_t regionX = x >> m_uRegionSideLengthPower;
const uint16_t regionY = y >> m_uRegionSideLengthPower;
const uint16_t regionZ = z >> m_uRegionSideLengthPower;
const uint16_t minRegionX = (std::max)(uint16_t(0),uint16_t(regionX-1));
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_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++)
{
for(uint16_t yCt = minRegionY; yCt <= maxRegionY; yCt++)
{
for(uint16_t xCt = minRegionX; xCt <= maxRegionX; xCt++)
{
volRegionLastModified->setVoxelAt(xCt,yCt,zCt,m_uCurrentTime);
}
}
}
}
//Increment time stamp. See earlier note.
incrementCurrentTime();
}
template <typename VoxelType>
void VolumeChangeTracker<VoxelType>::setLockedVoxelAt(uint16_t x, uint16_t y, uint16_t z, VoxelType value)
{
assert(m_bIsLocked);
//FIXME - rather than creating a iterator each time we should have one stored
/*Sampler<VoxelType> iterVol(*volumeData);
iterVol.setPosition(x,y,z);
iterVol.setVoxel(value);*/
volumeData->setVoxelAt(x,y,z,value);
}
template <typename VoxelType>
void VolumeChangeTracker<VoxelType>::lockRegion(const Region& regToLock)
{
if(m_bIsLocked)
{
throw std::logic_error("A region is already locked. Please unlock it before locking another.");
}
m_regLastLocked = regToLock;
m_bIsLocked = true;
}
template <typename VoxelType>
void VolumeChangeTracker<VoxelType>::unlockRegion(void)
{
if(!m_bIsLocked)
{
throw std::logic_error("No region is locked. You must lock a region before you can unlock it.");
}
//Note: We increase the time stamp both at the start and the end
//to avoid ambiguity about whether the timestamp comparison should
//be '<' vs '<=' or '>' vs '>=' in the users code.
incrementCurrentTime();
const uint16_t firstRegionX = m_regLastLocked.getLowerCorner().getX() >> m_uRegionSideLengthPower;
const uint16_t firstRegionY = m_regLastLocked.getLowerCorner().getY() >> m_uRegionSideLengthPower;
const uint16_t firstRegionZ = m_regLastLocked.getLowerCorner().getZ() >> m_uRegionSideLengthPower;
const uint16_t lastRegionX = m_regLastLocked.getUpperCorner().getX() >> m_uRegionSideLengthPower;
const uint16_t lastRegionY = m_regLastLocked.getUpperCorner().getY() >> m_uRegionSideLengthPower;
const uint16_t lastRegionZ = m_regLastLocked.getUpperCorner().getZ() >> m_uRegionSideLengthPower;
for(uint16_t zCt = firstRegionZ; zCt <= lastRegionZ; zCt++)
{
for(uint16_t yCt = firstRegionY; yCt <= lastRegionY; yCt++)
{
for(uint16_t xCt = firstRegionX; xCt <= lastRegionX; xCt++)
{
volRegionLastModified->setVoxelAt(xCt,yCt,zCt,m_uCurrentTime);
}
}
}
m_bIsLocked = false;
//Increment time stamp. See earlier note.
incrementCurrentTime();
}
template <typename VoxelType>
void VolumeChangeTracker<VoxelType>::incrementCurrentTime(void)
{
//Increment the current time.
uint32_t time = m_uCurrentTime++;
//Watch out for wraparound. Hopefully this will never happen
//as we have a pretty big counter, but it's best to be sure...
assert(time < m_uCurrentTime);
if(time >= m_uCurrentTime)
{
throw std::overflow_error("The VolumeChangeTracker time has overflowed.");
}
}
}