More work on handling fixed size volumes.
This commit is contained in:
parent
596dcf507e
commit
529ed89bdb
@ -48,7 +48,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void CubicSurfaceExtractor<VoxelType>::execute()
|
||||
{
|
||||
uint32_t arraySize[3]= {m_regSizeInVoxels.width()+2, m_regSizeInVoxels.height()+2, MaxQuadsSharingVertex};
|
||||
uint32_t arraySize[3]= {m_regSizeInVoxels.getWidth()+2, m_regSizeInVoxels.getHeight()+2, MaxQuadsSharingVertex};
|
||||
m_previousSliceVertices.resize(arraySize);
|
||||
m_currentSliceVertices.resize(arraySize);
|
||||
memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial));
|
||||
|
@ -7,7 +7,7 @@ namespace PolyVox
|
||||
{
|
||||
Region croppedRegion = regionToSmooth;
|
||||
|
||||
Array<3, uint16_t> temp(ArraySizes(croppedRegion.width())(croppedRegion.height())(croppedRegion.depth()));
|
||||
Array<3, uint16_t> temp(ArraySizes(croppedRegion.getWidth())(croppedRegion.getHeight())(croppedRegion.getDepth()));
|
||||
|
||||
for (int z = croppedRegion.getLowerCorner().getZ(); z < croppedRegion.getUpperCorner().getZ(); z++)
|
||||
{
|
||||
|
@ -36,25 +36,35 @@ namespace PolyVox
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
|
||||
const static Region MaxRegion;
|
||||
|
||||
Region();
|
||||
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
|
||||
|
||||
uint32_t getDepth(void) const;
|
||||
Vector3DUint32 getDimensions(void);
|
||||
uint32_t getHeight(void) const;
|
||||
const Vector3DInt32& getLowerCorner(void) const;
|
||||
const Vector3DInt32& getUpperCorner(void) const;
|
||||
uint32_t getWidth(void) const;
|
||||
|
||||
void setLowerCorner(const Vector3DInt32& v3dLowerCorner);
|
||||
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
|
||||
void setToMaxSize(void);
|
||||
|
||||
bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const;
|
||||
bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const;
|
||||
void cropTo(const Region& other);
|
||||
/// Deprecated and wrong by 1 - use getDepth() instead.
|
||||
int32_t depth(void) const;
|
||||
/// Deprecated and wrong by 1 - use getHeight() instead.
|
||||
int32_t height(void) const;
|
||||
void shift(const Vector3DInt32& amount);
|
||||
void shiftLowerCorner(const Vector3DInt32& amount);
|
||||
void shiftUpperCorner(const Vector3DInt32& amount);
|
||||
/// Deprecated and wrong by 1 - use getDimensions() instead.
|
||||
Vector3DInt32 dimensions(void);
|
||||
/// Deprecated and wrong by 1 - use getWidth() instead.
|
||||
int32_t width(void) const;
|
||||
|
||||
private:
|
||||
|
@ -46,7 +46,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
void SurfaceExtractor<VoxelType>::execute()
|
||||
{
|
||||
uint32_t arraySizes[2]= {m_regSizeInVoxels.width()+1, m_regSizeInVoxels.height()+1}; // Array dimensions
|
||||
uint32_t arraySizes[2]= {m_regSizeInVoxels.getWidth(), m_regSizeInVoxels.getHeight()}; // Array dimensions
|
||||
|
||||
//For edge indices
|
||||
Array2DInt32 m_pPreviousVertexIndicesX(arraySizes);
|
||||
|
@ -124,6 +124,8 @@ namespace PolyVox
|
||||
/// Constructor
|
||||
Volume(uint16_t uBlockSideLength = 32);
|
||||
/// Constructor
|
||||
Volume(const Region& regValid, uint16_t uBlockSideLength = 32);
|
||||
/// Constructor
|
||||
Volume(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength = 32);
|
||||
/// Destructor
|
||||
~Volume();
|
||||
@ -163,9 +165,9 @@ namespace PolyVox
|
||||
void clearBlockCache(void);
|
||||
float calculateCompressionRatio(void);
|
||||
uint32_t calculateSizeInBytes(void);
|
||||
/// Resizes the volume to the specified dimensions
|
||||
void resize(uint16_t uBlockSideLength = 32);
|
||||
void resize(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength);
|
||||
|
||||
/// Deprecated - I don't think we should expose this function? Let us know if you disagree...
|
||||
void resize(const Region& regValidRegion, uint16_t uBlockSideLength);
|
||||
/// gets called when a new region is allocated and needs to be filled
|
||||
/// NOTE: accessing ANY voxels outside this region during the process of this function
|
||||
/// is absolutely unsafe
|
||||
@ -202,37 +204,15 @@ namespace PolyVox
|
||||
//the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume.
|
||||
VoxelType* m_pUncompressedBorderData;
|
||||
|
||||
/*int32_t m_uMinX;
|
||||
int32_t m_uMinY;
|
||||
int32_t m_uMinZ;
|
||||
|
||||
int32_t m_uMaxX;
|
||||
int32_t m_uMaxY;
|
||||
int32_t m_uMaxZ;*/
|
||||
|
||||
//The size of the volume
|
||||
Region m_regValidRegion;
|
||||
|
||||
/*int32_t m_uBlockMinX;
|
||||
int32_t m_uBlockMinY;
|
||||
int32_t m_uBlockMinZ;
|
||||
|
||||
int32_t m_uBlockMaxX;
|
||||
int32_t m_uBlockMaxY;
|
||||
int32_t m_uBlockMaxZ;*/
|
||||
|
||||
Region m_regValidRegionInBlocks;
|
||||
|
||||
int32_t m_uWidthInBlocks;
|
||||
int32_t m_uHeightInBlocks;
|
||||
int32_t m_uDepthInBlocks;
|
||||
|
||||
int32_t m_uWidth;
|
||||
int32_t m_uHeight;
|
||||
int32_t m_uDepth;
|
||||
|
||||
uint8_t m_uBlockSideLengthPower;
|
||||
//The size of the blocks
|
||||
uint16_t m_uBlockSideLength;
|
||||
uint8_t m_uBlockSideLengthPower;
|
||||
|
||||
//Some useful sizes
|
||||
int32_t m_uLongestSideLength;
|
||||
int32_t m_uShortestSideLength;
|
||||
float m_fDiagonalLength;
|
||||
|
@ -49,23 +49,9 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
Volume<VoxelType>::Volume(uint16_t uBlockSideLength)
|
||||
:
|
||||
m_uTimestamper(0)
|
||||
,m_uMaxUncompressedBlockCacheSize(256)
|
||||
,m_uMaxBlocksLoaded(4096)
|
||||
,m_uBlockSideLength(uBlockSideLength)
|
||||
,m_pUncompressedBorderData(0)
|
||||
,m_v3dLastAccessedBlockPos((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)()) //An invalid index
|
||||
{
|
||||
setBlockCacheSize(m_uMaxUncompressedBlockCacheSize);
|
||||
|
||||
m_regValidRegion.setToMaxSize();
|
||||
|
||||
m_regValidRegionInBlocks.setLowerCorner(m_regValidRegion.getLowerCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
m_regValidRegionInBlocks.setUpperCorner(m_regValidRegion.getUpperCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
|
||||
//Create a volume of the right size.
|
||||
resize(uBlockSideLength);
|
||||
resize(Region::MaxRegion,uBlockSideLength);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -82,23 +68,28 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
Volume<VoxelType>::Volume(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength)
|
||||
:m_uTimestamper(0)
|
||||
,m_uMaxUncompressedBlockCacheSize(256)
|
||||
,m_uBlockSideLength(uBlockSideLength)
|
||||
,m_pUncompressedBorderData(0)
|
||||
,m_uMaxBlocksLoaded(4096)
|
||||
,m_v3dLastAccessedBlockPos((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)()) //An invalid index
|
||||
{
|
||||
setBlockCacheSize(m_uMaxUncompressedBlockCacheSize);
|
||||
|
||||
m_regValidRegion.setLowerCorner(Vector3DInt32(0,0,0));
|
||||
m_regValidRegion.setUpperCorner(Vector3DInt32(uWidth - 1,uHeight - 1,uDepth - 1));
|
||||
|
||||
m_regValidRegionInBlocks.setLowerCorner(m_regValidRegion.getLowerCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
m_regValidRegionInBlocks.setUpperCorner(m_regValidRegion.getUpperCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
Region regValid(Vector3DInt32(0,0,0), Vector3DInt32(uWidth - 1,uHeight - 1,uDepth - 1));
|
||||
resize(Region(Vector3DInt32(0,0,0), Vector3DInt32(uWidth - 1,uHeight - 1,uDepth - 1)), uBlockSideLength);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Builds a volume of the desired dimensions
|
||||
/// \param uWidth The desired width in voxels. This must be a power of two.
|
||||
/// \param uHeight The desired height in voxels. This must be a power of two.
|
||||
/// \param uDepth The desired depth in voxels. This must be a power of two.
|
||||
/// \param uBlockSideLength The size of the blocks which make up the volume. Small
|
||||
/// blocks are more likely to be homogeneous (so more easily shared) and have better
|
||||
/// cache behaviour. However, there is a memory overhead per block so if they are
|
||||
/// not shared it could actually be less efficient (this will depend on the data).
|
||||
/// The size of the volume may also be a factor when choosing block size. Accept
|
||||
/// the default if you are not sure what to choose here.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
Volume<VoxelType>::Volume(const Region& regValid, uint16_t uBlockSideLength)
|
||||
{
|
||||
//Create a volume of the right size.
|
||||
resize(uWidth, uHeight, uDepth, uBlockSideLength);
|
||||
resize(regValid,uBlockSideLength);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -121,8 +112,6 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
VoxelType Volume<VoxelType>::getBorderValue(void) const
|
||||
{
|
||||
/*Block<VoxelType>* pUncompressedBorderBlock = getUncompressedBlock(const_cast<Block<VoxelType>*>(&m_pBorderBlock));
|
||||
return pUncompressedBorderBlock->getVoxelAt(0,0,0);*/
|
||||
return *m_pUncompressedBorderData;
|
||||
}
|
||||
|
||||
@ -135,7 +124,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
Region Volume<VoxelType>::getEnclosingRegion(void) const
|
||||
{
|
||||
return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uWidth-1,m_uHeight-1,m_uDepth-1));
|
||||
return m_regValidRegion;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -145,7 +134,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t Volume<VoxelType>::getWidth(void) const
|
||||
{
|
||||
return m_uWidth;
|
||||
return m_regValidRegion.getWidth();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -155,7 +144,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t Volume<VoxelType>::getHeight(void) const
|
||||
{
|
||||
return m_uHeight;
|
||||
return m_regValidRegion.getHeight();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -165,7 +154,7 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
int32_t Volume<VoxelType>::getDepth(void) const
|
||||
{
|
||||
return m_uDepth;
|
||||
return m_regValidRegion.getDepth();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -210,6 +199,8 @@ namespace PolyVox
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
VoxelType Volume<VoxelType>::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const
|
||||
{
|
||||
if(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)))
|
||||
{
|
||||
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
@ -223,6 +214,11 @@ namespace PolyVox
|
||||
|
||||
return pUncompressedBlock->getVoxelAt(xOffset,yOffset,zOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
return getBorderValue();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// \param v3dPos the 3D position of the voxel
|
||||
@ -293,6 +289,8 @@ namespace PolyVox
|
||||
template <typename VoxelType>
|
||||
bool Volume<VoxelType>::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue)
|
||||
{
|
||||
assert(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)));
|
||||
|
||||
const int32_t blockX = uXPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockY = uYPos >> m_uBlockSideLengthPower;
|
||||
const int32_t blockZ = uZPos >> m_uBlockSideLengthPower;
|
||||
@ -331,43 +329,6 @@ namespace PolyVox
|
||||
m_vecUncompressedBlockCache.clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Note: Calling this function will destroy all existing data in the volume.
|
||||
/// \param uBlockSideLength The size of the blocks which make up the volume. Small
|
||||
/// blocks are more likely to be homogeneous (so more easily shared) and have better
|
||||
/// cache behaviour. However, there is a memory overhead per block so if they are
|
||||
/// not shared it could actually be less efficient (this will depend on the data).
|
||||
/// The size of the volume may also be a factor when choosing block size. Accept
|
||||
/// the default if you are not sure what to choose here.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void Volume<VoxelType>::resize(uint16_t uBlockSideLength)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(uBlockSideLength > 0);
|
||||
assert(isPowerOf2(uBlockSideLength));
|
||||
|
||||
//Release mode validation
|
||||
if(uBlockSideLength == 0)
|
||||
{
|
||||
throw std::invalid_argument("Block side length cannot be zero.");
|
||||
}
|
||||
if(!isPowerOf2(uBlockSideLength))
|
||||
{
|
||||
throw std::invalid_argument("Block side length must be a power of two.");
|
||||
}
|
||||
|
||||
//Clear the previous data
|
||||
m_pBlocks.clear();
|
||||
m_pUncompressedTimestamps.clear();
|
||||
|
||||
m_pUncompressedTimestamps.resize(m_uMaxUncompressedBlockCacheSize, 0);
|
||||
|
||||
//Compute the block side length
|
||||
m_uBlockSideLength = uBlockSideLength;
|
||||
m_uBlockSideLengthPower = logBase2(m_uBlockSideLength);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// Note: Calling this function will destroy all existing data in the volume.
|
||||
/// \param uWidth The desired width in voxels. This must be a power of two.
|
||||
@ -381,17 +342,10 @@ namespace PolyVox
|
||||
/// the default if you are not sure what to choose here.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
void Volume<VoxelType>::resize(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength)
|
||||
void Volume<VoxelType>::resize(const Region& regValidRegion, uint16_t uBlockSideLength)
|
||||
{
|
||||
//Debug mode validation
|
||||
assert(uBlockSideLength > 0);
|
||||
assert(isPowerOf2(uBlockSideLength));
|
||||
assert(uBlockSideLength <= uWidth);
|
||||
assert(uBlockSideLength <= uHeight);
|
||||
assert(uBlockSideLength <= uDepth);
|
||||
assert(0 < uWidth);
|
||||
assert(0 < uHeight);
|
||||
assert(0 < uDepth);
|
||||
|
||||
//Release mode validation
|
||||
if(uBlockSideLength == 0)
|
||||
@ -402,49 +356,29 @@ namespace PolyVox
|
||||
{
|
||||
throw std::invalid_argument("Block side length must be a power of two.");
|
||||
}
|
||||
if(uBlockSideLength > uWidth)
|
||||
{
|
||||
throw std::invalid_argument("Block side length cannot be greater than volume width.");
|
||||
}
|
||||
if(uBlockSideLength > uHeight)
|
||||
{
|
||||
throw std::invalid_argument("Block side length cannot be greater than volume height.");
|
||||
}
|
||||
if(uBlockSideLength > uDepth)
|
||||
{
|
||||
throw std::invalid_argument("Block side length cannot be greater than volume depth.");
|
||||
}
|
||||
if(0 >= uWidth)
|
||||
{
|
||||
throw std::invalid_argument("Volume width cannot be smaller than 1.");
|
||||
}
|
||||
if(0 >= uHeight)
|
||||
{
|
||||
throw std::invalid_argument("Volume height cannot be smaller than 1.");
|
||||
}
|
||||
if(0 >= uDepth)
|
||||
{
|
||||
throw std::invalid_argument("Volume depth cannot be smaller than 1.");
|
||||
}
|
||||
|
||||
m_uTimestamper = 0;
|
||||
m_uMaxUncompressedBlockCacheSize = 256;
|
||||
m_uBlockSideLength = uBlockSideLength;
|
||||
m_pUncompressedBorderData = 0;
|
||||
m_uMaxBlocksLoaded = 4096;
|
||||
m_v3dLastAccessedBlockPos = Vector3DInt32((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)()); //An invalid index
|
||||
|
||||
m_regValidRegion = regValidRegion;
|
||||
|
||||
m_regValidRegionInBlocks.setLowerCorner(m_regValidRegion.getLowerCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
m_regValidRegionInBlocks.setUpperCorner(m_regValidRegion.getUpperCorner() / static_cast<int32_t>(uBlockSideLength));
|
||||
|
||||
setBlockCacheSize(m_uMaxUncompressedBlockCacheSize);
|
||||
|
||||
//Clear the previous data
|
||||
m_pBlocks.clear();
|
||||
m_pUncompressedTimestamps.clear();
|
||||
|
||||
//Compute the volume side lengths
|
||||
m_uWidth = uWidth;
|
||||
m_uHeight = uHeight;
|
||||
m_uDepth = uDepth;
|
||||
|
||||
//Compute the block side length
|
||||
m_uBlockSideLength = uBlockSideLength;
|
||||
m_uBlockSideLengthPower = logBase2(m_uBlockSideLength);
|
||||
|
||||
//Compute the side lengths in blocks
|
||||
m_uWidthInBlocks = m_uWidth / m_uBlockSideLength;
|
||||
m_uHeightInBlocks = m_uHeight / m_uBlockSideLength;
|
||||
m_uDepthInBlocks = m_uDepth / m_uBlockSideLength;
|
||||
|
||||
//Clear the previous data
|
||||
m_pBlocks.clear();
|
||||
m_pUncompressedTimestamps.clear();
|
||||
@ -456,9 +390,9 @@ namespace PolyVox
|
||||
std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength, VoxelType());
|
||||
|
||||
//Other properties we might find useful later
|
||||
m_uLongestSideLength = (std::max)((std::max)(m_uWidth,m_uHeight),m_uDepth);
|
||||
m_uShortestSideLength = (std::min)((std::min)(m_uWidth,m_uHeight),m_uDepth);
|
||||
m_fDiagonalLength = sqrtf(static_cast<float>(m_uWidth * m_uWidth + m_uHeight * m_uHeight + m_uDepth * m_uDepth));
|
||||
m_uLongestSideLength = (std::max)((std::max)(getWidth(),getHeight()),getDepth());
|
||||
m_uShortestSideLength = (std::min)((std::min)(getWidth(),getHeight()),getDepth());
|
||||
m_fDiagonalLength = sqrtf(static_cast<float>(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth()));
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
|
@ -153,15 +153,8 @@ namespace PolyVox
|
||||
uYPosInBlock * mVolume->m_uBlockSideLength +
|
||||
uZPosInBlock * mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength;
|
||||
|
||||
//if((uXBlock < mVolume->m_uWidthInBlocks) && (uYBlock < mVolume->m_uHeightInBlocks) && (uZBlock < mVolume->m_uDepthInBlocks) && (uXBlock >= 0) && (uYBlock >= 0) && (uZBlock >=0))
|
||||
//if((uXBlock <= mVolume->m_uBlockMaxX) && (uYBlock <= mVolume->m_uBlockMaxY) && (uZBlock <= mVolume->m_uBlockMaxZ) && (uXBlock >= mVolume->m_uBlockMinX) && (uYBlock >= mVolume->m_uBlockMinY) && (uZBlock >= mVolume->m_uBlockMinZ))
|
||||
if(mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock)))
|
||||
{
|
||||
/*const uint32_t uBlockIndexInVolume = uXBlock +
|
||||
uYBlock * mVolume->m_uWidthInBlocks +
|
||||
uZBlock * mVolume->m_uWidthInBlocks * mVolume->m_uHeightInBlocks;
|
||||
const Block<VoxelType>& currentBlock = mVolume->m_pBlocks[uBlockIndexInVolume];*/
|
||||
|
||||
Block<VoxelType>* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock);
|
||||
|
||||
mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock;
|
||||
|
@ -25,6 +25,13 @@ freely, subject to the following restrictions:
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
const Region Region::MaxRegion
|
||||
(
|
||||
Vector3DInt32((std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)(), (std::numeric_limits<int32_t>::min)()),
|
||||
Vector3DInt32((std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)(), (std::numeric_limits<int32_t>::max)())
|
||||
);
|
||||
|
||||
|
||||
Region::Region()
|
||||
:m_v3dLowerCorner(0,0,0)
|
||||
,m_v3dUpperCorner(0,0,0)
|
||||
@ -35,6 +42,36 @@ namespace PolyVox
|
||||
:m_v3dLowerCorner(v3dLowerCorner)
|
||||
,m_v3dUpperCorner(v3dUpperCorner)
|
||||
{
|
||||
//Check the region is valid.
|
||||
assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
|
||||
assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
|
||||
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
|
||||
}
|
||||
|
||||
uint32_t Region::getDepth(void) const
|
||||
{
|
||||
//We're returning the result as unsigned, so ensure that
|
||||
//the upper value is at least as big as the lower value.
|
||||
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
|
||||
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ() + 1;
|
||||
}
|
||||
|
||||
Vector3DUint32 Region::getDimensions(void)
|
||||
{
|
||||
//We're returning the result as unsigned, so ensure that
|
||||
//the upper value is at least as big as the lower value.
|
||||
assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
|
||||
assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
|
||||
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
|
||||
return static_cast<Vector3DUint32>(m_v3dUpperCorner - m_v3dLowerCorner) + Vector3DUint32(1,1,1);
|
||||
}
|
||||
|
||||
uint32_t Region::getHeight(void) const
|
||||
{
|
||||
//We're returning the result as unsigned, so ensure that
|
||||
//the upper value is at least as big as the lower value.
|
||||
assert(m_v3dUpperCorner.getY() >= m_v3dLowerCorner.getY());
|
||||
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY() + 1;
|
||||
}
|
||||
|
||||
const Vector3DInt32& Region::getLowerCorner(void) const
|
||||
@ -47,6 +84,14 @@ namespace PolyVox
|
||||
return m_v3dUpperCorner;
|
||||
}
|
||||
|
||||
uint32_t Region::getWidth(void) const
|
||||
{
|
||||
//We're returning the result as unsigned, so ensure that
|
||||
//the upper value is at least as big as the lower value.
|
||||
assert(m_v3dUpperCorner.getX() >= m_v3dLowerCorner.getX());
|
||||
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX() + 1;
|
||||
}
|
||||
|
||||
void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner)
|
||||
{
|
||||
m_v3dLowerCorner = v3dLowerCorner;
|
||||
@ -57,14 +102,6 @@ namespace PolyVox
|
||||
m_v3dUpperCorner = v3dUpperCorner;
|
||||
}
|
||||
|
||||
void Region::setToMaxSize(void)
|
||||
{
|
||||
int32_t iMin = (std::numeric_limits<int32_t>::min)();
|
||||
int32_t iMax = (std::numeric_limits<int32_t>::max)();
|
||||
m_v3dLowerCorner = Vector3DInt32(iMin, iMin,iMin);
|
||||
m_v3dUpperCorner = Vector3DInt32(iMax, iMax,iMax);
|
||||
}
|
||||
|
||||
bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
|
||||
{
|
||||
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
|
||||
@ -97,11 +134,15 @@ namespace PolyVox
|
||||
|
||||
int32_t Region::depth(void) const
|
||||
{
|
||||
//This function is deprecated and wrong. Use getDepth() instead.
|
||||
assert(false);
|
||||
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
|
||||
}
|
||||
|
||||
int32_t Region::height(void) const
|
||||
{
|
||||
//This function is deprecated and wrong. Use getHeight() instead.
|
||||
assert(false);
|
||||
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
|
||||
}
|
||||
|
||||
@ -123,11 +164,15 @@ namespace PolyVox
|
||||
|
||||
Vector3DInt32 Region::dimensions(void)
|
||||
{
|
||||
//This function is deprecated and wrong. Use getDimensions() instead.
|
||||
assert(false);
|
||||
return m_v3dUpperCorner - m_v3dLowerCorner;
|
||||
}
|
||||
|
||||
int32_t Region::width(void) const
|
||||
{
|
||||
//This function is deprecated and wrong. Use getWidth() instead.
|
||||
assert(false);
|
||||
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,8 @@ namespace PolyVox
|
||||
stream.read(reinterpret_cast<char*>(&volumeDepth), sizeof(volumeDepth));
|
||||
|
||||
//Resize the volume
|
||||
volume.resize(volumeWidth, volumeHeight, volumeDepth);
|
||||
//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, volumeHeight, volumeDepth)), 32);
|
||||
|
||||
//Read data
|
||||
bool firstTime = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user