diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index 3e843543..20c97eb8 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -34,6 +34,9 @@ LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build ADD_EXECUTABLE(BasicExample ${SRC_FILES}) +IF(MSVC) + SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") +ENDIF(MSVC) TARGET_LINK_LIBRARIES(BasicExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) #Install - Only install the example in Windows diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index ef0825c6..fe9a9139 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -40,6 +40,9 @@ LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build ADD_EXECUTABLE(OpenGLExample ${SRC_FILES}) +IF(MSVC) + SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") +ENDIF(MSVC) TARGET_LINK_LIBRARIES(OpenGLExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) #Install - Only install the example in Windows diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index db5cc1de..1444eff6 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -36,6 +36,9 @@ LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build ADD_EXECUTABLE(PagingExample ${SRC_FILES}) +IF(MSVC) + SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") +ENDIF(MSVC) TARGET_LINK_LIBRARIES(PagingExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) #Install - Only install the example in Windows diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index aaa677ff..e282fcf8 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -34,6 +34,9 @@ LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES}) +IF(MSVC) + SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings +ENDIF(MSVC) TARGET_LINK_LIBRARIES(SmoothLODExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) #Install - Only install the example in Windows diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 5d357ef2..a1bcf575 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -61,6 +61,9 @@ SET(CORE_INC_FILES include/PolyVoxCore/Vector.h include/PolyVoxCore/Vector.inl include/PolyVoxCore/VertexTypes.h + include/PolyVoxCore/Volume.h + include/PolyVoxCore/Volume.inl + include/PolyVoxCore/VolumeSampler.inl include/PolyVoxCore/VolumeResampler.h include/PolyVoxCore/VolumeResampler.inl include/PolyVoxCore/VoxelFilters.h @@ -108,7 +111,7 @@ IF(BUILD_STATIC_LIBRARIES) SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES OUTPUT_NAME "PolyVoxCore") SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) IF(MSVC) - SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports + SET_TARGET_PROPERTIES(PolyVoxCoreStatic PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports ENDIF(MSVC) SET(PolyVoxCore_LIBRARY "PolyVoxCoreStatic") ENDIF() @@ -118,7 +121,7 @@ IF(BUILD_DYNAMIC_LIBRARIES) SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS") SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) IF(MSVC) - SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports + SET_TARGET_PROPERTIES(PolyVoxCoreDynamic PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports ENDIF(MSVC) SET(PolyVoxCore_LIBRARY "PolyVoxCoreDynamic") ENDIF() diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index b9ba2909..2fb4fd0e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -21,12 +21,13 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#ifndef __PolyVox_Volume_H__ -#define __PolyVox_Volume_H__ +#ifndef __PolyVox_LargeVolume_H__ +#define __PolyVox_LargeVolume_H__ #include "PolyVoxImpl/Block.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Volume.h" #include #include @@ -141,10 +142,11 @@ namespace PolyVox /// of the block cache (amoung other problems). //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template - class LargeVolume + class LargeVolume : public Volume { public: - class Sampler + typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn + class Sampler : public VolumeOfVoxelType::template Sampler< LargeVolume > { public: Sampler(LargeVolume* volume); @@ -156,7 +158,6 @@ namespace PolyVox int32_t getPosY(void) const; int32_t getPosZ(void) const; VoxelType getSubSampledVoxel(uint8_t uLevel) const; - const LargeVolume* getVolume(void) const; inline VoxelType getVoxel(void) const; void setPosition(const Vector3DInt32& v3dNewPos); @@ -201,15 +202,6 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1pz(void) const; private: - - //The current volume - LargeVolume* mVolume; - - //The current position in the volume - int32_t mXPosInVolume; - int32_t mYPosInVolume; - int32_t mZPosInVolume; - //Other current position information VoxelType* mCurrentVoxel; }; @@ -257,20 +249,6 @@ namespace PolyVox /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the LargeVolume. - Region getEnclosingRegion(void) const; - /// Gets the width of the volume in voxels. - int32_t getWidth(void) const; - /// Gets the height of the volume in voxels. - int32_t getHeight(void) const; - /// Gets the depth of the volume in voxels. - int32_t getDepth(void) const; - /// Gets the length of the longest side in voxels - int32_t getLongestSideLength(void) const; - /// Gets the length of the shortest side in voxels - int32_t getShortestSideLength(void) const; - /// Gets the length of the diagonal in voxels - float getDiagonalLength(void) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector @@ -342,18 +320,12 @@ private: VoxelType* m_pUncompressedBorderData; //The size of the volume - Region m_regValidRegion; Region m_regValidRegionInBlocks; //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; - bool m_bCompressionEnabled; bool m_bPagingEnabled; }; @@ -362,4 +334,4 @@ private: #include "PolyVoxCore/LargeVolume.inl" #include "PolyVoxCore/LargeVolumeSampler.inl" -#endif +#endif //__PolyVox_LargeVolume_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index f21153d2..b041685c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -49,6 +49,7 @@ namespace PolyVox polyvox_function&, const Region&)> dataOverflowHandler, uint16_t uBlockSideLength ) + :Volume(Region::MaxRegion) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; @@ -95,6 +96,7 @@ namespace PolyVox bool bPagingEnabled, uint16_t uBlockSideLength ) + :Volume(regValid) { m_funcDataRequiredHandler = dataRequiredHandler; m_funcDataOverflowHandler = dataOverflowHandler; @@ -124,79 +126,6 @@ namespace PolyVox return *m_pUncompressedBorderData; } - //////////////////////////////////////////////////////////////////////////////// - /// \return A Region representing the extent of the volume. - //////////////////////////////////////////////////////////////////////////////// - template - Region LargeVolume::getEnclosingRegion(void) const - { - return m_regValidRegion; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64. - /// \sa getHeight(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getWidth(void) const - { - return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64. - /// \sa getWidth(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getHeight(void) const - { - return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64. - /// \sa getWidth(), getHeight() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getDepth(void) const - { - return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the shortest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 256. - /// \sa getLongestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getShortestSideLength(void) const - { - return m_uShortestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the longest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 1024. - /// \sa getShortestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t LargeVolume::getLongestSideLength(void) const - { - return m_uLongestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the diagonal in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024) - /// = 1173.139. This value is computed on volume creation so retrieving it is fast. - /// \sa getShortestSideLength(), getLongestSideLength() - //////////////////////////////////////////////////////////////////////////////// - template - float LargeVolume::getDiagonalLength(void) const - { - return m_fDiagonalLength; - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel @@ -206,7 +135,7 @@ namespace PolyVox template VoxelType LargeVolume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { - if(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; @@ -309,7 +238,7 @@ namespace PolyVox template bool LargeVolume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { - assert(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); + assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; @@ -495,10 +424,10 @@ namespace PolyVox m_pLastAccessedBlock = 0; m_bCompressionEnabled = true; - m_regValidRegion = regValidRegion; + this->m_regValidRegion = regValidRegion; - m_regValidRegionInBlocks.setLowerCorner(m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); - m_regValidRegionInBlocks.setUpperCorner(m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); + m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); + m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); setMaxNumberOfUncompressedBlocks(m_uMaxNumberOfUncompressedBlocks); @@ -517,9 +446,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)(getWidth(),getHeight()),getDepth()); - m_uShortestSideLength = (std::min)((std::min)(getWidth(),getHeight()),getDepth()); - m_fDiagonalLength = sqrtf(static_cast(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth())); + this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth()); + this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth()); + this->m_fDiagonalLength = sqrtf(static_cast(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth())); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 2b7e5371..994a9ff3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -26,8 +26,8 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Region.h" -#define BORDER_LOW(x) ((( x >> mVolume->m_uBlockSideLengthPower) << mVolume->m_uBlockSideLengthPower) != x) -#define BORDER_HIGH(x) ((( (x+1) >> mVolume->m_uBlockSideLengthPower) << mVolume->m_uBlockSideLengthPower) != (x+1)) +#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x) +#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1)) //#define BORDER_LOW(x) (( x % mVolume->m_uBlockSideLength) != 0) //#define BORDER_HIGH(x) (( x % mVolume->m_uBlockSideLength) != mVolume->m_uBlockSideLength - 1) @@ -36,7 +36,7 @@ namespace PolyVox { template LargeVolume::Sampler::Sampler(LargeVolume* volume) - :mVolume(volume) + :Volume::template Sampler< LargeVolume >(volume) { } @@ -52,10 +52,10 @@ namespace PolyVox { return *this; } - mVolume = rhs.mVolume; - mXPosInVolume = rhs.mXPosInVolume; - mYPosInVolume = rhs.mYPosInVolume; - mZPosInVolume = rhs.mZPosInVolume; + this->mVolume = rhs.mVolume; + this->mXPosInVolume = rhs.mXPosInVolume; + this->mYPosInVolume = rhs.mYPosInVolume; + this->mZPosInVolume = rhs.mZPosInVolume; mCurrentVoxel = rhs.mCurrentVoxel; return *this; } @@ -63,19 +63,19 @@ namespace PolyVox template int32_t LargeVolume::Sampler::getPosX(void) const { - return mXPosInVolume; + return this->mXPosInVolume; } template int32_t LargeVolume::Sampler::getPosY(void) const { - return mYPosInVolume; + return this->mYPosInVolume; } template int32_t LargeVolume::Sampler::getPosZ(void) const { - return mZPosInVolume; + return this->mZPosInVolume; } template @@ -108,7 +108,7 @@ namespace PolyVox { for(uint8_t x = 0; x < uSize; ++x) { - tValue = (std::min)(tValue, mVolume->getVoxelAt(mXPosInVolume + x, mYPosInVolume + y, mZPosInVolume + z)); + tValue = (std::min)(tValue, this->mVolume->getVoxelAt(this->mXPosInVolume + x, this->mYPosInVolume + y, this->mZPosInVolume + z)); } } } @@ -116,12 +116,6 @@ namespace PolyVox } } - template - const LargeVolume* LargeVolume::Sampler::getVolume(void) const - { - return mVolume; - } - template VoxelType LargeVolume::Sampler::getVoxel(void) const { @@ -137,31 +131,31 @@ namespace PolyVox template void LargeVolume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { - mXPosInVolume = xPos; - mYPosInVolume = yPos; - mZPosInVolume = zPos; + this->mXPosInVolume = xPos; + this->mYPosInVolume = yPos; + this->mZPosInVolume = zPos; - 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 int32_t uXBlock = this->mXPosInVolume >> this->mVolume->m_uBlockSideLengthPower; + const int32_t uYBlock = this->mYPosInVolume >> this->mVolume->m_uBlockSideLengthPower; + const int32_t uZBlock = this->mZPosInVolume >> this->mVolume->m_uBlockSideLengthPower; - const uint16_t uXPosInBlock = mXPosInVolume - (uXBlock << mVolume->m_uBlockSideLengthPower); - const uint16_t uYPosInBlock = mYPosInVolume - (uYBlock << mVolume->m_uBlockSideLengthPower); - const uint16_t uZPosInBlock = mZPosInVolume - (uZBlock << mVolume->m_uBlockSideLengthPower); + const uint16_t uXPosInBlock = this->mXPosInVolume - (uXBlock << this->mVolume->m_uBlockSideLengthPower); + const uint16_t uYPosInBlock = this->mYPosInVolume - (uYBlock << this->mVolume->m_uBlockSideLengthPower); + const uint16_t uZPosInBlock = this->mZPosInVolume - (uZBlock << this->mVolume->m_uBlockSideLengthPower); const uint32_t uVoxelIndexInBlock = uXPosInBlock + - uYPosInBlock * mVolume->m_uBlockSideLength + - uZPosInBlock * mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + uYPosInBlock * this->mVolume->m_uBlockSideLength + + uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; - if(mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) + if(this->mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) { - Block* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); + Block* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock; } else { - mCurrentVoxel = mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock; + mCurrentVoxel = this->mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock; } } @@ -169,7 +163,7 @@ namespace PolyVox void LargeVolume::Sampler::movePositiveX(void) { //Note the *pre* increament here - if((++mXPosInVolume) % mVolume->m_uBlockSideLength != 0) + if((++this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. ++mCurrentVoxel; @@ -177,7 +171,7 @@ namespace PolyVox else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -185,15 +179,15 @@ namespace PolyVox void LargeVolume::Sampler::movePositiveY(void) { //Note the *pre* increament here - if((++mYPosInVolume) % mVolume->m_uBlockSideLength != 0) + if((++this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel += mVolume->m_uBlockSideLength; + mCurrentVoxel += this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -201,15 +195,15 @@ namespace PolyVox void LargeVolume::Sampler::movePositiveZ(void) { //Note the *pre* increament here - if((++mZPosInVolume) % mVolume->m_uBlockSideLength != 0) + if((++this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel += mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -217,7 +211,7 @@ namespace PolyVox void LargeVolume::Sampler::moveNegativeX(void) { //Note the *post* decreament here - if((mXPosInVolume--) % mVolume->m_uBlockSideLength != 0) + if((this->mXPosInVolume--) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. --mCurrentVoxel; @@ -225,7 +219,7 @@ namespace PolyVox else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -233,15 +227,15 @@ namespace PolyVox void LargeVolume::Sampler::moveNegativeY(void) { //Note the *post* decreament here - if((mYPosInVolume--) % mVolume->m_uBlockSideLength != 0) + if((this->mYPosInVolume--) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel -= mVolume->m_uBlockSideLength; + mCurrentVoxel -= this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -249,106 +243,106 @@ namespace PolyVox void LargeVolume::Sampler::moveNegativeZ(void) { //Note the *post* decreament here - if((mZPosInVolume--) % mVolume->m_uBlockSideLength != 0) + if((this->mZPosInVolume--) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel -= mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mYPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType LargeVolume::Sampler::peekVoxel1nx0py1nz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel1nx0py0pz(void) const { - if( BORDER_LOW(mXPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) ) { return *(mCurrentVoxel - 1); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel1nx0py1pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType LargeVolume::Sampler::peekVoxel1nx1py1nz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_LOW(mYPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel1nx1py0pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel1nx1py1pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1); } ////////////////////////////////////////////////////////////////////////// @@ -356,41 +350,41 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if( BORDER_LOW(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel0px1ny0pz(void) const { - if( BORDER_LOW(mYPosInVolume) ) + if( BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel0px1ny1pz(void) const { - if( BORDER_LOW(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType LargeVolume::Sampler::peekVoxel0px0py1nz(void) const { - if( BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1); } template @@ -402,41 +396,41 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px0py1pz(void) const { - if( BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType LargeVolume::Sampler::peekVoxel0px1py1nz(void) const { - if( BORDER_HIGH(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel0px1py0pz(void) const { - if( BORDER_HIGH(mYPosInVolume) ) + if( BORDER_HIGH(this->mYPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel0px1py1pz(void) const { - if( BORDER_HIGH(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1); } ////////////////////////////////////////////////////////////////////////// @@ -444,90 +438,90 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny1nz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel1px1ny0pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mYPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel1px1ny1pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType LargeVolume::Sampler::peekVoxel1px0py1nz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel1px0py0pz(void) const { - if( BORDER_HIGH(mXPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) ) { return *(mCurrentVoxel + 1); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel1px0py1pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType LargeVolume::Sampler::peekVoxel1px1py1nz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType LargeVolume::Sampler::peekVoxel1px1py0pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType LargeVolume::Sampler::peekVoxel1px1py1pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 6a586174..d7d2b1bf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -26,6 +26,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Region.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Volume.h" #include #include @@ -33,22 +34,20 @@ freely, subject to the following restrictions: namespace PolyVox { template - class RawVolume + class RawVolume : public Volume { public: #ifndef SWIG - class Sampler + typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn + class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume > { public: Sampler(RawVolume* volume); ~Sampler(); - Sampler& operator=(const Sampler& rhs) throw(); - int32_t getPosX(void) const; int32_t getPosY(void) const; int32_t getPosZ(void) const; - const RawVolume* getVolume(void) const; inline VoxelType getVoxel(void) const; void setPosition(const Vector3DInt32& v3dNewPos); @@ -93,14 +92,6 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1pz(void) const; private: - //The current volume - RawVolume* mVolume; - - //The current position in the volume - int32_t mXPosInVolume; - int32_t mYPosInVolume; - int32_t mZPosInVolume; - //Other current position information VoxelType* mCurrentVoxel; @@ -120,20 +111,6 @@ namespace PolyVox /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the RawVolume. - Region getEnclosingRegion(void) const; - /// Gets the width of the volume in voxels. - int32_t getWidth(void) const; - /// Gets the height of the volume in voxels. - int32_t getHeight(void) const; - /// Gets the depth of the volume in voxels. - int32_t getDepth(void) const; - /// Gets the length of the longest side in voxels - int32_t getLongestSideLength(void) const; - /// Gets the length of the shortest side in voxels - int32_t getShortestSideLength(void) const; - /// Gets the length of the diagonal in voxels - float getDiagonalLength(void) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector @@ -158,14 +135,6 @@ private: //The border value VoxelType m_tBorderValue; - - //The size of the volume - Region m_regValidRegion; - - //Some useful sizes - int32_t m_uLongestSideLength; - int32_t m_uShortestSideLength; - float m_fDiagonalLength; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index e174d9bc..cbbdbec9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -47,6 +47,7 @@ namespace PolyVox ( const Region& regValid ) + :Volume(regValid) { //Create a volume of the right size. resize(regValid); @@ -63,7 +64,7 @@ namespace PolyVox } //////////////////////////////////////////////////////////////////////////////// - /// The border value is returned whenever an atempt is made to read a voxel which + /// The border value is returned whenever an attempt is made to read a voxel which /// is outside the extents of the volume. /// \return The value used for voxels outside of the volume //////////////////////////////////////////////////////////////////////////////// @@ -73,79 +74,6 @@ namespace PolyVox return m_tBorderValue; } - //////////////////////////////////////////////////////////////////////////////// - /// \return A Region representing the extent of the volume. - //////////////////////////////////////////////////////////////////////////////// - template - Region RawVolume::getEnclosingRegion(void) const - { - return m_regValidRegion; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64. - /// \sa getHeight(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t RawVolume::getWidth(void) const - { - return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64. - /// \sa getWidth(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t RawVolume::getHeight(void) const - { - return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64. - /// \sa getWidth(), getHeight() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t RawVolume::getDepth(void) const - { - return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the shortest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 256. - /// \sa getLongestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t RawVolume::getShortestSideLength(void) const - { - return m_uShortestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the longest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 1024. - /// \sa getShortestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t RawVolume::getLongestSideLength(void) const - { - return m_uLongestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the diagonal in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024) - /// = 1173.139. This value is computed on volume creation so retrieving it is fast. - /// \sa getShortestSideLength(), getLongestSideLength() - //////////////////////////////////////////////////////////////////////////////// - template - float RawVolume::getDiagonalLength(void) const - { - return m_fDiagonalLength; - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel @@ -155,18 +83,18 @@ namespace PolyVox template VoxelType RawVolume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { - if(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { return m_pData [ uXPos + - uYPos * getWidth() + - uZPos * getWidth() * getHeight() + uYPos * this->getWidth() + + uZPos * this->getWidth() * this->getHeight() ]; } else { - return getBorderValue(); + return this->getBorderValue(); } } @@ -199,13 +127,13 @@ namespace PolyVox template bool RawVolume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { - assert(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); + assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); m_pData [ uXPos + - uYPos * getWidth() + - uZPos * getWidth() * getHeight() + uYPos * this->getWidth() + + uZPos * this->getWidth() * this->getHeight() ] = tValue; //Return true to indicate that we modified a voxel. @@ -229,20 +157,20 @@ namespace PolyVox template void RawVolume::resize(const Region& regValidRegion) { - m_regValidRegion = regValidRegion; + this->m_regValidRegion = regValidRegion; //Ensure dimensions of the specified Region are valid - assert(getWidth() > 0); - assert(getHeight() > 0); - assert(getDepth() > 0); + assert(this->getWidth() > 0); + assert(this->getHeight() > 0); + assert(this->getDepth() > 0); //Create the data - m_pData = new VoxelType[getWidth() * getHeight()* getDepth()]; + m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()]; //Other properties we might find useful later - m_uLongestSideLength = (std::max)((std::max)(getWidth(),getHeight()),getDepth()); - m_uShortestSideLength = (std::min)((std::min)(getWidth(),getHeight()),getDepth()); - m_fDiagonalLength = sqrtf(static_cast(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth())); + this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth()); + this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth()); + this->m_fDiagonalLength = sqrtf(static_cast(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth())); } //////////////////////////////////////////////////////////////////////////////// @@ -251,7 +179,7 @@ namespace PolyVox template uint32_t RawVolume::calculateSizeInBytes(void) { - return getWidth() * getHeight() * getDepth() * sizeof(VoxelType); + return this->getWidth() * this->getHeight() * this->getDepth() * sizeof(VoxelType); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 570ea47a..cff073fb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -31,10 +31,7 @@ namespace PolyVox { template RawVolume::Sampler::Sampler(RawVolume* volume) - :mVolume(volume) - ,mXPosInVolume(0) - ,mYPosInVolume(0) - ,mZPosInVolume(0) + :Volume::template Sampler< RawVolume >(volume) ,mCurrentVoxel(0) ,m_bIsCurrentPositionValid(false) { @@ -45,49 +42,28 @@ namespace PolyVox { } - template - typename RawVolume::Sampler& RawVolume::Sampler::operator=(const typename RawVolume::Sampler& rhs) throw() - { - if(this == &rhs) - { - return *this; - } - mVolume = rhs.mVolume; - mXPosInVolume = rhs.mXPosInVolume; - mYPosInVolume = rhs.mYPosInVolume; - mZPosInVolume = rhs.mZPosInVolume; - mCurrentVoxel = rhs.mCurrentVoxel; - return *this; - } - template int32_t RawVolume::Sampler::getPosX(void) const { - return mXPosInVolume; + return this->mXPosInVolume; } template int32_t RawVolume::Sampler::getPosY(void) const { - return mYPosInVolume; + return this->mYPosInVolume; } template int32_t RawVolume::Sampler::getPosZ(void) const { - return mZPosInVolume; - } - - template - const RawVolume* RawVolume::Sampler::getVolume(void) const - { - return mVolume; + return this->mZPosInVolume; } template VoxelType RawVolume::Sampler::getVoxel(void) const { - return m_bIsCurrentPositionValid ? *mCurrentVoxel : mVolume->m_tBorderValue; + return m_bIsCurrentPositionValid ? *mCurrentVoxel : this->mVolume->getBorderValue(); } template @@ -99,119 +75,119 @@ namespace PolyVox template void RawVolume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { - mXPosInVolume = xPos; - mYPosInVolume = yPos; - mZPosInVolume = zPos; + this->mXPosInVolume = xPos; + this->mYPosInVolume = yPos; + this->mZPosInVolume = zPos; const uint32_t uVoxelIndex = xPos + - yPos * mVolume->getWidth() + - zPos * mVolume->getWidth() * mVolume->getHeight(); + yPos * this->mVolume->getWidth() + + zPos * this->mVolume->getWidth() * this->mVolume->getHeight(); - mCurrentVoxel = mVolume->m_pData + uVoxelIndex; + mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; - m_bIsCurrentPositionValid = mVolume->m_regValidRegion.containsPoint(Vector3DInt32(xPos, yPos, zPos)); + m_bIsCurrentPositionValid = this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos)); } template void RawVolume::Sampler::movePositiveX(void) { - mXPosInVolume++; + this->mXPosInVolume++; ++mCurrentVoxel; - m_bIsCurrentPositionValid = mXPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getX(); + m_bIsCurrentPositionValid = this->mXPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getX(); } template void RawVolume::Sampler::movePositiveY(void) { - mYPosInVolume++; - mCurrentVoxel += mVolume->getWidth(); - m_bIsCurrentPositionValid = mYPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getY(); + this->mYPosInVolume++; + mCurrentVoxel += this->mVolume->getWidth(); + m_bIsCurrentPositionValid = this->mYPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getY(); } template void RawVolume::Sampler::movePositiveZ(void) { - mZPosInVolume--; - mCurrentVoxel += mVolume->getWidth() * mVolume->getHeight(); - m_bIsCurrentPositionValid = mZPosInVolume <= mVolume->getEnclosingRegion().getUpperCorner().getZ(); + this->mZPosInVolume++; + mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight(); + m_bIsCurrentPositionValid = this->mZPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getZ(); } template void RawVolume::Sampler::moveNegativeX(void) { - mXPosInVolume--; + this->mXPosInVolume--; --mCurrentVoxel; - m_bIsCurrentPositionValid = mXPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getX(); + m_bIsCurrentPositionValid = this->mXPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getX(); } template void RawVolume::Sampler::moveNegativeY(void) { - mYPosInVolume--; - mCurrentVoxel -= mVolume->getWidth(); - m_bIsCurrentPositionValid = mYPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getY(); + this->mYPosInVolume--; + mCurrentVoxel -= this->mVolume->getWidth(); + m_bIsCurrentPositionValid = this->mYPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getY(); } template void RawVolume::Sampler::moveNegativeZ(void) { - mZPosInVolume--; - mCurrentVoxel -= mVolume->getWidth() * mVolume->getHeight(); - m_bIsCurrentPositionValid =mZPosInVolume >= mVolume->getEnclosingRegion().getLowerCorner().getZ(); + this->mZPosInVolume--; + mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight(); + m_bIsCurrentPositionValid =this->mZPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getZ(); } template VoxelType RawVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1nx0py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1nx0py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx0py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1nx1py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1nx1py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx1py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1); } ////////////////////////////////////////////////////////////////////////// @@ -219,25 +195,25 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel0px1ny1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel0px1ny0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel0px1ny1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel0px0py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1); } template @@ -249,25 +225,25 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel0px0py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel0px1py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel0px1py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel0px1py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1); } ////////////////////////////////////////////////////////////////////////// @@ -275,54 +251,54 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel1px1ny1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1px1ny0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1px1ny1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1px0py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1px0py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1px0py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1px1py1nz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1px1py0pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1px1py1pz(void) const { - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 60ce2ba6..5888df0d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -41,6 +41,7 @@ namespace PolyVox Region(); Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner); + Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ); const Vector3DInt32& getLowerCorner(void) const; const Vector3DInt32& getUpperCorner(void) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index d2c2edfc..b75cd367 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -26,6 +26,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Region.h" #include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Volume.h" #include #include @@ -33,14 +34,12 @@ freely, subject to the following restrictions: namespace PolyVox { template - class SimpleVolume + class SimpleVolume : public Volume { public: #ifndef SWIG class Block { - //Make Sampler a friend - friend class SimpleVolume::Sampler; public: Block(uint16_t uSideLength = 0); @@ -61,7 +60,8 @@ namespace PolyVox uint8_t m_uSideLengthPower; }; - class Sampler + typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn + class Sampler : public VolumeOfVoxelType::template Sampler< SimpleVolume > { public: Sampler(SimpleVolume* volume); @@ -73,7 +73,6 @@ namespace PolyVox int32_t getPosY(void) const; int32_t getPosZ(void) const; VoxelType getSubSampledVoxel(uint8_t uLevel) const; - const SimpleVolume* getVolume(void) const; inline VoxelType getVoxel(void) const; void setPosition(const Vector3DInt32& v3dNewPos); @@ -117,16 +116,7 @@ namespace PolyVox inline VoxelType peekVoxel1px1py0pz(void) const; inline VoxelType peekVoxel1px1py1pz(void) const; - private: - - //The current volume - SimpleVolume* mVolume; - - //The current position in the volume - int32_t mXPosInVolume; - int32_t mYPosInVolume; - int32_t mZPosInVolume; - + private: //Other current position information VoxelType* mCurrentVoxel; }; @@ -149,20 +139,6 @@ namespace PolyVox /// Gets the value used for voxels which are outside the volume VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the SimpleVolume. - Region getEnclosingRegion(void) const; - /// Gets the width of the volume in voxels. - int32_t getWidth(void) const; - /// Gets the height of the volume in voxels. - int32_t getHeight(void) const; - /// Gets the depth of the volume in voxels. - int32_t getDepth(void) const; - /// Gets the length of the longest side in voxels - int32_t getLongestSideLength(void) const; - /// Gets the length of the shortest side in voxels - int32_t getShortestSideLength(void) const; - /// Gets the length of the diagonal in voxels - float getDiagonalLength(void) const; /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector @@ -193,8 +169,7 @@ private: //the VolumeIterator can do it's usual pointer arithmetic without needing to know it's gone outside the volume. VoxelType* m_pUncompressedBorderData; - //The size of the volume - Region m_regValidRegion; + //The size of the volume in vlocks Region m_regValidRegionInBlocks; //Volume size measured in blocks. @@ -206,11 +181,6 @@ private: //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; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 3554c687..a401ec95 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -69,6 +69,7 @@ namespace PolyVox const Region& regValid, uint16_t uBlockSideLength ) + :Volume(regValid) { //Create a volume of the right size. resize(regValid,uBlockSideLength); @@ -95,79 +96,6 @@ namespace PolyVox return *m_pUncompressedBorderData; } - //////////////////////////////////////////////////////////////////////////////// - /// \return A Region representing the extent of the volume. - //////////////////////////////////////////////////////////////////////////////// - template - Region SimpleVolume::getEnclosingRegion(void) const - { - return m_regValidRegion; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64. - /// \sa getHeight(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getWidth(void) const - { - return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64. - /// \sa getWidth(), getDepth() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getHeight(void) const - { - return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64. - /// \sa getWidth(), getHeight() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getDepth(void) const - { - return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the shortest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 256. - /// \sa getLongestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getShortestSideLength(void) const - { - return m_uShortestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the longest side in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return 1024. - /// \sa getShortestSideLength(), getDiagonalLength() - //////////////////////////////////////////////////////////////////////////////// - template - int32_t SimpleVolume::getLongestSideLength(void) const - { - return m_uLongestSideLength; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return The length of the diagonal in voxels. For example, if a volume has - /// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024) - /// = 1173.139. This value is computed on volume creation so retrieving it is fast. - /// \sa getShortestSideLength(), getLongestSideLength() - //////////////////////////////////////////////////////////////////////////////// - template - float SimpleVolume::getDiagonalLength(void) const - { - return m_fDiagonalLength; - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos The \c x position of the voxel /// \param uYPos The \c y position of the voxel @@ -177,7 +105,7 @@ namespace PolyVox template VoxelType SimpleVolume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { - if(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; @@ -228,7 +156,7 @@ namespace PolyVox template bool SimpleVolume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { - assert(m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); + assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); const int32_t blockX = uXPos >> m_uBlockSideLengthPower; const int32_t blockY = uYPos >> m_uBlockSideLengthPower; @@ -279,10 +207,10 @@ namespace PolyVox m_uBlockSideLength = uBlockSideLength; m_pUncompressedBorderData = 0; - m_regValidRegion = regValidRegion; + this->m_regValidRegion = regValidRegion; - m_regValidRegionInBlocks.setLowerCorner(m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); - m_regValidRegionInBlocks.setUpperCorner(m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); + m_regValidRegionInBlocks.setLowerCorner(this->m_regValidRegion.getLowerCorner() / static_cast(uBlockSideLength)); + m_regValidRegionInBlocks.setUpperCorner(this->m_regValidRegion.getUpperCorner() / static_cast(uBlockSideLength)); //Compute the block side length m_uBlockSideLength = uBlockSideLength; @@ -306,9 +234,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)(getWidth(),getHeight()),getDepth()); - m_uShortestSideLength = (std::min)((std::min)(getWidth(),getHeight()),getDepth()); - m_fDiagonalLength = sqrtf(static_cast(getWidth() * getWidth() + getHeight() * getHeight() + getDepth() * getDepth())); + this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth()); + this->m_uShortestSideLength = (std::min)((std::min)(this->getWidth(),this->getHeight()),this->getDepth()); + this->m_fDiagonalLength = sqrtf(static_cast(this->getWidth() * this->getWidth() + this->getHeight() * this->getHeight() + this->getDepth() * this->getDepth())); } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index bc7dcc7c..ba8bdb1a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -26,17 +26,17 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Region.h" -#define BORDER_LOW(x) ((( x >> mVolume->m_uBlockSideLengthPower) << mVolume->m_uBlockSideLengthPower) != x) -#define BORDER_HIGH(x) ((( (x+1) >> mVolume->m_uBlockSideLengthPower) << mVolume->m_uBlockSideLengthPower) != (x+1)) -//#define BORDER_LOW(x) (( x % mVolume->m_uBlockSideLength) != 0) -//#define BORDER_HIGH(x) (( x % mVolume->m_uBlockSideLength) != mVolume->m_uBlockSideLength - 1) +#define BORDER_LOW(x) ((( x >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != x) +#define BORDER_HIGH(x) ((( (x+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (x+1)) +//#define BORDER_LOW(x) (( x % this->mVolume->m_uBlockSideLength) != 0) +//#define BORDER_HIGH(x) (( x % this->mVolume->m_uBlockSideLength) != this->mVolume->m_uBlockSideLength - 1) #include namespace PolyVox { template SimpleVolume::Sampler::Sampler(SimpleVolume* volume) - :mVolume(volume) + :Volume::template Sampler< SimpleVolume >(volume) { } @@ -52,10 +52,10 @@ namespace PolyVox { return *this; } - mVolume = rhs.mVolume; - mXPosInVolume = rhs.mXPosInVolume; - mYPosInVolume = rhs.mYPosInVolume; - mZPosInVolume = rhs.mZPosInVolume; + this->mVolume = rhs.mVolume; + this->mXPosInVolume = rhs.mXPosInVolume; + this->mYPosInVolume = rhs.mYPosInVolume; + this->mZPosInVolume = rhs.mZPosInVolume; mCurrentVoxel = rhs.mCurrentVoxel; return *this; } @@ -63,19 +63,19 @@ namespace PolyVox template int32_t SimpleVolume::Sampler::getPosX(void) const { - return mXPosInVolume; + return this->mXPosInVolume; } template int32_t SimpleVolume::Sampler::getPosY(void) const { - return mYPosInVolume; + return this->mYPosInVolume; } template int32_t SimpleVolume::Sampler::getPosZ(void) const { - return mZPosInVolume; + return this->mZPosInVolume; } template @@ -108,7 +108,7 @@ namespace PolyVox { for(uint8_t x = 0; x < uSize; ++x) { - tValue = (std::min)(tValue, mVolume->getVoxelAt(mXPosInVolume + x, mYPosInVolume + y, mZPosInVolume + z)); + tValue = (std::min)(tValue, this->mVolume->getVoxelAt(this->mXPosInVolume + x, this->mYPosInVolume + y, this->mZPosInVolume + z)); } } } @@ -116,12 +116,6 @@ namespace PolyVox } } - template - const SimpleVolume* SimpleVolume::Sampler::getVolume(void) const - { - return mVolume; - } - template VoxelType SimpleVolume::Sampler::getVoxel(void) const { @@ -137,31 +131,31 @@ namespace PolyVox template void SimpleVolume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { - mXPosInVolume = xPos; - mYPosInVolume = yPos; - mZPosInVolume = zPos; + this->mXPosInVolume = xPos; + this->mYPosInVolume = yPos; + this->mZPosInVolume = zPos; - 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 int32_t uXBlock = this->mXPosInVolume >> this->mVolume->m_uBlockSideLengthPower; + const int32_t uYBlock = this->mYPosInVolume >> this->mVolume->m_uBlockSideLengthPower; + const int32_t uZBlock = this->mZPosInVolume >> this->mVolume->m_uBlockSideLengthPower; - const uint16_t uXPosInBlock = mXPosInVolume - (uXBlock << mVolume->m_uBlockSideLengthPower); - const uint16_t uYPosInBlock = mYPosInVolume - (uYBlock << mVolume->m_uBlockSideLengthPower); - const uint16_t uZPosInBlock = mZPosInVolume - (uZBlock << mVolume->m_uBlockSideLengthPower); + const uint16_t uXPosInBlock = this->mXPosInVolume - (uXBlock << this->mVolume->m_uBlockSideLengthPower); + const uint16_t uYPosInBlock = this->mYPosInVolume - (uYBlock << this->mVolume->m_uBlockSideLengthPower); + const uint16_t uZPosInBlock = this->mZPosInVolume - (uZBlock << this->mVolume->m_uBlockSideLengthPower); const uint32_t uVoxelIndexInBlock = uXPosInBlock + - uYPosInBlock * mVolume->m_uBlockSideLength + - uZPosInBlock * mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + uYPosInBlock * this->mVolume->m_uBlockSideLength + + uZPosInBlock * this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; - if(mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) + if(this->mVolume->m_regValidRegionInBlocks.containsPoint(Vector3DInt32(uXBlock, uYBlock, uZBlock))) { - Block* pUncompressedCurrentBlock = mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); + Block* pUncompressedCurrentBlock = this->mVolume->getUncompressedBlock(uXBlock, uYBlock, uZBlock); mCurrentVoxel = pUncompressedCurrentBlock->m_tUncompressedData + uVoxelIndexInBlock; } else { - mCurrentVoxel = mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock; + mCurrentVoxel = this->mVolume->m_pUncompressedBorderData + uVoxelIndexInBlock; } } @@ -169,7 +163,7 @@ namespace PolyVox void SimpleVolume::Sampler::movePositiveX(void) { //Note the *pre* increament here - if((++mXPosInVolume) % mVolume->m_uBlockSideLength != 0) + if((++this->mXPosInVolume) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. ++mCurrentVoxel; @@ -177,7 +171,7 @@ namespace PolyVox else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -185,15 +179,15 @@ namespace PolyVox void SimpleVolume::Sampler::movePositiveY(void) { //Note the *pre* increament here - if((++mYPosInVolume) % mVolume->m_uBlockSideLength != 0) + if((++this->mYPosInVolume) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel += mVolume->m_uBlockSideLength; + mCurrentVoxel += this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -201,15 +195,15 @@ namespace PolyVox void SimpleVolume::Sampler::movePositiveZ(void) { //Note the *pre* increament here - if((++mZPosInVolume) % mVolume->m_uBlockSideLength != 0) + if((++this->mZPosInVolume) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel += mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + mCurrentVoxel += this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -217,7 +211,7 @@ namespace PolyVox void SimpleVolume::Sampler::moveNegativeX(void) { //Note the *post* decreament here - if((mXPosInVolume--) % mVolume->m_uBlockSideLength != 0) + if((this->mXPosInVolume--) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. --mCurrentVoxel; @@ -225,7 +219,7 @@ namespace PolyVox else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -233,15 +227,15 @@ namespace PolyVox void SimpleVolume::Sampler::moveNegativeY(void) { //Note the *post* decreament here - if((mYPosInVolume--) % mVolume->m_uBlockSideLength != 0) + if((this->mYPosInVolume--) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel -= mVolume->m_uBlockSideLength; + mCurrentVoxel -= this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } @@ -249,106 +243,106 @@ namespace PolyVox void SimpleVolume::Sampler::moveNegativeZ(void) { //Note the *post* decreament here - if((mZPosInVolume--) % mVolume->m_uBlockSideLength != 0) + if((this->mZPosInVolume--) % this->mVolume->m_uBlockSideLength != 0) { //No need to compute new block. - mCurrentVoxel -= mVolume->m_uBlockSideLength * mVolume->m_uBlockSideLength; + mCurrentVoxel -= this->mVolume->m_uBlockSideLength * this->mVolume->m_uBlockSideLength; } else { //We've hit the block boundary. Just calling setPosition() is the easiest way to resolve this. - setPosition(mXPosInVolume, mYPosInVolume, mZPosInVolume); + setPosition(this->mXPosInVolume, this->mYPosInVolume, this->mZPosInVolume); } } template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mYPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py1nz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py0pz(void) const { - if( BORDER_LOW(mXPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) ) { return *(mCurrentVoxel - 1); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py1pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py1nz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_LOW(mYPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py0pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py1pz(void) const { - if( BORDER_LOW(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - 1 + mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume-1,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1); } ////////////////////////////////////////////////////////////////////////// @@ -356,41 +350,41 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if( BORDER_LOW(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny0pz(void) const { - if( BORDER_LOW(mYPosInVolume) ) + if( BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny1pz(void) const { - if( BORDER_LOW(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType SimpleVolume::Sampler::peekVoxel0px0py1nz(void) const { - if( BORDER_LOW(mZPosInVolume) ) + if( BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1); } template @@ -402,41 +396,41 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px0py1pz(void) const { - if( BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType SimpleVolume::Sampler::peekVoxel0px1py1nz(void) const { - if( BORDER_HIGH(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel0px1py0pz(void) const { - if( BORDER_HIGH(mYPosInVolume) ) + if( BORDER_HIGH(this->mYPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel0px1py1pz(void) const { - if( BORDER_HIGH(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1); } ////////////////////////////////////////////////////////////////////////// @@ -444,90 +438,90 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny1nz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny0pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mYPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny1pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume-1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType SimpleVolume::Sampler::peekVoxel1px0py1nz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel1px0py0pz(void) const { - if( BORDER_HIGH(mXPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) ) { return *(mCurrentVoxel + 1); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel1px0py1pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType SimpleVolume::Sampler::peekVoxel1px1py1nz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_LOW(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength - mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume-1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType SimpleVolume::Sampler::peekVoxel1px1py0pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType SimpleVolume::Sampler::peekVoxel1px1py1pz(void) const { - if( BORDER_HIGH(mXPosInVolume) && BORDER_HIGH(mYPosInVolume) && BORDER_HIGH(mZPosInVolume) ) + if( BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) { - return *(mCurrentVoxel + 1 + mVolume->m_uBlockSideLength + mVolume->m_uBlockSideLength*mVolume->m_uBlockSideLength); + return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } - return mVolume->getVoxelAt(mXPosInVolume+1,mYPosInVolume+1,mZPosInVolume+1); + return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h new file mode 100644 index 00000000..51b7634a --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -0,0 +1,157 @@ +/******************************************************************************* +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_Volume_H__ +#define __PolyVox_Volume_H__ + +#include "PolyVoxCore/Region.h" +#include "PolyVoxCore/PolyVoxForwardDeclarations.h" + +#include +#include + +namespace PolyVox +{ + template + class Volume + { + public: + #ifndef SWIG + template + class Sampler + { + public: + Sampler(DerivedVolumeType* volume); + ~Sampler(); + + int32_t getPosX(void) const; + int32_t getPosY(void) const; + int32_t getPosZ(void) const; + inline VoxelType getVoxel(void) const; + + void setPosition(const Vector3DInt32& v3dNewPos); + void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); + + void movePositiveX(void); + void movePositiveY(void); + void movePositiveZ(void); + + void moveNegativeX(void); + void moveNegativeY(void); + void moveNegativeZ(void); + + inline VoxelType peekVoxel1nx1ny1nz(void) const; + inline VoxelType peekVoxel1nx1ny0pz(void) const; + inline VoxelType peekVoxel1nx1ny1pz(void) const; + inline VoxelType peekVoxel1nx0py1nz(void) const; + inline VoxelType peekVoxel1nx0py0pz(void) const; + inline VoxelType peekVoxel1nx0py1pz(void) const; + inline VoxelType peekVoxel1nx1py1nz(void) const; + inline VoxelType peekVoxel1nx1py0pz(void) const; + inline VoxelType peekVoxel1nx1py1pz(void) const; + + inline VoxelType peekVoxel0px1ny1nz(void) const; + inline VoxelType peekVoxel0px1ny0pz(void) const; + inline VoxelType peekVoxel0px1ny1pz(void) const; + inline VoxelType peekVoxel0px0py1nz(void) const; + inline VoxelType peekVoxel0px0py0pz(void) const; + inline VoxelType peekVoxel0px0py1pz(void) const; + inline VoxelType peekVoxel0px1py1nz(void) const; + inline VoxelType peekVoxel0px1py0pz(void) const; + inline VoxelType peekVoxel0px1py1pz(void) const; + + inline VoxelType peekVoxel1px1ny1nz(void) const; + inline VoxelType peekVoxel1px1ny0pz(void) const; + inline VoxelType peekVoxel1px1ny1pz(void) const; + inline VoxelType peekVoxel1px0py1nz(void) const; + inline VoxelType peekVoxel1px0py0pz(void) const; + inline VoxelType peekVoxel1px0py1pz(void) const; + inline VoxelType peekVoxel1px1py1nz(void) const; + inline VoxelType peekVoxel1px1py0pz(void) const; + inline VoxelType peekVoxel1px1py1pz(void) const; + + protected: + DerivedVolumeType* mVolume; + + //The current position in the volume + int32_t mXPosInVolume; + int32_t mYPosInVolume; + int32_t mZPosInVolume; + }; + #endif + + public: + /// Constructor for creating a fixed size volume. + Volume + ( + const Region& regValid + ); + /// Destructor + ~Volume(); + + /// Gets the value used for voxels which are outside the volume + VoxelType getBorderValue(void) const; + /// Gets a Region representing the extents of the Volume. + Region getEnclosingRegion(void) const; + /// Gets the width of the volume in voxels. + int32_t getWidth(void) const; + /// Gets the height of the volume in voxels. + int32_t getHeight(void) const; + /// Gets the depth of the volume in voxels. + int32_t getDepth(void) const; + /// Gets the length of the longest side in voxels + int32_t getLongestSideLength(void) const; + /// Gets the length of the shortest side in voxels + int32_t getShortestSideLength(void) const; + /// Gets the length of the diagonal in voxels + float getDiagonalLength(void) const; + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; + /// Gets a voxel at the position given by a 3D vector + VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const; + + /// Sets the value used for voxels which are outside the volume + void setBorderValue(const VoxelType& tBorder); + /// Sets the voxel at the position given by x,y,z coordinates + bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); + /// Sets the voxel at the position given by a 3D vector + bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue); + + /// Calculates approximatly how many bytes of memory the volume is currently using. + uint32_t calculateSizeInBytes(void); + +protected: + //The size of the volume + Region m_regValidRegion; + + //Some useful sizes + int32_t m_uLongestSideLength; + int32_t m_uShortestSideLength; + float m_fDiagonalLength; + }; +} + +#include "PolyVoxCore/Volume.inl" +#include "PolyVoxCore/VolumeSampler.inl" + +#endif //__PolyVox_Volume_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl new file mode 100644 index 00000000..0a7f4cad --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl @@ -0,0 +1,203 @@ +/******************************************************************************* +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. +*******************************************************************************/ + +#include "PolyVoxCore/Log.h" +#include "PolyVoxCore/Region.h" +#include "PolyVoxCore/Vector.h" + +#include + +namespace PolyVox +{ + template + Volume::Volume + ( + const Region& regValid + ) + :m_regValidRegion(regValid) + { + } + + //////////////////////////////////////////////////////////////////////////////// + /// Destroys the volume + //////////////////////////////////////////////////////////////////////////////// + template + Volume::~Volume() + { + } + + //////////////////////////////////////////////////////////////////////////////// + /// The border value is returned whenever an attempt is made to read a voxel which + /// is outside the extents of the volume. + /// \return The value used for voxels outside of the volume + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType Volume::getBorderValue(void) const + { + assert(false); + return VoxelType(); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return A Region representing the extent of the volume. + //////////////////////////////////////////////////////////////////////////////// + template + Region Volume::getEnclosingRegion(void) const + { + return m_regValidRegion; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return The width of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the width is 64. + /// \sa getHeight(), getDepth() + //////////////////////////////////////////////////////////////////////////////// + template + int32_t Volume::getWidth(void) const + { + return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return The height of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the height is 64. + /// \sa getWidth(), getDepth() + //////////////////////////////////////////////////////////////////////////////// + template + int32_t Volume::getHeight(void) const + { + return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return The depth of the volume in voxels. Note that this value is inclusive, so that if the valid range is e.g. 0 to 63 then the depth is 64. + /// \sa getWidth(), getHeight() + //////////////////////////////////////////////////////////////////////////////// + template + int32_t Volume::getDepth(void) const + { + return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return The length of the shortest side in voxels. For example, if a volume has + /// dimensions 256x512x1024 this function will return 256. + /// \sa getLongestSideLength(), getDiagonalLength() + //////////////////////////////////////////////////////////////////////////////// + template + int32_t Volume::getShortestSideLength(void) const + { + return m_uShortestSideLength; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return The length of the longest side in voxels. For example, if a volume has + /// dimensions 256x512x1024 this function will return 1024. + /// \sa getShortestSideLength(), getDiagonalLength() + //////////////////////////////////////////////////////////////////////////////// + template + int32_t Volume::getLongestSideLength(void) const + { + return m_uLongestSideLength; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return The length of the diagonal in voxels. For example, if a volume has + /// dimensions 256x512x1024 this function will return sqrt(256*256+512*512+1024*1024) + /// = 1173.139. This value is computed on volume creation so retrieving it is fast. + /// \sa getShortestSideLength(), getLongestSideLength() + //////////////////////////////////////////////////////////////////////////////// + template + float Volume::getDiagonalLength(void) const + { + return m_fDiagonalLength; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos The \c x position of the voxel + /// \param uYPos The \c y position of the voxel + /// \param uZPos The \c z position of the voxel + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType Volume::getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + { + assert(false); + return VoxelType(); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos The 3D position of the voxel + /// \return The voxel value + //////////////////////////////////////////////////////////////////////////////// + template + VoxelType Volume::getVoxelAt(const Vector3DInt32& v3dPos) const + { + assert(false); + return VoxelType(); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param tBorder The value to use for voxels outside the volume. + //////////////////////////////////////////////////////////////////////////////// + template + void Volume::setBorderValue(const VoxelType& tBorder) + { + assert(false); + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param uXPos the \c x position of the voxel + /// \param uYPos the \c y position of the voxel + /// \param uZPos the \c z position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + bool Volume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) + { + assert(false); + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \param v3dPos the 3D position of the voxel + /// \param tValue the value to which the voxel will be set + /// \return whether the requested position is inside the volume + //////////////////////////////////////////////////////////////////////////////// + template + bool Volume::setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) + { + assert(false); + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + /// Note: This function needs reviewing for accuracy... + //////////////////////////////////////////////////////////////////////////////// + template + uint32_t Volume::calculateSizeInBytes(void) + { + return getWidth() * getHeight() * getDepth() * sizeof(VoxelType); + } + +} + diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl new file mode 100644 index 00000000..68b2e314 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl @@ -0,0 +1,328 @@ +/******************************************************************************* +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. +*******************************************************************************/ + +#include "PolyVoxImpl/Block.h" +#include "PolyVoxCore/Volume.h" +#include "PolyVoxCore/Vector.h" +#include "PolyVoxCore/Region.h" + +#include +namespace PolyVox +{ + template + template + Volume::Sampler::Sampler(DerivedVolumeType* volume) + :mVolume(volume) + ,mXPosInVolume(0) + ,mYPosInVolume(0) + ,mZPosInVolume(0) + { + } + + template + template + Volume::Sampler::~Sampler() + { + } + + template + template + int32_t Volume::Sampler::getPosX(void) const + { + return mXPosInVolume; + } + + template + template + int32_t Volume::Sampler::getPosY(void) const + { + return mYPosInVolume; + } + + template + template + int32_t Volume::Sampler::getPosZ(void) const + { + return mZPosInVolume; + } + + template + template + VoxelType Volume::Sampler::getVoxel(void) const + { + return mVolume->getVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume); + } + + template + template + void Volume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) + { + mXPosInVolume = v3dNewPos.getX(); + mYPosInVolume = v3dNewPos.getY(); + mZPosInVolume = v3dNewPos.getZ(); + } + + template + template + void Volume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) + { + mXPosInVolume = xPos; + mYPosInVolume = yPos; + mZPosInVolume = zPos; + } + + template + template + void Volume::Sampler::movePositiveX(void) + { + mXPosInVolume++; + } + + template + template + void Volume::Sampler::movePositiveY(void) + { + mYPosInVolume++; + } + + template + template + void Volume::Sampler::movePositiveZ(void) + { + mZPosInVolume++; + } + + template + template + void Volume::Sampler::moveNegativeX(void) + { + mXPosInVolume--; + } + + template + template + void Volume::Sampler::moveNegativeY(void) + { + mYPosInVolume--; + } + + template + template + void Volume::Sampler::moveNegativeZ(void) + { + mZPosInVolume--; + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx1ny1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx1ny0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx1ny1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume - 1, mZPosInVolume + 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx0py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx0py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx0py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume , mZPosInVolume + 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx1py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx1py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1nx1py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume - 1, mYPosInVolume + 1, mZPosInVolume + 1); + } + + ////////////////////////////////////////////////////////////////////////// + + template + template + VoxelType Volume::Sampler::peekVoxel0px1ny1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px1ny0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px1ny1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume - 1, mZPosInVolume + 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px0py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px0py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px0py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume , mZPosInVolume + 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px1py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px1py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel0px1py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume , mYPosInVolume + 1, mZPosInVolume + 1); + } + + ////////////////////////////////////////////////////////////////////////// + + template + template + VoxelType Volume::Sampler::peekVoxel1px1ny1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px1ny0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px1ny1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume - 1, mZPosInVolume + 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px0py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px0py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px0py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume , mZPosInVolume + 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px1py1nz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume - 1); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px1py0pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume ); + } + + template + template + VoxelType Volume::Sampler::peekVoxel1px1py1pz(void) const + { + return mVolume->getVoxelAt(mXPosInVolume + 1, mYPosInVolume + 1, mZPosInVolume + 1); + } +} diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index e0eaa1c1..8b6491d5 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -50,6 +50,16 @@ namespace PolyVox assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ()); } + Region::Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ) + :m_v3dLowerCorner(iLowerX, iLowerY, iLowerZ) + ,m_v3dUpperCorner(iUpperX, iUpperY, iUpperZ) + { + //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()); + } + const Vector3DInt32& Region::getLowerCorner(void) const { return m_v3dLowerCorner; diff --git a/library/PolyVoxCore/source/VoxelFilters.cpp b/library/PolyVoxCore/source/VoxelFilters.cpp index e97f1fa6..45c5176c 100644 --- a/library/PolyVoxCore/source/VoxelFilters.cpp +++ b/library/PolyVoxCore/source/VoxelFilters.cpp @@ -28,13 +28,6 @@ namespace PolyVox template< template class VolumeType> float computeSmoothedVoxel(typename VolumeType::Sampler& volIter) { - assert(volIter.getPosX() >= 1); - assert(volIter.getPosY() >= 1); - assert(volIter.getPosZ() >= 1); - assert(volIter.getPosX() <= volIter.getVolume()->getWidth() - 2); - assert(volIter.getPosY() <= volIter.getVolume()->getHeight() - 2); - assert(volIter.getPosZ() <= volIter.getVolume()->getDepth() - 2); - float sum = 0.0; if(volIter.peekVoxel1nx1ny1nz() != 0) sum += 1.0f; diff --git a/library/PolyVoxUtil/CMakeLists.txt b/library/PolyVoxUtil/CMakeLists.txt index 52d1efc7..3c2a78a4 100644 --- a/library/PolyVoxUtil/CMakeLists.txt +++ b/library/PolyVoxUtil/CMakeLists.txt @@ -35,7 +35,7 @@ IF(BUILD_STATIC_LIBRARIES) SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES OUTPUT_NAME "PolyVoxUtil") SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) IF(MSVC) - SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports + SET_TARGET_PROPERTIES(PolyVoxUtilStatic PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports ENDIF(MSVC) ADD_DEPENDENCIES(PolyVoxUtilStatic PolyVoxCoreStatic) ENDIF() @@ -46,7 +46,7 @@ IF(BUILD_DYNAMIC_LIBRARIES) SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES COMPILE_FLAGS "-DPOLYVOX_SHARED_EXPORTS") SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES VERSION ${POLYVOX_VERSION} SOVERSION ${POLYVOX_VERSION_MAJOR}) IF(MSVC) - SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES COMPILE_FLAGS "/wd4251") #Disable warning on STL exports + SET_TARGET_PROPERTIES(PolyVoxUtilDynamic PROPERTIES COMPILE_FLAGS "/W4 /wd4251 /wd4127") #Disable warning on STL exports ENDIF(MSVC) ADD_DEPENDENCIES(PolyVoxUtilDynamic PolyVoxCoreDynamic) ENDIF() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 877e7fe5..39a68d7b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -59,3 +59,7 @@ ADD_TEST(MaterialTestCompile ${LATEST_TEST} testCompile) CREATE_TEST(testvector.h testvector.cpp testvector) ADD_TEST(VectorLengthTest ${LATEST_TEST} testLength) ADD_TEST(VectorDotProductTest ${LATEST_TEST} testDotProduct) + +# Volume subclass tests +CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass) +ADD_TEST(VolumeSubclassExtractSurfaceTest ${LATEST_TEST} testExtractSurface) diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp new file mode 100644 index 00000000..4ed1e4aa --- /dev/null +++ b/tests/TestVolumeSubclass.cpp @@ -0,0 +1,129 @@ +/******************************************************************************* +Copyright (c) 2010 Matt 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. +*******************************************************************************/ + +#include "TestVolumeSubclass.h" + +#include "PolyVoxCore/Array.h" +#include "PolyVoxCore/CubicSurfaceExtractor.h" +#include "PolyVoxCore/Material.h" +#include "PolyVoxCore/Vector.h" +#include "PolyVoxCore/Volume.h" + +#include + +using namespace PolyVox; + +template +class VolumeSubclass : public Volume +{ +public: + typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn + class Sampler : public VolumeOfVoxelType::template Sampler< VolumeSubclass > + { + public: + Sampler(VolumeSubclass* volume) + :Volume::template Sampler< VolumeSubclass >(volume) + { + this->mVolume = volume; + } + //~Sampler(); + }; + + /// Constructor for creating a fixed size volume. + VolumeSubclass(const Region& regValid) + :Volume(regValid) + { + mVolumeData.resize(ArraySizes(this->getWidth())(this->getHeight())(this->getDepth())); + } + /// Destructor + ~VolumeSubclass() {}; + + /// Gets the value used for voxels which are outside the volume + VoxelType getBorderValue(void) const { return 0; } + /// Gets a voxel at the position given by x,y,z coordinates + VoxelType getVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos) const + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + { + return mVolumeData[uXPos][uYPos][uZPos]; + } + else + { + return getBorderValue(); + } + } + /// Gets a voxel at the position given by a 3D vector + VoxelType getVoxelAt(const Vector3DInt32& v3dPos) const { return getVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } + + /// Sets the value used for voxels which are outside the volume + void setBorderValue(const VoxelType& tBorder) { } + /// Sets the voxel at the position given by x,y,z coordinates + bool setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) + { + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + { + mVolumeData[uXPos][uYPos][uZPos] = tValue; + return true; + } + else + { + return false; + } + } + /// Sets the voxel at the position given by a 3D vector + bool setVoxelAt(const Vector3DInt32& v3dPos, VoxelType tValue) { return setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); } + + /// Calculates approximatly how many bytes of memory the volume is currently using. + uint32_t calculateSizeInBytes(void) { return 0; } + + /// Deprecated - I don't think we should expose this function? Let us know if you disagree... + //void resize(const Region& regValidRegion); + +private: + Array<3, VoxelType> mVolumeData; +}; + +void TestVolumeSubclass::testExtractSurface() +{ + VolumeSubclass volumeSubclass(Region(0,0,0,16,16,16)); + + for(int32_t z = 0; z < volumeSubclass.getDepth() / 2; z++) + { + for(int32_t y = 0; y < volumeSubclass.getHeight(); y++) + { + for(int32_t x = 0; x < volumeSubclass.getWidth(); x++) + { + Material8 mat(1); + volumeSubclass.setVoxelAt(Vector3DInt32(x,y,z),mat); + } + } + } + + SurfaceMesh result; + CubicSurfaceExtractor cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result); + cubicSurfaceExtractor.execute(); + + QCOMPARE(result.getNoOfVertices(), static_cast(8)); +} + +QTEST_MAIN(TestVolumeSubclass) diff --git a/tests/TestVolumeSubclass.h b/tests/TestVolumeSubclass.h new file mode 100644 index 00000000..46e86bd8 --- /dev/null +++ b/tests/TestVolumeSubclass.h @@ -0,0 +1,37 @@ +/******************************************************************************* +Copyright (c) 2010 Matt 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_TestVolumeSubclass_H__ +#define __PolyVox_TestVolumeSubclass_H__ + +#include + +class TestVolumeSubclass: public QObject +{ + Q_OBJECT + + private slots: + void testExtractSurface(); +}; + +#endif