From 8dc1951a062e4a21b35924e75721646deac5ed69 Mon Sep 17 00:00:00 2001 From: David Williams Date: Tue, 26 Jul 2011 21:36:17 +0100 Subject: [PATCH] More work making volumes use a base class. --- .../include/PolyVoxCore/LargeVolume.h | 3 +- .../PolyVoxCore/LargeVolumeSampler.inl | 6 - .../include/PolyVoxCore/RawVolume.h | 3 +- .../include/PolyVoxCore/RawVolumeSampler.inl | 6 - .../include/PolyVoxCore/SimpleVolume.h | 5 +- .../PolyVoxCore/SimpleVolumeSampler.inl | 6 - .../PolyVoxCore/include/PolyVoxCore/Volume.h | 5 +- .../include/PolyVoxCore/VolumeSampler.inl | 124 +++++++++++------- library/PolyVoxCore/source/VoxelFilters.cpp | 7 - 9 files changed, 85 insertions(+), 80 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 4c111ce9..382d1957 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -145,7 +145,7 @@ namespace PolyVox class LargeVolume : public Volume { public: - class Sampler : public Volume::Sampler + class Sampler : public Volume::Sampler< LargeVolume > { public: Sampler(LargeVolume* volume); @@ -157,7 +157,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); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 2b7e5371..9e667fa1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -116,12 +116,6 @@ namespace PolyVox } } - template - const LargeVolume* LargeVolume::Sampler::getVolume(void) const - { - return mVolume; - } - template VoxelType LargeVolume::Sampler::getVoxel(void) const { diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 877a519e..02540249 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -38,7 +38,7 @@ namespace PolyVox { public: #ifndef SWIG - class Sampler : public Volume::Sampler + class Sampler : public Volume::Sampler< RawVolume > { public: Sampler(RawVolume* volume); @@ -47,7 +47,6 @@ namespace PolyVox 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); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 63aa9827..e0f9bfff 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -63,12 +63,6 @@ namespace PolyVox return mZPosInVolume; } - template - const RawVolume* RawVolume::Sampler::getVolume(void) const - { - return mVolume; - } - template VoxelType RawVolume::Sampler::getVoxel(void) const { diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 788b98aa..48ea4f35 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -40,8 +40,6 @@ namespace PolyVox #ifndef SWIG class Block { - //Make Sampler a friend - friend class SimpleVolume::Sampler; public: Block(uint16_t uSideLength = 0); @@ -62,7 +60,7 @@ namespace PolyVox uint8_t m_uSideLengthPower; }; - class Sampler : public Volume::Sampler + class Sampler : public Volume::Sampler< SimpleVolume > { public: Sampler(SimpleVolume* volume); @@ -74,7 +72,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); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index bc7dcc7c..3190a8d2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -116,12 +116,6 @@ namespace PolyVox } } - template - const SimpleVolume* SimpleVolume::Sampler::getVolume(void) const - { - return mVolume; - } - template VoxelType SimpleVolume::Sampler::getVoxel(void) const { diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h index 5b8f311b..cc6a436d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -37,13 +37,13 @@ namespace PolyVox { public: #ifndef SWIG + template class Sampler { public: int32_t getPosX(void) const; int32_t getPosY(void) const; int32_t getPosZ(void) const; - const Volume* getVolume(void) const; inline VoxelType getVoxel(void) const; void setPosition(const Vector3DInt32& v3dNewPos); @@ -86,6 +86,9 @@ namespace PolyVox inline VoxelType peekVoxel1px1py1nz(void) const; inline VoxelType peekVoxel1px1py0pz(void) const; inline VoxelType peekVoxel1px1py1pz(void) const; + + protected: + DerivedVolumeType* m_pDerivedVolume; }; #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl index 8103fd9c..6085d7a7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl @@ -30,146 +30,160 @@ freely, subject to the following restrictions: namespace PolyVox { template - int32_t Volume::Sampler::getPosX(void) const + template + int32_t Volume::Sampler::getPosX(void) const { assert(false); return 0; } template - int32_t Volume::Sampler::getPosY(void) const + template + int32_t Volume::Sampler::getPosY(void) const { assert(false); return 0; } template - int32_t Volume::Sampler::getPosZ(void) const + template + int32_t Volume::Sampler::getPosZ(void) const { assert(false); return 0; } template - const Volume* Volume::Sampler::getVolume(void) const - { - assert(false); - return 0; - } - - template - VoxelType Volume::Sampler::getVoxel(void) const + template + VoxelType Volume::Sampler::getVoxel(void) const { assert(false); return VoxelType(); } template - void Volume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) + template + void Volume::Sampler::setPosition(const Vector3DInt32& v3dNewPos) { assert(false); } template - void Volume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) + template + void Volume::Sampler::setPosition(int32_t xPos, int32_t yPos, int32_t zPos) { assert(false); } template - void Volume::Sampler::movePositiveX(void) + template + void Volume::Sampler::movePositiveX(void) { assert(false); } template - void Volume::Sampler::movePositiveY(void) + template + void Volume::Sampler::movePositiveY(void) { assert(false); } template - void Volume::Sampler::movePositiveZ(void) + template + void Volume::Sampler::movePositiveZ(void) { assert(false); } template - void Volume::Sampler::moveNegativeX(void) + template + void Volume::Sampler::moveNegativeX(void) { assert(false); } template - void Volume::Sampler::moveNegativeY(void) + template + void Volume::Sampler::moveNegativeY(void) { assert(false); } template - void Volume::Sampler::moveNegativeZ(void) + template + void Volume::Sampler::moveNegativeZ(void) { assert(false); } template - VoxelType Volume::Sampler::peekVoxel1nx1ny1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx1ny1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx1ny0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx1ny0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx1ny1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx1ny1pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx0py1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx0py1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx0py0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx0py0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx0py1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx0py1pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx1py1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx1py1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx1py0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx1py0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1nx1py1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1nx1py1pz(void) const { assert(false); return VoxelType(); @@ -178,63 +192,72 @@ namespace PolyVox ////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::Sampler::peekVoxel0px1ny1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px1ny1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px1ny0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px1ny0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px1ny1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px1ny1pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px0py1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px0py1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px0py0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px0py0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px0py1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px0py1pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px1py1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px1py1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px1py0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px1py0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel0px1py1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel0px1py1pz(void) const { assert(false); return VoxelType(); @@ -243,63 +266,72 @@ namespace PolyVox ////////////////////////////////////////////////////////////////////////// template - VoxelType Volume::Sampler::peekVoxel1px1ny1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px1ny1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px1ny0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px1ny0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px1ny1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px1ny1pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px0py1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px0py1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px0py0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px0py0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px0py1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px0py1pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px1py1nz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px1py1nz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px1py0pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px1py0pz(void) const { assert(false); return VoxelType(); } template - VoxelType Volume::Sampler::peekVoxel1px1py1pz(void) const + template + VoxelType Volume::Sampler::peekVoxel1px1py1pz(void) const { assert(false); return VoxelType(); 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;