Index: tests/testvolume.cpp =================================================================== --- tests/testvolume.cpp (revision 1408) +++ tests/testvolume.cpp (working copy) @@ -31,15 +31,15 @@ void TestVolume::testSize() { - const uint16_t g_uVolumeSideLength = 128; + const int32_t g_uVolumeSideLength = 128; Volume volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength); //Note: Deliberatly go past each edge by one to test if the bounds checking works. - for (uint16_t z = 0; z < g_uVolumeSideLength + 1; z++) + for (int32_t z = 0; z < g_uVolumeSideLength + 1; z++) { - for (uint16_t y = 0; y < g_uVolumeSideLength + 1; y++) + for (int32_t y = 0; y < g_uVolumeSideLength + 1; y++) { - for (uint16_t x = 0; x < g_uVolumeSideLength + 1; x++) + for (int32_t x = 0; x < g_uVolumeSideLength + 1; x++) { volData.setVoxelAt(x,y,z,255); } Index: library/PolyVoxCore/source/Region.cpp =================================================================== --- library/PolyVoxCore/source/Region.cpp (revision 1408) +++ library/PolyVoxCore/source/Region.cpp (working copy) @@ -31,28 +31,28 @@ { } - Region::Region(const Vector3DInt16& v3dLowerCorner, const Vector3DInt16& v3dUpperCorner) + Region::Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner) :m_v3dLowerCorner(v3dLowerCorner) ,m_v3dUpperCorner(v3dUpperCorner) { } - const Vector3DInt16& Region::getLowerCorner(void) const + const Vector3DInt32& Region::getLowerCorner(void) const { return m_v3dLowerCorner; } - const Vector3DInt16& Region::getUpperCorner(void) const + const Vector3DInt32& Region::getUpperCorner(void) const { return m_v3dUpperCorner; } - void Region::setLowerCorner(const Vector3DInt16& v3dLowerCorner) + void Region::setLowerCorner(const Vector3DInt32& v3dLowerCorner) { m_v3dLowerCorner = v3dLowerCorner; } - void Region::setUpperCorner(const Vector3DInt16& v3dUpperCorner) + void Region::setUpperCorner(const Vector3DInt32& v3dUpperCorner) { m_v3dUpperCorner = v3dUpperCorner; } @@ -67,7 +67,7 @@ && (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary); } - bool Region::containsPoint(const Vector3DInt16& pos, uint8_t boundary) const + bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const { return (pos.getX() <= m_v3dUpperCorner.getX() - boundary) && (pos.getY() <= m_v3dUpperCorner.getY() - boundary) @@ -87,38 +87,38 @@ m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ())); } - int16_t Region::depth(void) const + int32_t Region::depth(void) const { return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ(); } - int16_t Region::height(void) const + int32_t Region::height(void) const { return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY(); } - void Region::shift(const Vector3DInt16& amount) + void Region::shift(const Vector3DInt32& amount) { m_v3dLowerCorner += amount; m_v3dUpperCorner += amount; } - void Region::shiftLowerCorner(const Vector3DInt16& amount) + void Region::shiftLowerCorner(const Vector3DInt32& amount) { m_v3dLowerCorner += amount; } - void Region::shiftUpperCorner(const Vector3DInt16& amount) + void Region::shiftUpperCorner(const Vector3DInt32& amount) { m_v3dUpperCorner += amount; } - Vector3DInt16 Region::dimensions(void) + Vector3DInt32 Region::dimensions(void) { return m_v3dUpperCorner - m_v3dLowerCorner; } - int16_t Region::width(void) const + int32_t Region::width(void) const { return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX(); } Index: library/PolyVoxCore/source/GradientEstimators.cpp =================================================================== --- library/PolyVoxCore/source/GradientEstimators.cpp (revision 1408) +++ library/PolyVoxCore/source/GradientEstimators.cpp (working copy) @@ -37,13 +37,13 @@ while(iterSurfaceVertex != vecVertices.end()) { const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast(mesh.m_Region.getLowerCorner()); - const Vector3DInt16 v3dFloor = static_cast(v3dPos); + const Vector3DInt32 v3dFloor = static_cast(v3dPos); VolumeSampler volIter(volumeData); //Check all corners are within the volume, allowing a boundary for gradient estimation bool lowerCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor,2); - bool upperCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor+Vector3DInt16(1,1,1),2); + bool upperCornerInside = volumeData->getEnclosingRegion().containsPoint(v3dFloor+Vector3DInt32(1,1,1),2); if(lowerCornerInside && upperCornerInside) //If this test fails the vertex will be left as it was { @@ -69,7 +69,7 @@ const Vector3DInt32 v3dFloor = static_cast(v3dPos); - volIter.setPosition(static_cast(v3dFloor)); + volIter.setPosition(static_cast(v3dFloor)); Vector3DFloat gradFloor; switch(normalGenerationMethod) { @@ -89,15 +89,15 @@ if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5 { - volIter.setPosition(static_cast(v3dFloor+Vector3DInt32(1,0,0))); + volIter.setPosition(static_cast(v3dFloor+Vector3DInt32(1,0,0))); } if((v3dPos.getY() - v3dFloor.getY()) > 0.25) //The result should be 0.0 or 0.5 { - volIter.setPosition(static_cast(v3dFloor+Vector3DInt32(0,1,0))); + volIter.setPosition(static_cast(v3dFloor+Vector3DInt32(0,1,0))); } if((v3dPos.getZ() - v3dFloor.getZ()) > 0.25) //The result should be 0.0 or 0.5 { - volIter.setPosition(static_cast(v3dFloor+Vector3DInt32(0,0,1))); + volIter.setPosition(static_cast(v3dFloor+Vector3DInt32(0,0,1))); } Vector3DFloat gradCeil; @@ -126,7 +126,7 @@ if(normalGenerationMethod == SIMPLE) { - volIter.setPosition(static_cast(v3dFloor)); + volIter.setPosition(static_cast(v3dFloor)); const uint8_t uFloor = volIter.getVoxel() > 0 ? 1 : 0; if((v3dPos.getX() - v3dFloor.getX()) > 0.25) //The result should be 0.0 or 0.5 { Index: library/PolyVoxCore/include/VolumeSampler.h =================================================================== --- library/PolyVoxCore/include/VolumeSampler.h (revision 1408) +++ library/PolyVoxCore/include/VolumeSampler.h (working copy) @@ -37,15 +37,15 @@ VolumeSampler& operator=(const VolumeSampler& rhs) throw(); - uint16_t getPosX(void) const; - uint16_t getPosY(void) const; - uint16_t getPosZ(void) const; + int32_t getPosX(void) const; + int32_t getPosY(void) const; + int32_t getPosZ(void) const; VoxelType getSubSampledVoxel(uint8_t uLevel) const; const Volume* getVolume(void) const; inline VoxelType getVoxel(void) const; - void setPosition(const Vector3DInt16& v3dNewPos); - void setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos); + void setPosition(const Vector3DInt32& v3dNewPos); + void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); void movePositiveX(void); void movePositiveY(void); @@ -91,9 +91,9 @@ Volume* mVolume; //The current position in the volume - uint16_t mXPosInVolume; - uint16_t mYPosInVolume; - uint16_t mZPosInVolume; + int32_t mXPosInVolume; + int32_t mYPosInVolume; + int32_t mZPosInVolume; //Other current position information VoxelType* mCurrentVoxel; Index: library/PolyVoxCore/include/Volume.inl =================================================================== --- library/PolyVoxCore/include/Volume.inl (revision 1408) +++ library/PolyVoxCore/include/Volume.inl (working copy) @@ -27,6 +27,7 @@ #include "Region.h" #include "Vector.h" +#include #include #include //For memcpy #include @@ -47,7 +48,7 @@ /// the default if you are not sure what to choose here. //////////////////////////////////////////////////////////////////////////////// template - Volume::Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength) + Volume::Volume(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength) :m_uTimestamper(0) ,m_uMaxUncompressedBlockCacheSize(256) ,m_uBlockSideLength(uBlockSideLength) @@ -90,7 +91,7 @@ template Region Volume::getEnclosingRegion(void) const { - return Region(Vector3DInt16(0,0,0), Vector3DInt16(m_uWidth-1,m_uHeight-1,m_uDepth-1)); + return Region(Vector3DInt32(0,0,0), Vector3DInt32(m_uWidth-1,m_uHeight-1,m_uDepth-1)); } //////////////////////////////////////////////////////////////////////////////// @@ -98,7 +99,7 @@ /// \sa getHeight(), getDepth() //////////////////////////////////////////////////////////////////////////////// template - uint16_t Volume::getWidth(void) const + int32_t Volume::getWidth(void) const { return m_uWidth; } @@ -108,7 +109,7 @@ /// \sa getWidth(), getDepth() //////////////////////////////////////////////////////////////////////////////// template - uint16_t Volume::getHeight(void) const + int32_t Volume::getHeight(void) const { return m_uHeight; } @@ -118,7 +119,7 @@ /// \sa getWidth(), getHeight() //////////////////////////////////////////////////////////////////////////////// template - uint16_t Volume::getDepth(void) const + int32_t Volume::getDepth(void) const { return m_uDepth; } @@ -129,7 +130,7 @@ /// \sa getLongestSideLength(), getDiagonalLength() //////////////////////////////////////////////////////////////////////////////// template - uint16_t Volume::getShortestSideLength(void) const + int32_t Volume::getShortestSideLength(void) const { return m_uShortestSideLength; } @@ -140,7 +141,7 @@ /// \sa getShortestSideLength(), getDiagonalLength() //////////////////////////////////////////////////////////////////////////////// template - uint16_t Volume::getLongestSideLength(void) const + int32_t Volume::getLongestSideLength(void) const { return m_uLongestSideLength; } @@ -164,15 +165,15 @@ /// \return the voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const + VoxelType Volume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { //We don't use getEnclosingRegion here because we care - //about speed and don't need to check the lower bound. - if((uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth())) + //about speed + if((uXPos >=0) && (uYPos >=0) && (uZPos >=0) && (uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth())) { - const uint16_t blockX = uXPos >> m_uBlockSideLengthPower; - const uint16_t blockY = uYPos >> m_uBlockSideLengthPower; - const uint16_t blockZ = uZPos >> m_uBlockSideLengthPower; + const int32_t blockX = uXPos >> m_uBlockSideLengthPower; + const int32_t blockY = uYPos >> m_uBlockSideLengthPower; + const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower); const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower); @@ -193,7 +194,7 @@ /// \return the voxel value //////////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::getVoxelAt(const Vector3DUint16& v3dPos) const + VoxelType Volume::getVoxelAt(const Vector3DInt32& v3dPos) const { return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } @@ -231,15 +232,15 @@ /// \return whether the requested position is inside the volume //////////////////////////////////////////////////////////////////////////////// template - bool Volume::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue) + bool Volume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { //We don't use getEnclosingRegion here because we care - //about speed and don't need to check the lower bound. - if((uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth())) + //about speed + if((uXPos >=0) && (uYPos >=0) && (uZPos >=0) && (uXPos < getWidth()) && (uYPos < getHeight()) && (uZPos < getDepth())) { - const uint16_t blockX = uXPos >> m_uBlockSideLengthPower; - const uint16_t blockY = uYPos >> m_uBlockSideLengthPower; - const uint16_t blockZ = uZPos >> m_uBlockSideLengthPower; + const int32_t blockX = uXPos >> m_uBlockSideLengthPower; + const int32_t blockY = uYPos >> m_uBlockSideLengthPower; + const int32_t blockZ = uZPos >> m_uBlockSideLengthPower; const uint16_t xOffset = uXPos - (blockX << m_uBlockSideLengthPower); const uint16_t yOffset = uYPos - (blockY << m_uBlockSideLengthPower); @@ -265,7 +266,7 @@ /// \return whether the requested position is inside the volume //////////////////////////////////////////////////////////////////////////////// template - bool Volume::setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue) + bool Volume::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) { return setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); } @@ -294,7 +295,7 @@ /// the default if you are not sure what to choose here. //////////////////////////////////////////////////////////////////////////////// template - void Volume::resize(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength) + void Volume::resize(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength) { //Debug mode validation assert(uBlockSideLength > 0); @@ -302,6 +303,9 @@ assert(uBlockSideLength <= uWidth); assert(uBlockSideLength <= uHeight); assert(uBlockSideLength <= uDepth); + assert(0 < uWidth); + assert(0 < uHeight); + assert(0 < uDepth); //Release mode validation if(uBlockSideLength == 0) @@ -324,6 +328,18 @@ { 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."); + } //Clear the previous data m_pBlocks.clear(); @@ -367,14 +383,21 @@ } template - Block* Volume::getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const + Block* Volume::getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const { + assert(uBlockX >= 0); + assert(uBlockY >= 0); + assert(uBlockZ >= 0); + assert(uBlockX < m_uWidthInBlocks); + assert(uBlockY < m_uHeightInBlocks); + assert(uBlockZ < m_uDepthInBlocks); //Compute the block's index from it's position. - uint32_t uBlockIndex = + const int32_t uBlockIndex = uBlockX + uBlockY * m_uWidthInBlocks + uBlockZ * m_uWidthInBlocks * m_uHeightInBlocks; - + assert(uBlockIndex < m_uNoOfBlocksInVolume); + assert(uBlockIndex >= 0); //Get the block Block* block = &(m_pBlocks[uBlockIndex]); @@ -396,12 +419,12 @@ //Currently we find the oldest block by iterating over the whole array. Of course we could store the blocks sorted by //timestamp (set, priority_queue, etc) but then we'll need to move them around as the timestamp changes. Can come back //to this if it proves to be a bottleneck (compraed to the cost of actually doing the compression/decompression). - uint32_t uUncompressedBlockIndex = 100000000; + uint32_t uUncompressedBlockIndex = std::numeric_limits::max(); assert(m_vecUncompressedBlockCache.size() <= m_uMaxUncompressedBlockCacheSize); if(m_vecUncompressedBlockCache.size() == m_uMaxUncompressedBlockCacheSize) { int32_t leastRecentlyUsedBlockIndex = -1; - uint64_t uLeastRecentTimestamp = 1000000000000000; + uint32_t uLeastRecentTimestamp = std::numeric_limits::max(); // you said not int64 ;) for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++) { if(m_pUncompressedTimestamps[m_vecUncompressedBlockCache[ct].uBlockIndex] < uLeastRecentTimestamp) @@ -469,11 +492,11 @@ { setBlockCacheSize(m_uNoOfBlocksInVolume * 2); //Times two gives space to spare - for(uint32_t z = 0; z < m_uDepthInBlocks; z++) + for(int32_t z = 0; z < m_uDepthInBlocks; z++) { - for(uint32_t y = 0; y < m_uHeightInBlocks; y++) + for(int32_t y = 0; y < m_uHeightInBlocks; y++) { - for(uint32_t x = 0; x < m_uWidthInBlocks; x++) + for(int32_t x = 0; x < m_uWidthInBlocks; x++) { getUncompressedBlock(x,y,z); } Index: library/PolyVoxCore/include/SurfaceExtractor.inl =================================================================== --- library/PolyVoxCore/include/SurfaceExtractor.inl (revision 1408) +++ library/PolyVoxCore/include/SurfaceExtractor.inl (working copy) @@ -38,7 +38,7 @@ { //m_regSizeInVoxels.cropTo(m_volData->getEnclosingRegion()); m_regSizeInCells = m_regSizeInVoxels; - m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt16(1,1,1)); + m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); m_meshCurrent->clear(); } @@ -61,7 +61,7 @@ //Create a region corresponding to the first slice m_regSlicePrevious = m_regSizeInVoxels; - Vector3DInt16 v3dUpperCorner = m_regSlicePrevious.getUpperCorner(); + Vector3DInt32 v3dUpperCorner = m_regSlicePrevious.getUpperCorner(); v3dUpperCorner.setZ(m_regSlicePrevious.getLowerCorner().getZ()); //Set the upper z to the lower z to make it one slice thick. m_regSlicePrevious.setUpperCorner(v3dUpperCorner); m_regSliceCurrent = m_regSlicePrevious; @@ -88,10 +88,10 @@ m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ); m_regSlicePrevious = m_regSliceCurrent; - m_regSliceCurrent.shift(Vector3DInt16(0,0,1)); + m_regSliceCurrent.shift(Vector3DInt32(0,0,1)); //Process the other slices (previous slice is available) - for(int16_t uSlice = 1; uSlice <= m_regSizeInVoxels.depth(); uSlice++) + for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.depth(); uSlice++) { computeBitmaskForSlice(pPreviousBitmask, pCurrentBitmask); uNoOfNonEmptyCellsForSlice1 = m_uNoOfOccupiedCells; @@ -116,7 +116,7 @@ m_pPreviousVertexIndicesZ.swap(m_pCurrentVertexIndicesZ); m_regSlicePrevious = m_regSliceCurrent; - m_regSliceCurrent.shift(Vector3DInt16(0,0,1)); + m_regSliceCurrent.shift(Vector3DInt32(0,0,1)); } m_meshCurrent->m_Region = m_regSizeInVoxels; @@ -134,8 +134,8 @@ { m_uNoOfOccupiedCells = 0; - const int16_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX(); - const int16_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY(); + const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX(); + const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY(); iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ(); uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ(); @@ -400,18 +400,18 @@ Array2DInt32& m_pCurrentVertexIndicesY, Array2DInt32& m_pCurrentVertexIndicesZ) { - int16_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ(); - const uint16_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ(); + int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ(); + const uint32_t uZRegSpace = iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ(); //Iterate over each cell in the region - for(int16_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++) + for(int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++) { - const uint16_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); + const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); - for(int16_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); iXVolSpace <= m_regSliceCurrent.getUpperCorner().getX(); iXVolSpace++) + for(int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); iXVolSpace <= m_regSliceCurrent.getUpperCorner().getX(); iXVolSpace++) { //Current position - const uint16_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); + const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); //Determine the index into the edge table which tells us which vertices are inside of the surface uint8_t iCubeIndex = pCurrentBitmask[uXRegSpace][uYRegSpace]; @@ -622,17 +622,17 @@ indlist[i] = -1; } - for(int16_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++) + for(int32_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++) { - for(int16_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++) + for(int32_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++) { - int16_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ(); + int32_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ(); m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); //Current position - const uint16_t uXRegSpace = m_sampVolume.getPosX() - m_regSizeInVoxels.getLowerCorner().getX(); - const uint16_t uYRegSpace = m_sampVolume.getPosY() - m_regSizeInVoxels.getLowerCorner().getY(); - const uint16_t uZRegSpace = m_sampVolume.getPosZ() - m_regSizeInVoxels.getLowerCorner().getZ(); + const uint32_t uXRegSpace = m_sampVolume.getPosX() - m_regSizeInVoxels.getLowerCorner().getX(); + const uint32_t uYRegSpace = m_sampVolume.getPosY() - m_regSizeInVoxels.getLowerCorner().getY(); + const uint32_t uZRegSpace = m_sampVolume.getPosZ() - m_regSizeInVoxels.getLowerCorner().getZ(); //Determine the index into the edge table which tells us which vertices are inside of the surface uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace]; @@ -717,13 +717,10 @@ assert(ind1 >= 0); assert(ind2 >= 0); - assert(ind0 < 1000000); - assert(ind1 < 1000000); - assert(ind2 < 1000000); m_meshCurrent->addTriangle(ind0, ind1, ind2); } }//For each triangle }//For each cell } } -} \ No newline at end of file +} Index: library/PolyVoxCore/include/VolumeSampler.inl =================================================================== --- library/PolyVoxCore/include/VolumeSampler.inl (revision 1408) +++ library/PolyVoxCore/include/VolumeSampler.inl (working copy) @@ -56,19 +56,19 @@ } template - uint16_t VolumeSampler::getPosX(void) const + int32_t VolumeSampler::getPosX(void) const { return mXPosInVolume; } template - uint16_t VolumeSampler::getPosY(void) const + int32_t VolumeSampler::getPosY(void) const { return mYPosInVolume; } template - uint16_t VolumeSampler::getPosZ(void) const + int32_t VolumeSampler::getPosZ(void) const { return mZPosInVolume; } @@ -124,21 +124,21 @@ } template - void VolumeSampler::setPosition(const Vector3DInt16& v3dNewPos) + void VolumeSampler::setPosition(const Vector3DInt32& v3dNewPos) { setPosition(v3dNewPos.getX(), v3dNewPos.getY(), v3dNewPos.getZ()); } template - void VolumeSampler::setPosition(uint16_t xPos, uint16_t yPos, uint16_t zPos) + void VolumeSampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { mXPosInVolume = xPos; mYPosInVolume = yPos; mZPosInVolume = zPos; - const uint16_t uXBlock = mXPosInVolume >> mVolume->m_uBlockSideLengthPower; - const uint16_t uYBlock = mYPosInVolume >> mVolume->m_uBlockSideLengthPower; - const uint16_t uZBlock = mZPosInVolume >> mVolume->m_uBlockSideLengthPower; + const int32_t uXBlock = mXPosInVolume >> mVolume->m_uBlockSideLengthPower; + const int32_t uYBlock = mYPosInVolume >> mVolume->m_uBlockSideLengthPower; + const int32_t uZBlock = mZPosInVolume >> mVolume->m_uBlockSideLengthPower; const uint16_t uXPosInBlock = mXPosInVolume - (uXBlock << mVolume->m_uBlockSideLengthPower); const uint16_t uYPosInBlock = mYPosInVolume - (uYBlock << mVolume->m_uBlockSideLengthPower); @@ -148,7 +148,7 @@ uYPosInBlock * mVolume->m_uBlockSideLength + uZPosInBlock * mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; - if((uXBlock < mVolume->m_uWidthInBlocks) && (uYBlock < mVolume->m_uHeightInBlocks) && (uZBlock < mVolume->m_uDepthInBlocks)) + if((uXBlock < mVolume->m_uWidthInBlocks) && (uYBlock < mVolume->m_uHeightInBlocks) && (uZBlock < mVolume->m_uDepthInBlocks) && (uXBlock >= 0) && (uYBlock >= 0) && (uZBlock >=0)) { const uint32_t uBlockIndexInVolume = uXBlock + uYBlock * mVolume->m_uWidthInBlocks + Index: library/PolyVoxCore/include/GradientEstimators.inl =================================================================== --- library/PolyVoxCore/include/GradientEstimators.inl (revision 1408) +++ library/PolyVoxCore/include/GradientEstimators.inl (working copy) @@ -49,9 +49,9 @@ template Vector3DFloat computeDecimatedCentralDifferenceGradient(const VolumeSampler& volIter) { - const uint16_t x = volIter.getPosX(); - const uint16_t y = volIter.getPosY(); - const uint16_t z = volIter.getPosZ(); + const int32_t x = volIter.getPosX(); + const int32_t y = volIter.getPosY(); + const int32_t z = volIter.getPosZ(); //FIXME - bitwise way of doing this? VoxelType voxel1nx = volIter.getVoxelAt(x-2, y ,z ) > 0 ? 1: 0; @@ -74,9 +74,9 @@ template Vector3DFloat computeSmoothCentralDifferenceGradient(VolumeSampler& volIter) { - uint16_t initialX = volIter.getPosX(); - uint16_t initialY = volIter.getPosY(); - uint16_t initialZ = volIter.getPosZ(); + int32_t initialX = volIter.getPosX(); + int32_t initialY = volIter.getPosY(); + int32_t initialZ = volIter.getPosZ(); //FIXME - bitwise way of doing this? volIter.setPosition(initialX-1, initialY, initialZ); @@ -191,9 +191,9 @@ static const int weights[3][3][3] = { { {2,3,2}, {3,6,3}, {2,3,2} }, { {3,6,3}, {6,0,6}, {3,6,3} }, { {2,3,2}, {3,6,3}, {2,3,2} } }; - uint16_t initialX = volIter.getPosX(); - uint16_t initialY = volIter.getPosY(); - uint16_t initialZ = volIter.getPosZ(); + int32_t initialX = volIter.getPosX(); + int32_t initialY = volIter.getPosY(); + int32_t initialZ = volIter.getPosZ(); volIter.setPosition(initialX-1, initialY-1, initialZ-1); const float pVoxel1nx1ny1nz = computeSmoothedVoxel(volIter); volIter.setPosition(initialX-1, initialY-1, initialZ ); const float pVoxel1nx1ny0pz = computeSmoothedVoxel(volIter); Index: library/PolyVoxCore/include/Volume.h =================================================================== --- library/PolyVoxCore/include/Volume.h (revision 1408) +++ library/PolyVoxCore/include/Volume.h (working copy) @@ -122,7 +122,7 @@ public: /// Constructor - Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32); + Volume(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength = 32); /// Destructor ~Volume(); @@ -131,40 +131,40 @@ /// Gets a Region representing the extents of the Volume. Region getEnclosingRegion(void) const; /// Gets the width of the volume in voxels. - uint16_t getWidth(void) const; + int32_t getWidth(void) const; /// Gets the height of the volume in voxels. - uint16_t getHeight(void) const; + int32_t getHeight(void) const; /// Gets the depth of the volume in voxels. - uint16_t getDepth(void) const; + int32_t getDepth(void) const; /// Gets the length of the longest side in voxels - uint16_t getLongestSideLength(void) const; + int32_t getLongestSideLength(void) const; /// Gets the length of the shortest side in voxels - uint16_t getShortestSideLength(void) const; + int32_t getShortestSideLength(void) const; /// Gets the length of the diagonal in voxels float getDiagonalLength(void) const; /// Gets a voxel by x,y,z position - VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; + VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel by 3D vector position - VoxelType getVoxelAt(const Vector3DUint16& v3dPos) const; + VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; /// Sets the number of blocks for which uncompressed data is stored. void setBlockCacheSize(uint16_t uBlockCacheSize); /// Sets the value used for voxels which are outside the volume void setBorderValue(const VoxelType& tBorder); /// Sets the voxel at an x,y,z position - bool setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); + bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at a 3D vector position - bool setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); + bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue); void clearBlockCache(void); float calculateCompressionRatio(void); uint32_t calculateSizeInBytes(void); void useCompatibilityMode(void); /// Resizes the volume to the specified dimensions - void resize(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32); + void resize(int32_t uWidth, int32_t uHeight, int32_t uDepth, uint16_t uBlockSideLength = 32); private: - Block* getUncompressedBlock(uint16_t uBlockX, uint16_t uBlockY, uint16_t uBlockZ) const; + Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; //The block data mutable std::vector< Block > m_pBlocks; @@ -187,19 +187,19 @@ uint32_t m_uNoOfBlocksInVolume; - uint16_t m_uWidthInBlocks; - uint16_t m_uHeightInBlocks; - uint16_t m_uDepthInBlocks; + int32_t m_uWidthInBlocks; + int32_t m_uHeightInBlocks; + int32_t m_uDepthInBlocks; - uint16_t m_uWidth; - uint16_t m_uHeight; - uint16_t m_uDepth; + int32_t m_uWidth; + int32_t m_uHeight; + int32_t m_uDepth; uint8_t m_uBlockSideLengthPower; uint16_t m_uBlockSideLength; - uint16_t m_uLongestSideLength; - uint16_t m_uShortestSideLength; + int32_t m_uLongestSideLength; + int32_t m_uShortestSideLength; float m_fDiagonalLength; }; Index: library/PolyVoxCore/include/PolyVoxImpl/Block.h =================================================================== --- library/PolyVoxCore/include/PolyVoxImpl/Block.h (revision 1408) +++ library/PolyVoxCore/include/PolyVoxImpl/Block.h (working copy) @@ -25,7 +25,7 @@ #define __PolyVox_Block_H__ #include "PolyVoxForwardDeclarations.h" - +#include #include namespace PolyVox Index: library/PolyVoxCore/include/CubicSurfaceExtractorWithNormals.inl =================================================================== --- library/PolyVoxCore/include/CubicSurfaceExtractorWithNormals.inl (revision 1408) +++ library/PolyVoxCore/include/CubicSurfaceExtractorWithNormals.inl (working copy) @@ -37,7 +37,7 @@ ,m_meshCurrent(result) { m_regSizeInCells = m_regSizeInVoxels; - m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt16(1,1,1)); + m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); m_meshCurrent->clear(); } @@ -45,15 +45,16 @@ template void CubicSurfaceExtractorWithNormals::execute() { - for(int16_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++) + for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++) { - for(int16_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++) + for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++) { - for(int16_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++) + for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++) { - uint16_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); - uint16_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); - uint16_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ(); + // these are always positive anyway + uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); + uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); + uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ(); int currentVoxel = m_volData->getVoxelAt(x,y,z).getDensity() >= VoxelType::getThreshold(); @@ -146,4 +147,4 @@ lodRecord.endIndex = m_meshCurrent->getNoOfIndices(); m_meshCurrent->m_vecLodRecords.push_back(lodRecord); } -} \ No newline at end of file +} Index: library/PolyVoxCore/include/MeshDecimator.inl =================================================================== --- library/PolyVoxCore/include/MeshDecimator.inl (revision 1408) +++ library/PolyVoxCore/include/MeshDecimator.inl (working copy) @@ -174,7 +174,7 @@ for(int ct = 0; ct < vecVertexMetadata.size(); ct++) { Region regTransformed = m_pOutputMesh->m_Region; - regTransformed.shift(regTransformed.getLowerCorner() * static_cast(-1)); + regTransformed.shift(regTransformed.getLowerCorner() * static_cast(-1)); //Plus and minus X vecVertexMetadata[ct].isOnRegionFace.set(RFF_ON_REGION_FACE_NEG_X, m_pOutputMesh->m_vecVertices[ct].getPosition().getX() < regTransformed.getLowerCorner().getX() + 0.001f); @@ -206,7 +206,7 @@ for(int ct = 0; ct < vecVertexMetadata.size(); ct++) { Region regTransformed = m_pOutputMesh->m_Region; - regTransformed.shift(regTransformed.getLowerCorner() * static_cast(-1)); + regTransformed.shift(regTransformed.getLowerCorner() * static_cast(-1)); //Plus and minus X vecVertexMetadata[ct].isOnRegionFace.set(RFF_ON_REGION_FACE_NEG_X, m_pOutputMesh->m_vecVertices[ct].getPosition().getX() < regTransformed.getLowerCorner().getX() + 0.001f); @@ -495,4 +495,4 @@ return result; } -} \ No newline at end of file +} Index: library/PolyVoxCore/include/Region.h =================================================================== --- library/PolyVoxCore/include/Region.h (revision 1408) +++ library/PolyVoxCore/include/Region.h (working copy) @@ -37,28 +37,28 @@ { public: Region(); - Region(const Vector3DInt16& v3dLowerCorner, const Vector3DInt16& v3dUpperCorner); + Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner); - const Vector3DInt16& getLowerCorner(void) const; - const Vector3DInt16& getUpperCorner(void) const; + const Vector3DInt32& getLowerCorner(void) const; + const Vector3DInt32& getUpperCorner(void) const; - void setLowerCorner(const Vector3DInt16& v3dLowerCorner); - void setUpperCorner(const Vector3DInt16& v3dUpperCorner); + void setLowerCorner(const Vector3DInt32& v3dLowerCorner); + void setUpperCorner(const Vector3DInt32& v3dUpperCorner); bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const; - bool containsPoint(const Vector3DInt16& pos, uint8_t boundary = 0) const; + bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const; void cropTo(const Region& other); - int16_t depth(void) const; - int16_t height(void) const; - void shift(const Vector3DInt16& amount); - void shiftLowerCorner(const Vector3DInt16& amount); - void shiftUpperCorner(const Vector3DInt16& amount); - Vector3DInt16 dimensions(void); - int16_t width(void) const; + int32_t depth(void) const; + int32_t height(void) const; + void shift(const Vector3DInt32& amount); + void shiftLowerCorner(const Vector3DInt32& amount); + void shiftUpperCorner(const Vector3DInt32& amount); + Vector3DInt32 dimensions(void); + int32_t width(void) const; private: - Vector3DInt16 m_v3dLowerCorner; - Vector3DInt16 m_v3dUpperCorner; + Vector3DInt32 m_v3dLowerCorner; + Vector3DInt32 m_v3dUpperCorner; //FIXME - This variable is unused, but without it the OpenGL example crashes in release mode //when the volume size is 128^3 and the level of detail is 2. Very strange, but consistant. Index: library/PolyVoxCore/include/SurfaceExtractor.h =================================================================== --- library/PolyVoxCore/include/SurfaceExtractor.h (revision 1408) +++ library/PolyVoxCore/include/SurfaceExtractor.h (working copy) @@ -71,14 +71,14 @@ VolumeSampler m_sampVolume; //Holds a position in volume space. - int16_t iXVolSpace; - int16_t iYVolSpace; - int16_t iZVolSpace; + int32_t iXVolSpace; + int32_t iYVolSpace; + int32_t iZVolSpace; //Holds a position in region space. - uint16_t uXRegSpace; - uint16_t uYRegSpace; - uint16_t uZRegSpace; + uint32_t uXRegSpace; + uint32_t uYRegSpace; + uint32_t uZRegSpace; //Used to return the number of cells in a slice which contain triangles. uint32_t m_uNoOfOccupiedCells; Index: library/PolyVoxCore/include/CubicSurfaceExtractor.inl =================================================================== --- library/PolyVoxCore/include/CubicSurfaceExtractor.inl (revision 1408) +++ library/PolyVoxCore/include/CubicSurfaceExtractor.inl (working copy) @@ -40,7 +40,7 @@ ,m_meshCurrent(result) { m_regSizeInCells = m_regSizeInVoxels; - m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt16(1,1,1)); + m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); m_meshCurrent->clear(); } @@ -54,15 +54,16 @@ memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial)); memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial)); - for(int16_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ() + 1; z++) + for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ() + 1; z++) { - for(int16_t y = m_regSizeInVoxels.getLowerCorner().getY(); y <= m_regSizeInVoxels.getUpperCorner().getY() + 1; y++) + for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y <= m_regSizeInVoxels.getUpperCorner().getY() + 1; y++) { - for(int16_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX() + 1; x++) + for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX() + 1; x++) { - uint16_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); - uint16_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); - uint16_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ(); + // these are always positive anyway + uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); + uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); + uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ(); bool finalX = (x == m_regSizeInVoxels.getUpperCorner().getX() + 1); bool finalY = (y == m_regSizeInVoxels.getUpperCorner().getY() + 1); @@ -166,8 +167,8 @@ template int32_t CubicSurfaceExtractor::addVertex(float fX, float fY, float fZ, uint8_t uMaterialIn, Array<3, IndexAndMaterial>& existingVertices) { - uint16_t uX = static_cast(fX + 0.75f); - uint16_t uY = static_cast(fY + 0.75f); + uint32_t uX = static_cast(fX + 0.75f); + uint32_t uY = static_cast(fY + 0.75f); for(uint32_t ct = 0; ct < MaxQuadsSharingVertex; ct++) { @@ -200,4 +201,4 @@ assert(false); return 0; } -} \ No newline at end of file +} Index: examples/Basic/main.cpp =================================================================== --- examples/Basic/main.cpp (revision 1408) +++ examples/Basic/main.cpp (working copy) @@ -25,6 +25,7 @@ #include "MaterialDensityPair.h" #include "CubicSurfaceExtractorWithNormals.h" +#include "SurfaceExtractor.h" #include "SurfaceMesh.h" #include "Volume.h" @@ -436,13 +437,15 @@ for(int x = 1; x < volData.getWidth()-1; x++) { - std::cout << x << std::endl; + if(x%(volData.getWidth()/100) == 0) { + std::cout << "." << std::flush; + } for(int y = 1; y < volData.getHeight()-1; y++) { float perlinVal = perlin.Get(x / static_cast(volData.getHeight()-1), y / static_cast(volData.getDepth()-1)); perlinVal += 1.0f; perlinVal *= 0.5f; - perlinVal *= volData.getWidth(); + perlinVal *= volData.getShortestSideLength(); for(int z = 1; z < volData.getDepth()-1; z++) { MaterialDensityPair44 voxel; @@ -461,6 +464,7 @@ } } } + std::cout << std::endl; } void createSphereInVolume(Volume& volData, Vector3DFloat v3dVolCenter, float fRadius) @@ -510,15 +514,15 @@ openGLWidget.show(); //Create an empty volume and then place a sphere in it - Volume volData(256, 256, 256); + Volume volData(1024*128,16,16,16); volData.useCompatibilityMode(); //createSphereInVolume(volData, 30); createPerlinTerrain(volData); //createPerlinVolumeSlow(volData); - std::cout << "Memory usage: " << volData.calculateSizeInBytes() << std::endl; - //volData.setBlockCacheSize(8); - std::cout << "Memory usage: " << volData.calculateSizeInBytes() << std::endl; - std::cout << "Compression ratio: " << volData.calculateCompressionRatio() << std::endl; + std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl; + volData.setBlockCacheSize(64); + std::cout << "Memory usage: " << (volData.calculateSizeInBytes()/1024.0/1024.0) << "MB" << std::endl; + std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl; /*srand(12345); for(int ct = 0; ct < 1000; ct++) @@ -535,7 +539,8 @@ //Extract the surface SurfaceMesh mesh; - CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + SurfaceExtractor surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); surfaceExtractor.execute(); //Pass the surface to the OpenGL window Index: examples/OpenGL/Shapes.cpp =================================================================== --- examples/OpenGL/Shapes.cpp (revision 1408) +++ examples/OpenGL/Shapes.cpp (working copy) @@ -55,7 +55,7 @@ } } -void createCubeInVolume(Volume& volData, Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue) +void createCubeInVolume(Volume& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue) { //This three-level for loop iterates over every voxel between the specified corners for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++) @@ -68,4 +68,4 @@ } } } -} \ No newline at end of file +} Index: examples/OpenGL/main.cpp =================================================================== --- examples/OpenGL/main.cpp (revision 1408) +++ examples/OpenGL/main.cpp (working copy) @@ -75,9 +75,9 @@ Volume volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength); //Make our volume contain a sphere in the center. - uint16_t minPos = 0; - uint16_t midPos = g_uVolumeSideLength / 2; - uint16_t maxPos = g_uVolumeSideLength - 1; + int32_t minPos = 0; + int32_t midPos = g_uVolumeSideLength / 2; + int32_t maxPos = g_uVolumeSideLength - 1; cout << "Creating sphere 1" << std::endl; createSphereInVolume(volData, 60.0f, 5); @@ -91,18 +91,18 @@ createSphereInVolume(volData, 20.0f, 1); cout << "Creating cubes" << std::endl; - createCubeInVolume(volData, Vector3DUint16(minPos, minPos, minPos), Vector3DUint16(midPos-1, midPos-1, midPos-1), 0); - createCubeInVolume(volData, Vector3DUint16(midPos+1, midPos+1, minPos), Vector3DUint16(maxPos, maxPos, midPos-1), 0); - createCubeInVolume(volData, Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0); - createCubeInVolume(volData, Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0); + createCubeInVolume(volData, Vector3DInt32(minPos, minPos, minPos), Vector3DInt32(midPos-1, midPos-1, midPos-1), 0); + createCubeInVolume(volData, Vector3DInt32(midPos+1, midPos+1, minPos), Vector3DInt32(maxPos, maxPos, midPos-1), 0); + createCubeInVolume(volData, Vector3DInt32(midPos+1, minPos, midPos+1), Vector3DInt32(maxPos, midPos-1, maxPos), 0); + createCubeInVolume(volData, Vector3DInt32(minPos, midPos+1, midPos+1), Vector3DInt32(midPos-1, maxPos, maxPos), 0); - createCubeInVolume(volData, Vector3DUint16(1, midPos-10, midPos-10), Vector3DUint16(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity()); - createCubeInVolume(volData, Vector3DUint16(midPos-10, 1, midPos-10), Vector3DUint16(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity()); - createCubeInVolume(volData, Vector3DUint16(midPos-10, midPos-10 ,1), Vector3DUint16(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity()); + createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity()); + createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity()); + createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity()); //Smooth part of the volume - smoothRegion(volData, PolyVox::Region(Vector3DInt16(62, 62, 62), Vector3DInt16(130, 130, 130))); - smoothRegion(volData, PolyVox::Region(Vector3DInt16(62, 62, 62), Vector3DInt16(130, 130, 130))); + smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(130, 130, 130))); + smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(130, 130, 130))); QApplication app(argc, argv); Index: examples/OpenGL/OpenGLWidget.cpp =================================================================== --- examples/OpenGL/OpenGLWidget.cpp (revision 1408) +++ examples/OpenGL/OpenGLWidget.cpp (working copy) @@ -74,16 +74,16 @@ //Compute the extents of the current region //FIXME - This is a little complex? PolyVox could //provide more functions for dealing with regions? - uint16_t regionStartX = uRegionX * m_uRegionSideLength; - uint16_t regionStartY = uRegionY * m_uRegionSideLength; - uint16_t regionStartZ = uRegionZ * m_uRegionSideLength; + int32_t regionStartX = uRegionX * m_uRegionSideLength; + int32_t regionStartY = uRegionY * m_uRegionSideLength; + int32_t regionStartZ = uRegionZ * m_uRegionSideLength; - uint16_t regionEndX = regionStartX + m_uRegionSideLength; - uint16_t regionEndY = regionStartY + m_uRegionSideLength; - uint16_t regionEndZ = regionStartZ + m_uRegionSideLength; + int32_t regionEndX = regionStartX + m_uRegionSideLength; + int32_t regionEndY = regionStartY + m_uRegionSideLength; + int32_t regionEndZ = regionStartZ + m_uRegionSideLength; - Vector3DInt16 regLowerCorner(regionStartX, regionStartY, regionStartZ); - Vector3DInt16 regUpperCorner(regionEndX, regionEndY, regionEndZ); + Vector3DInt32 regLowerCorner(regionStartX, regionStartY, regionStartZ); + Vector3DInt32 regUpperCorner(regionEndX, regionEndY, regionEndZ); //Extract the surface for this region //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent); @@ -252,4 +252,4 @@ float aspect = static_cast(width()) / static_cast(height()); glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 1.0, 5000); -} \ No newline at end of file +} Index: examples/OpenGL/Shapes.h =================================================================== --- examples/OpenGL/Shapes.h (revision 1408) +++ examples/OpenGL/Shapes.h (working copy) @@ -28,6 +28,6 @@ #include "Volume.h" void createSphereInVolume(PolyVox::Volume& volData, float fRadius, uint8_t uValue); -void createCubeInVolume(PolyVox::Volume& volData, PolyVox::Vector3DUint16 lowerCorner, PolyVox::Vector3DUint16 upperCorner, uint8_t uValue); +void createCubeInVolume(PolyVox::Volume& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue); -#endif //__OpenGLExample_Shapes_H__ \ No newline at end of file +#endif //__OpenGLExample_Shapes_H__