From bd6efe8c3c8c1cd9dcb19d91b1c8a978e73cf52c Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 4 Mar 2015 22:42:14 +0100 Subject: [PATCH] Stuff related to valid regions is being moved from BaseVolum to RawVolume, as PagedVolume is now infinite. --- include/PolyVox/Array.h | 2 +- include/PolyVox/BaseVolume.h | 41 +--------- include/PolyVox/BaseVolume.inl | 97 +----------------------- include/PolyVox/BaseVolumeSampler.inl | 20 ----- include/PolyVox/PagedVolume.h | 2 +- include/PolyVox/PagedVolume.inl | 17 ++--- include/PolyVox/PagedVolumeSampler.inl | 10 --- include/PolyVox/RawVolume.h | 41 +++++++++- include/PolyVox/RawVolume.inl | 100 ++++++++++++++++++++++++- include/PolyVox/RawVolumeSampler.inl | 25 +++++++ tests/TestVolumeSubclass.cpp | 19 ++--- 11 files changed, 185 insertions(+), 189 deletions(-) diff --git a/include/PolyVox/Array.h b/include/PolyVox/Array.h index 68f54db5..2a34bc4f 100644 --- a/include/PolyVox/Array.h +++ b/include/PolyVox/Array.h @@ -98,7 +98,7 @@ namespace PolyVox return m_pElements[z * m_uDimensions[0] * m_uDimensions[1] + y * m_uDimensions[0] + x]; } - uint32_t getDimension(uint32_t dimension) + uint32_t getDimension(uint32_t dimension) const { return m_uDimensions[dimension]; } diff --git a/include/PolyVox/BaseVolume.h b/include/PolyVox/BaseVolume.h index f566e92f..5a401ec6 100644 --- a/include/PolyVox/BaseVolume.h +++ b/include/PolyVox/BaseVolume.h @@ -70,8 +70,6 @@ namespace PolyVox Vector3DInt32 getPosition(void) const; inline VoxelType getVoxel(void) const; - bool isCurrentPositionValid(void) const; - void setPosition(const Vector3DInt32& v3dNewPos); void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); inline bool setVoxel(VoxelType tValue); @@ -127,32 +125,10 @@ namespace PolyVox WrapMode m_eWrapMode; VoxelType m_tBorder; - - //Whether the current position is inside the volume - //FIXME - Replace these with flags - bool m_bIsCurrentPositionValidInX; - bool m_bIsCurrentPositionValidInY; - bool m_bIsCurrentPositionValidInZ; }; #endif public: - /// Gets the value used for voxels which are outside the volume - VoxelType getBorderValue(void) const; - /// Gets a Region representing the extents of the Volume. - const 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 template @@ -166,8 +142,6 @@ namespace PolyVox /// Gets a voxel at the position given by a 3D vector VoxelType getVoxel(const Vector3DInt32& v3dPos, WrapMode eWrapMode = WrapModes::Validate, VoxelType tBorder = VoxelType()) 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 void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue, WrapMode eWrapMode = WrapModes::Validate); /// Sets the voxel at the position given by a 3D vector @@ -177,8 +151,8 @@ namespace PolyVox uint32_t calculateSizeInBytes(void); protected: - /// Constructor for creating a fixed size volume. - BaseVolume(const Region& regValid); + /// Constructor for creating a volume. + BaseVolume(); /// Copy constructor BaseVolume(const BaseVolume& rhs); @@ -188,17 +162,6 @@ namespace PolyVox /// Assignment operator BaseVolume& operator=(const BaseVolume& rhs); - - //The size of the volume - Region m_regValidRegion; - - //Some useful sizes - int32_t m_uLongestSideLength; - int32_t m_uShortestSideLength; - float m_fDiagonalLength; - - //The border value - VoxelType m_tBorderValue; }; } diff --git a/include/PolyVox/BaseVolume.inl b/include/PolyVox/BaseVolume.inl index 16d3a761..3fc9287a 100644 --- a/include/PolyVox/BaseVolume.inl +++ b/include/PolyVox/BaseVolume.inl @@ -29,9 +29,7 @@ namespace PolyVox /// \sa RawVolume, PagedVolume //////////////////////////////////////////////////////////////////////////////// template - BaseVolume::BaseVolume(const Region& regValid) - :m_regValidRegion(regValid) - ,m_tBorderValue() + BaseVolume::BaseVolume() { } @@ -69,90 +67,6 @@ namespace PolyVox POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons."); } - //////////////////////////////////////////////////////////////////////////////// - /// 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 BaseVolume::getBorderValue(void) const - { - return m_tBorderValue; - } - - //////////////////////////////////////////////////////////////////////////////// - /// \return A Region representing the extent of the volume. - //////////////////////////////////////////////////////////////////////////////// - template - const Region& BaseVolume::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 BaseVolume::getWidth(void) const - { - return m_regValidRegion.getUpperX() - m_regValidRegion.getLowerX() + 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 BaseVolume::getHeight(void) const - { - return m_regValidRegion.getUpperY() - m_regValidRegion.getLowerY() + 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 BaseVolume::getDepth(void) const - { - return m_regValidRegion.getUpperZ() - m_regValidRegion.getLowerZ() + 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 BaseVolume::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 BaseVolume::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 BaseVolume::getDiagonalLength(void) const - { - return m_fDiagonalLength; - } - //////////////////////////////////////////////////////////////////////////////// /// This version of the function requires the wrap mode to be specified as a /// template parameter, which can provide better performance. @@ -221,15 +135,6 @@ namespace PolyVox return VoxelType(); } - //////////////////////////////////////////////////////////////////////////////// - /// \param tBorder The value to use for voxels outside the volume. - //////////////////////////////////////////////////////////////////////////////// - template - void BaseVolume::setBorderValue(const VoxelType& tBorder) - { - m_tBorderValue = tBorder; - } - //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel diff --git a/include/PolyVox/BaseVolumeSampler.inl b/include/PolyVox/BaseVolumeSampler.inl index 7021ed9f..6e0d134d 100644 --- a/include/PolyVox/BaseVolumeSampler.inl +++ b/include/PolyVox/BaseVolumeSampler.inl @@ -34,9 +34,6 @@ namespace PolyVox ,mZPosInVolume(0) ,m_eWrapMode(WrapModes::Border) ,m_tBorder() - ,m_bIsCurrentPositionValidInX(false) - ,m_bIsCurrentPositionValidInY(false) - ,m_bIsCurrentPositionValidInZ(false) { } @@ -60,13 +57,6 @@ namespace PolyVox return mVolume->getVoxel(mXPosInVolume, mYPosInVolume, mZPosInVolume); } - template - template - bool inline BaseVolume::Sampler::isCurrentPositionValid(void) const - { - return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ; - } - template template void BaseVolume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) @@ -81,10 +71,6 @@ namespace PolyVox mXPosInVolume = xPos; mYPosInVolume = yPos; mZPosInVolume = zPos; - - m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos); - m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos); - m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos); } template @@ -107,7 +93,6 @@ namespace PolyVox void BaseVolume::Sampler::movePositiveX(void) { mXPosInVolume++; - m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume); } template @@ -115,7 +100,6 @@ namespace PolyVox void BaseVolume::Sampler::movePositiveY(void) { mYPosInVolume++; - m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume); } template @@ -123,7 +107,6 @@ namespace PolyVox void BaseVolume::Sampler::movePositiveZ(void) { mZPosInVolume++; - m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume); } template @@ -131,7 +114,6 @@ namespace PolyVox void BaseVolume::Sampler::moveNegativeX(void) { mXPosInVolume--; - m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume); } template @@ -139,7 +121,6 @@ namespace PolyVox void BaseVolume::Sampler::moveNegativeY(void) { mYPosInVolume--; - m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume); } template @@ -147,7 +128,6 @@ namespace PolyVox void BaseVolume::Sampler::moveNegativeZ(void) { mZPosInVolume--; - m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume); } template diff --git a/include/PolyVox/PagedVolume.h b/include/PolyVox/PagedVolume.h index cd981863..ddea102a 100644 --- a/include/PolyVox/PagedVolume.h +++ b/include/PolyVox/PagedVolume.h @@ -320,7 +320,7 @@ namespace PolyVox uint32_t m_uChunkCountLimit; // The size of the volume - Region m_regValidRegionInChunks; + //Region m_regValidRegionInChunks; // The size of the chunks uint16_t m_uChunkSideLength; diff --git a/include/PolyVox/PagedVolume.inl b/include/PolyVox/PagedVolume.inl index 773cbbe8..5419e920 100644 --- a/include/PolyVox/PagedVolume.inl +++ b/include/PolyVox/PagedVolume.inl @@ -42,7 +42,7 @@ namespace PolyVox Pager* pPager, uint16_t uChunkSideLength ) - :BaseVolume(Region::MaxRegion()) + :BaseVolume() { m_uChunkSideLength = uChunkSideLength; m_pPager = pPager; @@ -203,11 +203,6 @@ namespace PolyVox template void PagedVolume::setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { - if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos)) == false) - { - POLYVOX_THROW(std::out_of_range, "Position is outside valid region"); - } - const int32_t chunkX = uXPos >> m_uChunkSideLengthPower; const int32_t chunkY = uYPos >> m_uChunkSideLengthPower; const int32_t chunkZ = uZPos >> m_uChunkSideLengthPower; @@ -358,12 +353,12 @@ namespace PolyVox //Compute the chunk side length m_uChunkSideLengthPower = logBase2(m_uChunkSideLength); - m_regValidRegionInChunks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uChunkSideLengthPower); + /*m_regValidRegionInChunks.setLowerX(this->m_regValidRegion.getLowerX() >> m_uChunkSideLengthPower); m_regValidRegionInChunks.setLowerY(this->m_regValidRegion.getLowerY() >> m_uChunkSideLengthPower); m_regValidRegionInChunks.setLowerZ(this->m_regValidRegion.getLowerZ() >> m_uChunkSideLengthPower); m_regValidRegionInChunks.setUpperX(this->m_regValidRegion.getUpperX() >> m_uChunkSideLengthPower); m_regValidRegionInChunks.setUpperY(this->m_regValidRegion.getUpperY() >> m_uChunkSideLengthPower); - m_regValidRegionInChunks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uChunkSideLengthPower); + m_regValidRegionInChunks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uChunkSideLengthPower);*/ //setMaxNumberOfChunks(m_uChunkCountLimit); @@ -371,9 +366,9 @@ namespace PolyVox m_pRecentlyUsedChunks.clear(); //Other properties we might find useful later - 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())); + //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/include/PolyVox/PagedVolumeSampler.inl b/include/PolyVox/PagedVolumeSampler.inl index 74e05baa..19eff82a 100644 --- a/include/PolyVox/PagedVolumeSampler.inl +++ b/include/PolyVox/PagedVolumeSampler.inl @@ -118,16 +118,6 @@ namespace PolyVox template bool PagedVolume::Sampler::setVoxel(VoxelType tValue) { - /*if(m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ) - { - *mCurrentVoxel = tValue; - return true; - } - else - { - return false; - }*/ - //Need to think what effect this has on any existing iterators. POLYVOX_THROW(not_implemented, "This function cannot be used on PagedVolume samplers."); return false; diff --git a/include/PolyVox/RawVolume.h b/include/PolyVox/RawVolume.h index aa2f87cb..41139f78 100644 --- a/include/PolyVox/RawVolume.h +++ b/include/PolyVox/RawVolume.h @@ -57,7 +57,9 @@ namespace PolyVox Sampler(RawVolume* volume); ~Sampler(); - inline VoxelType getVoxel(void) const; + inline VoxelType getVoxel(void) const; + + bool isCurrentPositionValid(void) const; void setPosition(const Vector3DInt32& v3dNewPos); void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); @@ -105,6 +107,12 @@ namespace PolyVox //Other current position information VoxelType* mCurrentVoxel; + + //Whether the current position is inside the volume + //FIXME - Replace these with flags + bool m_bIsCurrentPositionValidInX; + bool m_bIsCurrentPositionValidInY; + bool m_bIsCurrentPositionValidInZ; }; #endif @@ -115,11 +123,31 @@ namespace PolyVox /// Destructor ~RawVolume(); + /// Gets the value used for voxels which are outside the volume + VoxelType getBorderValue(void) const; + /// Gets a Region representing the extents of the Volume. + const 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 getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const; /// Gets a voxel at the position given by a 3D vector VoxelType getVoxel(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 void setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue); /// Sets the voxel at the position given by a 3D vector @@ -138,6 +166,17 @@ namespace PolyVox private: void initialise(const Region& regValidRegion); + //The size of the volume + Region m_regValidRegion; + + //Some useful sizes + int32_t m_uLongestSideLength; + int32_t m_uShortestSideLength; + float m_fDiagonalLength; + + //The border value + VoxelType m_tBorderValue; + //The voxel data VoxelType* m_pData; }; diff --git a/include/PolyVox/RawVolume.inl b/include/PolyVox/RawVolume.inl index 51429dbc..2f0419d5 100644 --- a/include/PolyVox/RawVolume.inl +++ b/include/PolyVox/RawVolume.inl @@ -29,7 +29,9 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// template RawVolume::RawVolume(const Region& regValid) - :BaseVolume(regValid) + :BaseVolume() + , m_regValidRegion(regValid) + , m_tBorderValue() { this->setBorderValue(VoxelType()); @@ -73,6 +75,90 @@ namespace PolyVox POLYVOX_THROW(not_implemented, "Volume assignment operator not implemented for performance reasons."); } + //////////////////////////////////////////////////////////////////////////////// + /// 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 RawVolume::getBorderValue(void) const + { + return m_tBorderValue; + } + + //////////////////////////////////////////////////////////////////////////////// + /// \return A Region representing the extent of the volume. + //////////////////////////////////////////////////////////////////////////////// + template + const 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.getUpperX() - m_regValidRegion.getLowerX() + 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.getUpperY() - m_regValidRegion.getLowerY() + 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.getUpperZ() - m_regValidRegion.getLowerZ() + 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; + } + //////////////////////////////////////////////////////////////////////////////// /// This version of the function is provided so that the wrap mode does not need /// to be specified as a template parameter, as it may be confusing to some users. @@ -120,6 +206,15 @@ namespace PolyVox return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } + //////////////////////////////////////////////////////////////////////////////// + /// \param tBorder The value to use for voxels outside the volume. + //////////////////////////////////////////////////////////////////////////////// + template + void RawVolume::setBorderValue(const VoxelType& tBorder) + { + m_tBorderValue = tBorder; + } + //////////////////////////////////////////////////////////////////////////////// /// \param uXPos the \c x position of the voxel /// \param uYPos the \c y position of the voxel @@ -185,6 +280,9 @@ namespace PolyVox //Create the data m_pData = new VoxelType[this->getWidth() * this->getHeight()* this->getDepth()]; + // Clear to zeros + std::fill(m_pData, m_pData + this->getWidth() * this->getHeight()* this->getDepth(), VoxelType()); + //Other properties we might find useful later 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()); diff --git a/include/PolyVox/RawVolumeSampler.inl b/include/PolyVox/RawVolumeSampler.inl index 2eb3fab4..a1ff0bec 100644 --- a/include/PolyVox/RawVolumeSampler.inl +++ b/include/PolyVox/RawVolumeSampler.inl @@ -34,6 +34,9 @@ namespace PolyVox RawVolume::Sampler::Sampler(RawVolume* volume) :BaseVolume::template Sampler< RawVolume >(volume) ,mCurrentVoxel(0) + , m_bIsCurrentPositionValidInX(false) + , m_bIsCurrentPositionValidInY(false) + , m_bIsCurrentPositionValidInZ(false) { } @@ -55,6 +58,12 @@ namespace PolyVox } } + template + bool inline RawVolume::Sampler::isCurrentPositionValid(void) const + { + return m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ; + } + template void RawVolume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) { @@ -67,6 +76,10 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::setPosition(xPos, yPos, zPos); + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos); + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos); + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos); + // Then we update the voxel pointer if(this->isCurrentPositionValid()) { @@ -111,6 +124,8 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::movePositiveX(); + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume); + // Then we update the voxel pointer if(this->isCurrentPositionValid() && bIsOldPositionValid ) { @@ -131,6 +146,8 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::movePositiveY(); + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume); + // Then we update the voxel pointer if(this->isCurrentPositionValid() && bIsOldPositionValid ) { @@ -151,6 +168,8 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::movePositiveZ(); + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume); + // Then we update the voxel pointer if(this->isCurrentPositionValid() && bIsOldPositionValid ) { @@ -171,6 +190,8 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::moveNegativeX(); + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(mXPosInVolume); + // Then we update the voxel pointer if(this->isCurrentPositionValid() && bIsOldPositionValid ) { @@ -191,6 +212,8 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::moveNegativeY(); + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(mYPosInVolume); + // Then we update the voxel pointer if(this->isCurrentPositionValid() && bIsOldPositionValid ) { @@ -211,6 +234,8 @@ namespace PolyVox // Base version updates position and validity flags. BaseVolume::template Sampler< RawVolume >::moveNegativeZ(); + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(mZPosInVolume); + // Then we update the voxel pointer if(this->isCurrentPositionValid() && bIsOldPositionValid ) { diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index ea62537b..eb5238ca 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -62,8 +62,8 @@ public: /// Constructor for creating a fixed size volume. VolumeSubclass(const Region& regValid) - :BaseVolume(regValid) - , mVolumeData(this->getWidth(), this->getHeight(), this->getDepth()) + :BaseVolume() + , mVolumeData(regValid.getWidthInVoxels(), regValid.getHeightInVoxels(), regValid.getDepthInVoxels()) { //mVolumeData.resize(ArraySizes(this->getWidth())(this->getHeight())(this->getDepth())); } @@ -73,7 +73,7 @@ public: /// Gets a voxel at the position given by x,y,z coordinates VoxelType getVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos) const { - if(this->m_regValidRegion.containsPoint(uXPos, uYPos, uZPos)) + if ((uXPos < mVolumeData.getDimension(0)) && (uYPos < mVolumeData.getDimension(1)) && (uZPos < mVolumeData.getDimension(2))) { return mVolumeData(uXPos, uYPos, uZPos); } @@ -94,7 +94,7 @@ public: /// Sets the voxel at the position given by x,y,z coordinates bool setVoxel(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { - if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + if ((uXPos < mVolumeData.getDimension(0)) && (uYPos < mVolumeData.getDimension(1)) && (uZPos < mVolumeData.getDimension(2))) { mVolumeData(uXPos, uYPos, uZPos) = tValue; return true; @@ -119,13 +119,14 @@ private: void TestVolumeSubclass::testExtractSurface() { - VolumeSubclass volumeSubclass(Region(0,0,0,16,16,16)); + Region region(0, 0, 0, 16, 16, 16); + VolumeSubclass volumeSubclass(region); - for(int32_t z = 0; z < volumeSubclass.getDepth() / 2; z++) + for (int32_t z = 0; z < region.getDepthInVoxels() / 2; z++) { - for(int32_t y = 0; y < volumeSubclass.getHeight(); y++) + for (int32_t y = 0; y < region.getHeightInVoxels(); y++) { - for(int32_t x = 0; x < volumeSubclass.getWidth(); x++) + for (int32_t x = 0; x < region.getWidthInVoxels(); x++) { Material8 mat(1); volumeSubclass.setVoxel(Vector3DInt32(x,y,z),mat); @@ -133,7 +134,7 @@ void TestVolumeSubclass::testExtractSurface() } } - auto result = extractCubicMesh(&volumeSubclass, volumeSubclass.getEnclosingRegion()); + auto result = extractCubicMesh(&volumeSubclass, region); QCOMPARE(result.getNoOfVertices(), static_cast(8)); }