From ba827d446bbe869fcea022a4937097366283f995 Mon Sep 17 00:00:00 2001 From: David Williams Date: Fri, 30 Nov 2012 23:47:03 +0100 Subject: [PATCH] Added 'containsPoint' functions which take separate components instead of vectors. --- .../include/PolyVoxCore/RawVolumeSampler.inl | 17 +++--- .../PolyVoxCore/include/PolyVoxCore/Region.h | 4 ++ library/PolyVoxCore/source/Region.cpp | 58 ++++++++++++++----- 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 39f7c0f0..4d8db5ed 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -546,8 +546,7 @@ namespace PolyVox int32_t zPos = this->mZPosInVolume; //FIXME - Can we speed this up? - //FIXME - replace with versions which don't build Vector3DInt32. - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos), 1)) + if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 1)) { //We're well inside the region so all flags can be set. m_uValidFlags = Current | PositiveX | NegativeX | PositiveY | NegativeY | PositiveZ | NegativeZ; @@ -556,13 +555,13 @@ namespace PolyVox { m_uValidFlags = 0; //FIXME - replace with versions which don't build Vector3DInt32. - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos), 0)) m_uValidFlags |= Current; - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos+1, yPos, zPos), 0)) m_uValidFlags |= PositiveX; - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos-1, yPos, zPos), 0)) m_uValidFlags |= NegativeX; - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos+1, zPos), 0)) m_uValidFlags |= PositiveY; - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos-1, zPos), 0)) m_uValidFlags |= NegativeY; - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos+1), 0)) m_uValidFlags |= PositiveZ; - if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos-1), 0)) m_uValidFlags |= NegativeZ; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 0)) m_uValidFlags |= Current; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos+1, yPos, zPos, 0)) m_uValidFlags |= PositiveX; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos-1, yPos, zPos, 0)) m_uValidFlags |= NegativeX; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos+1, zPos, 0)) m_uValidFlags |= PositiveY; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos-1, zPos, 0)) m_uValidFlags |= NegativeY; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos+1, 0)) m_uValidFlags |= PositiveZ; + if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos-1, 0)) m_uValidFlags |= NegativeZ; } } } \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index ae674a19..771a2015 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -128,9 +128,13 @@ namespace PolyVox /// Sets the position of the upper corner. void setUpperCorner(const Vector3DInt32& v3dUpperCorner); + /// Tests whether the given point is contained in this Region. + bool containsPoint(float fX, float fY, float fZ, float boundary = 0.0f) const; /// Tests whether the given point is contained in this Region. bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const; /// Tests whether the given point is contained in this Region. + bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary = 0) const; + /// Tests whether the given point is contained in this Region. bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const; /// Tests whether the given position is contained in the 'x' range of this Region. bool containsPointInX(float pos, float boundary = 0.0f) const; diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index a3aafc6b..6fa81738 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -163,34 +163,62 @@ namespace PolyVox /// The boundary value can be used to ensure a position is only considered to be inside /// the Region if it is that far in in all directions. Also, the test is inclusive such /// that positions lying exactly on the edge of the Region are considered to be inside it. - /// \param pos The position to test. + /// \param fX The 'x' position of the point to test. + /// \param fY The 'y' position of the point to test. + /// \param fZ The 'z' position of the point to test. /// \param boundary The desired boundary value. //////////////////////////////////////////////////////////////////////////////// - bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const + bool Region::containsPoint(float fX, float fY, float fZ, float boundary) const { - return (pos.getX() <= m_iUpperX - boundary) - && (pos.getY() <= m_iUpperY - boundary) - && (pos.getZ() <= m_iUpperZ - boundary) - && (pos.getX() >= m_iLowerX + boundary) - && (pos.getY() >= m_iLowerY + boundary) - && (pos.getZ() >= m_iLowerZ + boundary); + return (fX <= m_iUpperX - boundary) + && (fY <= m_iUpperY - boundary) + && (fZ <= m_iUpperZ - boundary) + && (fX >= m_iLowerX + boundary) + && (fY >= m_iLowerY + boundary) + && (fZ >= m_iLowerZ + boundary); } //////////////////////////////////////////////////////////////////////////////// /// The boundary value can be used to ensure a position is only considered to be inside /// the Region if it is that far in in all directions. Also, the test is inclusive such /// that positions lying exactly on the edge of the Region are considered to be inside it. - /// \param pos The position to test. + /// \param pos The position of the point to test. + /// \param boundary The desired boundary value. + //////////////////////////////////////////////////////////////////////////////// + bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const + { + return containsPoint(pos.getX(), pos.getY(), pos.getZ(), boundary); + } + + //////////////////////////////////////////////////////////////////////////////// + /// The boundary value can be used to ensure a position is only considered to be inside + /// the Region if it is that far in in all directions. Also, the test is inclusive such + /// that positions lying exactly on the edge of the Region are considered to be inside it. + /// \param iX The 'x' position of the point to test. + /// \param iY The 'y' position of the point to test. + /// \param iZ The 'z' position of the point to test. + /// \param boundary The desired boundary value. + //////////////////////////////////////////////////////////////////////////////// + bool Region::containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary) const + { + return (iX <= m_iUpperX - boundary) + && (iY <= m_iUpperY - boundary) + && (iZ <= m_iUpperZ - boundary) + && (iX >= m_iLowerX + boundary) + && (iY >= m_iLowerY + boundary) + && (iZ >= m_iLowerZ + boundary); + } + + //////////////////////////////////////////////////////////////////////////////// + /// The boundary value can be used to ensure a position is only considered to be inside + /// the Region if it is that far in in all directions. Also, the test is inclusive such + /// that positions lying exactly on the edge of the Region are considered to be inside it. + /// \param pos The position of the point to test. /// \param boundary The desired boundary value. //////////////////////////////////////////////////////////////////////////////// bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const { - return (pos.getX() <= m_iUpperX - boundary) - && (pos.getY() <= m_iUpperY - boundary) - && (pos.getZ() <= m_iUpperZ - boundary) - && (pos.getX() >= m_iLowerX + boundary) - && (pos.getY() >= m_iLowerY + boundary) - && (pos.getZ() >= m_iLowerZ + boundary); + return containsPoint(pos.getX(), pos.getY(), pos.getZ(), boundary); } ////////////////////////////////////////////////////////////////////////////////