From 2a12bcd6d67e92ca235727531ecb746acf69f435 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 18 Dec 2012 14:34:36 +0100 Subject: [PATCH 1/6] Fixed behavior of SimpleVolumeSampler.inl --- .../PolyVoxCore/SimpleVolumeSampler.inl | 66 +++++++++++-------- tests/testvolume.cpp | 4 +- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 7920fc6b..d324b966 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -26,6 +26,13 @@ freely, subject to the following restrictions: //#define BORDER_LOW(x) (( x % this->mVolume->m_uBlockSideLength) != 0) //#define BORDER_HIGH(x) (( x % this->mVolume->m_uBlockSideLength) != this->mVolume->m_uBlockSideLength - 1) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) + namespace PolyVox { /** @@ -299,7 +306,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -309,7 +316,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } @@ -319,7 +326,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -329,7 +336,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -339,7 +346,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) ) { return *(mCurrentVoxel - 1); } @@ -349,7 +356,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -359,7 +366,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -369,7 +376,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } @@ -379,7 +386,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1nx1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -391,7 +398,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -401,7 +408,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } @@ -411,7 +418,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -421,7 +428,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -441,7 +448,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -451,7 +458,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -461,7 +468,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } @@ -471,7 +478,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel0px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -483,7 +490,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -493,7 +500,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } @@ -503,7 +510,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -513,7 +520,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -523,7 +530,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) ) { return *(mCurrentVoxel + 1); } @@ -533,7 +540,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -543,7 +550,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -553,7 +560,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } @@ -563,7 +570,7 @@ namespace PolyVox template VoxelType SimpleVolume::Sampler::peekVoxel1px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -571,5 +578,12 @@ namespace PolyVox } } +#undef CAN_GO_NEG_X +#undef CAN_GO_POS_X +#undef CAN_GO_NEG_Y +#undef CAN_GO_POS_Y +#undef CAN_GO_NEG_Z +#undef CAN_GO_POS_Z + #undef BORDER_LOW #undef BORDER_HIGH diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 088670b2..8913d915 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -321,12 +321,12 @@ void TestVolume::testSimpleVolumeDirectAccess() void TestVolume::testSimpleVolumeSamplers() { - /*int32_t result = 0; + int32_t result = 0; QBENCHMARK { result = testSamplersWithWrapping(m_pSimpleVolume); } - QCOMPARE(result, static_cast(-601818385)); //FXME - Wrong value?!*/ + QCOMPARE(result, static_cast(-928601007)); } void TestVolume::testLargeVolumeDirectAccess() From 8b018be2dc67a65b4fea84c8b62a6170d7028239 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 18 Dec 2012 16:25:31 +0100 Subject: [PATCH 2/6] Fix for LargeVolumeSampler. --- .../PolyVoxCore/LargeVolumeSampler.inl | 70 ++++++++++--------- .../PolyVoxCore/SimpleVolumeSampler.inl | 20 ++---- tests/testvolume.cpp | 8 +-- 3 files changed, 48 insertions(+), 50 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 530fafc0..b6f3fc4f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -21,10 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#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) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) namespace PolyVox { @@ -280,7 +282,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -290,7 +292,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength); } @@ -300,7 +302,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -310,7 +312,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -320,7 +322,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) ) { return *(mCurrentVoxel - 1); } @@ -330,7 +332,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -340,7 +342,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -350,7 +352,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength); } @@ -360,7 +362,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1nx1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -372,7 +374,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -382,7 +384,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength); } @@ -392,7 +394,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -402,7 +404,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -422,7 +424,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -432,7 +434,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -442,7 +444,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength); } @@ -452,7 +454,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel0px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -464,7 +466,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -474,7 +476,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength); } @@ -484,7 +486,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1ny1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -494,7 +496,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px0py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -504,7 +506,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px0py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) ) { return *(mCurrentVoxel + 1); } @@ -514,7 +516,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px0py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -524,7 +526,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1py1nz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_LOW(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_NEG_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength - this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -534,7 +536,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1py0pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength); } @@ -544,7 +546,7 @@ namespace PolyVox template VoxelType LargeVolume::Sampler::peekVoxel1px1py1pz(void) const { - if((this->isCurrentPositionValid()) && BORDER_HIGH(this->mXPosInVolume) && BORDER_HIGH(this->mYPosInVolume) && BORDER_HIGH(this->mZPosInVolume) ) + if((this->isCurrentPositionValid()) && CAN_GO_POS_X(this->mXPosInVolume) && CAN_GO_POS_Y(this->mYPosInVolume) && CAN_GO_POS_Z(this->mZPosInVolume) ) { return *(mCurrentVoxel + 1 + this->mVolume->m_uBlockSideLength + this->mVolume->m_uBlockSideLength*this->mVolume->m_uBlockSideLength); } @@ -552,5 +554,9 @@ namespace PolyVox } } -#undef BORDER_LOW -#undef BORDER_HIGH +#undef CAN_GO_NEG_X +#undef CAN_GO_POS_X +#undef CAN_GO_NEG_Y +#undef CAN_GO_POS_Y +#undef CAN_GO_NEG_Z +#undef CAN_GO_POS_Z diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index d324b966..8e8deddf 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -21,17 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#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) - -#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) -#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) -#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) -#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) -#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && ((( val >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != val)) -#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((( (val+1) >> this->mVolume->m_uBlockSideLengthPower) << this->mVolume->m_uBlockSideLengthPower) != (val+1))) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) namespace PolyVox { @@ -584,6 +579,3 @@ namespace PolyVox #undef CAN_GO_POS_Y #undef CAN_GO_NEG_Z #undef CAN_GO_POS_Z - -#undef BORDER_LOW -#undef BORDER_HIGH diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 8913d915..47130f95 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -331,23 +331,23 @@ void TestVolume::testSimpleVolumeSamplers() void TestVolume::testLargeVolumeDirectAccess() { - /*int32_t result = 0; + int32_t result = 0; QBENCHMARK { result = testDirectAccessWithWrapping(m_pLargeVolume); } - QCOMPARE(result, static_cast(-601818385)); //FXME - Wrong value?!*/ + QCOMPARE(result, static_cast(-928601007)); } void TestVolume::testLargeVolumeSamplers() { int32_t result = 0; - /*QBENCHMARK + QBENCHMARK { result = testSamplersWithWrapping(m_pLargeVolume); } - QCOMPARE(result, static_cast(-601818385)); //FXME - Wrong value?!*/ + QCOMPARE(result, static_cast(-928601007)); } QTEST_MAIN(TestVolume) From 4396c609bbab4c8580a9e620401cc609245d020b Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 18 Dec 2012 16:46:57 +0100 Subject: [PATCH 3/6] Added wrap mode support to CubicSurfaceExtractor. --- .../include/PolyVoxCore/CubicSurfaceExtractor.h | 7 ++++++- .../include/PolyVoxCore/CubicSurfaceExtractor.inl | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 76f53f89..524132b6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -29,6 +29,7 @@ freely, subject to the following restrictions: #include "PolyVoxForwardDeclarations.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/DefaultIsQuadNeeded.h" #include "PolyVoxCore/SurfaceMesh.h" @@ -109,7 +110,7 @@ namespace PolyVox }; public: - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); @@ -145,6 +146,10 @@ namespace PolyVox //This constant defines the maximum number of quads which can share a //vertex in a cubic style mesh. See the initialisation for more details. static const uint32_t MaxVerticesPerPosition; + + //The wrap mode + WrapMode m_eWrapMode; + typename VolumeType::VoxelType m_tBorderValue; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 211498c9..c9b793f5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -35,11 +35,13 @@ namespace PolyVox const uint32_t CubicSurfaceExtractor::MaxVerticesPerPosition = 6; template - CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, bool bMergeQuads, IsQuadNeeded isQuadNeeded) + CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) ,m_bMergeQuads(bMergeQuads) + ,m_eWrapMode(eWrapMode) + ,m_tBorderValue(tBorderValue) { m_funcIsQuadNeededCallback = isQuadNeeded; } @@ -68,6 +70,7 @@ namespace PolyVox m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2); typename VolumeType::Sampler volumeSampler(m_volData); + volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue); for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ(); z++) { From 933c211d47ef32f70fba25cd41c4fefeb88b4fc4 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 19 Dec 2012 11:23:55 +0100 Subject: [PATCH 4/6] Added wrap mode support to CubicSurfaceExtractorWithNormals. --- .../CubicSurfaceExtractorWithNormals.h | 7 ++++++- .../CubicSurfaceExtractorWithNormals.inl | 16 +++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h index cf5bd70e..0d9f61bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/DefaultIsQuadNeeded.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/SurfaceMesh.h" namespace PolyVox @@ -35,7 +36,7 @@ namespace PolyVox class CubicSurfaceExtractorWithNormals { public: - CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), IsQuadNeeded isQuadNeeded = IsQuadNeeded()); void execute(); @@ -51,6 +52,10 @@ namespace PolyVox //Information about the region we are currently processing Region m_regSizeInVoxels; + + //The wrap mode + WrapMode m_eWrapMode; + typename VolumeType::VoxelType m_tBorderValue; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index e3c5ca34..5e16d3b8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -24,11 +24,13 @@ freely, subject to the following restrictions: namespace PolyVox { template - CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, IsQuadNeeded isQuadNeeded) + CubicSurfaceExtractorWithNormals::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) ,m_regSizeInVoxels(region) + ,m_eWrapMode(eWrapMode) + ,m_tBorderValue(tBorderValue) { m_funcIsQuadNeededCallback = isQuadNeeded; } @@ -51,7 +53,7 @@ namespace PolyVox uint32_t material = 0; - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x+1,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(1.0f, 0.0f, 0.0f), static_cast(material))); @@ -61,7 +63,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v2,v1); m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x+1,y,z), m_volData->getVoxelAt(x,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x+1,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ - 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX + 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(-1.0f, 0.0f, 0.0f), static_cast(material))); @@ -72,7 +74,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v3,v2); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y+1,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 1.0f, 0.0f), static_cast(material))); @@ -82,7 +84,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v1,v2); m_meshCurrent->addTriangleCubic(v1,v3,v2); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y+1,z), m_volData->getVoxelAt(x,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y+1,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ - 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, -1.0f, 0.0f), static_cast(material))); @@ -93,7 +95,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z), m_volData->getVoxelAt(x,y,z+1), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, 1.0f), static_cast(material))); @@ -103,7 +105,7 @@ namespace PolyVox m_meshCurrent->addTriangleCubic(v0,v2,v1); m_meshCurrent->addTriangleCubic(v1,v2,v3); } - if(m_funcIsQuadNeededCallback(m_volData->getVoxelAt(x,y,z+1), m_volData->getVoxelAt(x,y,z), material)) + if(m_funcIsQuadNeededCallback(m_volData->getVoxelWithWrapping(x,y,z+1,m_eWrapMode,m_tBorderValue), m_volData->getVoxelWithWrapping(x,y,z,m_eWrapMode,m_tBorderValue), material)) { uint32_t v0 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY - 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); uint32_t v1 = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(regX - 0.5f, regY + 0.5f, regZ + 0.5f), Vector3DFloat(0.0f, 0.0f, -1.0f), static_cast(material))); From 44dcb0ba898cef8c10c1a97616efeddf55d776d6 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 19 Dec 2012 11:32:45 +0100 Subject: [PATCH 5/6] Different method of controlling the war mode of the MarchingCubesSurfaceExtractor. --- .../include/PolyVoxCore/MarchingCubesSurfaceExtractor.h | 3 ++- .../include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl | 4 ++-- tests/TestSurfaceExtractor.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index b0d7c694..6473a3d4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -28,6 +28,7 @@ freely, subject to the following restrictions: #include "Impl/TypeDef.h" #include "PolyVoxCore/Array.h" +#include "PolyVoxCore/BaseVolume.h" //For wrap modes... should move these? #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/DefaultMarchingCubesController.h" @@ -37,7 +38,7 @@ namespace PolyVox class MarchingCubesSurfaceExtractor { public: - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(0), Controller controller = Controller()); void execute(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 23617603..1ca352eb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -24,7 +24,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, Controller controller) + MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -36,7 +36,7 @@ namespace PolyVox m_regSizeInCells = m_regSizeInVoxels; m_regSizeInCells.setUpperCorner(m_regSizeInCells.getUpperCorner() - Vector3DInt32(1,1,1)); - m_sampVolume.setWrapMode(m_controller.getWrapMode(), m_controller.getBorderValue()); + m_sampVolume.setWrapMode(eWrapMode, tBorderValue); } template diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 4bc7fc15..6114935d 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -132,7 +132,7 @@ void testForType(SurfaceMesh& result) DefaultMarchingCubesController controller; controller.setThreshold(50); - MarchingCubesSurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, controller); + MarchingCubesSurfaceExtractor< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, 0, controller); extractor.execute(); } @@ -156,7 +156,7 @@ void testCustomController(SurfaceMesh& result) } CustomMarchingCubesController controller; - MarchingCubesSurfaceExtractor< SimpleVolume, CustomMarchingCubesController > extractor(&volData, volData.getEnclosingRegion(), &result, controller); + MarchingCubesSurfaceExtractor< SimpleVolume, CustomMarchingCubesController > extractor(&volData, volData.getEnclosingRegion(), &result, WrapModes::Border, 0, controller); extractor.execute(); } From 898aa241264aa29324a0dcf68b8534431f581fd0 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Wed, 19 Dec 2012 11:46:44 +0100 Subject: [PATCH 6/6] Removed code which is redundant after previous commit. --- .../DefaultMarchingCubesController.h | 20 ------------------- .../PolyVoxCore/include/PolyVoxCore/Density.h | 19 ------------------ .../include/PolyVoxCore/MaterialDensityPair.h | 14 ------------- tests/TestSurfaceExtractor.cpp | 10 ---------- 4 files changed, 63 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h index 8d5359e9..7be8dc9e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/DefaultMarchingCubesController.h @@ -78,8 +78,6 @@ namespace PolyVox */ DefaultMarchingCubesController(void) :m_tThreshold(((std::numeric_limits::min)() + (std::numeric_limits::max)()) / 2) - ,m_eWrapMode(WrapModes::Border) - ,m_tBorder(VoxelType(0)) { } @@ -105,11 +103,6 @@ namespace PolyVox return 1; } - VoxelType getBorderValue(void) - { - return m_tBorder; - } - /** * Returns the density value which was passed to the constructor. * @@ -122,26 +115,13 @@ namespace PolyVox return m_tThreshold; } - WrapMode getWrapMode(void) - { - return m_eWrapMode; - } - void setThreshold(DensityType tThreshold) { m_tThreshold = tThreshold; } - void setWrapMode(WrapMode eWrapMode, VoxelType tBorder = VoxelType(0)) - { - m_eWrapMode = eWrapMode; - m_tBorder = tBorder; - } - private: DensityType m_tThreshold; - WrapMode m_eWrapMode; - VoxelType m_tBorder; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index a92d23b9..4d60ad53 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -155,13 +155,11 @@ namespace PolyVox { // Default to a threshold value halfway between the min and max possible values. m_tThreshold = (Density::getMinDensity() + Density::getMaxDensity()) / 2; - m_eWrapMode = WrapModes::Border; } DefaultMarchingCubesController(DensityType tThreshold) { m_tThreshold = tThreshold; - m_eWrapMode = WrapModes::Border; } DensityType convertToDensity(Density voxel) @@ -174,35 +172,18 @@ namespace PolyVox return 1; } - Density getBorderValue(void) - { - return m_tBorder; - } - DensityType getThreshold(void) { return m_tThreshold; } - WrapMode getWrapMode(void) - { - return m_eWrapMode; - } - void setThreshold(DensityType tThreshold) { m_tThreshold = tThreshold; } - void setWrapMode(WrapMode eWrapMode) - { - m_eWrapMode = eWrapMode; - } - private: DensityType m_tThreshold; - WrapMode m_eWrapMode; - Density m_tBorder; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index d3df49b8..ec8fb874 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -119,13 +119,11 @@ namespace PolyVox { // Default to a threshold value halfway between the min and max possible values. m_tThreshold = (MaterialDensityPair::getMinDensity() + MaterialDensityPair::getMaxDensity()) / 2; - m_eWrapMode = WrapModes::Border; } DefaultMarchingCubesController(DensityType tThreshold) { m_tThreshold = tThreshold; - m_eWrapMode = WrapModes::Border; } DensityType convertToDensity(MaterialDensityPair voxel) @@ -148,25 +146,13 @@ namespace PolyVox return m_tThreshold; } - WrapMode getWrapMode(void) - { - return m_eWrapMode; - } - void setThreshold(DensityType tThreshold) { m_tThreshold = tThreshold; } - void setWrapMode(WrapMode eWrapMode) - { - m_eWrapMode = eWrapMode; - } - private: DensityType m_tThreshold; - WrapMode m_eWrapMode; - MaterialDensityPair m_tBorder; }; typedef MaterialDensityPair MaterialDensityPair44; diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 6114935d..80416eb4 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -59,16 +59,6 @@ public: { return 50.0f; } - - WrapMode getWrapMode(void) - { - return WrapModes::Border; - } - - float getBorderValue(void) - { - return 0.0f; - } }; // These 'writeDensityValueToVoxel' functions provide a unified interface for writting densities to primative and class voxel types.