From c73b45b7215cd308d8e44eb9dcdb0a3322b542b2 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 13 Aug 2011 08:57:45 +0100 Subject: [PATCH] Fixed bug with RawVolume always starting coordinates at (0,0,0). Removed Filters.h/.inl Added Summed Area Table support to LowPassFilter. Added test for low pass filter. --- examples/OpenGL/main.cpp | 10 +- examples/Paging/main.cpp | 1 - examples/SmoothLOD/main.cpp | 9 +- library/PolyVoxCore/CMakeLists.txt | 2 - .../include/PolyVoxCore/Filters.inl | 73 ---------- .../include/PolyVoxCore/LowPassFilter.h | 6 +- .../include/PolyVoxCore/LowPassFilter.inl | 137 +++++++++++++++++- .../include/PolyVoxCore/RawVolume.inl | 41 ++++-- .../include/PolyVoxCore/RawVolumeSampler.inl | 23 ++- .../PolyVoxCore/include/PolyVoxCore/Volume.h | 2 +- .../include/PolyVoxCore/Volume.inl | 3 +- tests/CMakeLists.txt | 4 + tests/TestLowPassFilter.cpp | 66 +++++++++ .../Filters.h => tests/TestLowPassFilter.h | 75 +++++----- 14 files changed, 308 insertions(+), 144 deletions(-) delete mode 100644 library/PolyVoxCore/include/PolyVoxCore/Filters.inl create mode 100644 tests/TestLowPassFilter.cpp rename library/PolyVoxCore/include/PolyVoxCore/Filters.h => tests/TestLowPassFilter.h (68%) diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 63861e4e..22ad8e6f 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -21,10 +21,11 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Filters.h" #include "PolyVoxCore/Log.h" #include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxCore/LowPassFilter.h" +#include "PolyVoxCore/RawVolume.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxImpl/Utility.h" @@ -101,8 +102,11 @@ int main(int argc, char *argv[]) createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity()); //Smooth part of the volume - smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127))); - smoothRegion(volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(127, 127, 127))); + RawVolume tempVolume(Region(0,0,0,128, 128, 128)); + LowPassFilter pass1(&volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3); + pass1.executeSAT(); + LowPassFilter pass2(&tempVolume, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), &volData, PolyVox::Region(Vector3DInt32(62, 62, 62), Vector3DInt32(126, 126, 126)), 3); + pass2.executeSAT(); QApplication app(argc, argv); diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 754c0230..5a171110 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -29,7 +29,6 @@ freely, subject to the following restrictions: #include "PolyVoxCore/SurfaceExtractor.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/LargeVolume.h" -#include "PolyVoxCore/Filters.h" #include diff --git a/examples/SmoothLOD/main.cpp b/examples/SmoothLOD/main.cpp index 145ab2c6..f15458da 100644 --- a/examples/SmoothLOD/main.cpp +++ b/examples/SmoothLOD/main.cpp @@ -24,7 +24,6 @@ freely, subject to the following restrictions: #include "OpenGLWidget.h" #include "PolyVoxCore/Density.h" -#include "PolyVoxCore/Filters.h" #include "PolyVoxCore/SurfaceExtractor.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/RawVolume.h" @@ -86,10 +85,10 @@ int main(int argc, char *argv[]) SimpleVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 28); - //Smooth the data - smoothRegion(volData, volData.getEnclosingRegion()); - smoothRegion(volData, volData.getEnclosingRegion()); - smoothRegion(volData, volData.getEnclosingRegion()); + //Smooth the data - should reimplement this using LowPassFilter + //smoothRegion(volData, volData.getEnclosingRegion()); + //smoothRegion(volData, volData.getEnclosingRegion()); + //smoothRegion(volData, volData.getEnclosingRegion()); RawVolume volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 31, 31))); diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index feb3bacb..eb848533 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -29,8 +29,6 @@ SET(CORE_INC_FILES include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl include/PolyVoxCore/Density.h - include/PolyVoxCore/Filters.h - include/PolyVoxCore/Filters.inl include/PolyVoxCore/GradientEstimators.h include/PolyVoxCore/GradientEstimators.inl include/PolyVoxCore/LargeVolume.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Filters.inl b/library/PolyVoxCore/include/PolyVoxCore/Filters.inl deleted file mode 100644 index ca0e1472..00000000 --- a/library/PolyVoxCore/include/PolyVoxCore/Filters.inl +++ /dev/null @@ -1,73 +0,0 @@ -#include "PolyVoxCore/MaterialDensityPair.h" - -namespace PolyVox -{ - template< template class VolumeType, typename VoxelType> - void smoothRegion(VolumeType& volData, const Region& regionToSmooth) - { - Region croppedRegion = regionToSmooth; - - uint32_t uArrayWidth = croppedRegion.getUpperCorner().getX() - croppedRegion.getLowerCorner().getX() + 1; - uint32_t uArrayHeight = croppedRegion.getUpperCorner().getY() - croppedRegion.getLowerCorner().getY() + 1; - uint32_t uArrayDepth = croppedRegion.getUpperCorner().getZ() - croppedRegion.getLowerCorner().getZ() + 1; - Array<3, uint16_t> temp(ArraySizes(uArrayWidth)(uArrayHeight)(uArrayDepth)); - - for (int32_t z = croppedRegion.getLowerCorner().getZ(); z <= croppedRegion.getUpperCorner().getZ(); z++) - { - for (int32_t y = croppedRegion.getLowerCorner().getY(); y <= croppedRegion.getUpperCorner().getY(); y++) - { - for (int32_t x = croppedRegion.getLowerCorner().getX(); x <= croppedRegion.getUpperCorner().getX(); x++) - { - uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()]; - - uDensity=0; - uDensity += volData.getVoxelAt(x-1,y-1,z-1).getDensity(); - uDensity += volData.getVoxelAt(x-1,y-1,z-0).getDensity(); - uDensity += volData.getVoxelAt(x-1,y-1,z+1).getDensity(); - uDensity += volData.getVoxelAt(x-1,y-0,z-1).getDensity(); - uDensity += volData.getVoxelAt(x-1,y-0,z-0).getDensity(); - uDensity += volData.getVoxelAt(x-1,y-0,z+1).getDensity(); - uDensity += volData.getVoxelAt(x-1,y+1,z-1).getDensity(); - uDensity += volData.getVoxelAt(x-1,y+1,z-0).getDensity(); - uDensity += volData.getVoxelAt(x-1,y+1,z+1).getDensity(); - - uDensity += volData.getVoxelAt(x-0,y-1,z-1).getDensity(); - uDensity += volData.getVoxelAt(x-0,y-1,z-0).getDensity(); - uDensity += volData.getVoxelAt(x-0,y-1,z+1).getDensity(); - uDensity += volData.getVoxelAt(x-0,y-0,z-1).getDensity(); - uDensity += volData.getVoxelAt(x-0,y-0,z-0).getDensity(); - uDensity += volData.getVoxelAt(x-0,y-0,z+1).getDensity(); - uDensity += volData.getVoxelAt(x-0,y+1,z-1).getDensity(); - uDensity += volData.getVoxelAt(x-0,y+1,z-0).getDensity(); - uDensity += volData.getVoxelAt(x-0,y+1,z+1).getDensity(); - - uDensity += volData.getVoxelAt(x+1,y-1,z-1).getDensity(); - uDensity += volData.getVoxelAt(x+1,y-1,z-0).getDensity(); - uDensity += volData.getVoxelAt(x+1,y-1,z+1).getDensity(); - uDensity += volData.getVoxelAt(x+1,y-0,z-1).getDensity(); - uDensity += volData.getVoxelAt(x+1,y-0,z-0).getDensity(); - uDensity += volData.getVoxelAt(x+1,y-0,z+1).getDensity(); - uDensity += volData.getVoxelAt(x+1,y+1,z-1).getDensity(); - uDensity += volData.getVoxelAt(x+1,y+1,z-0).getDensity(); - uDensity += volData.getVoxelAt(x+1,y+1,z+1).getDensity(); - uDensity /= 27; - } - } - } - - for (int32_t z = croppedRegion.getLowerCorner().getZ(); z < croppedRegion.getUpperCorner().getZ(); z++) - { - for (int32_t y = croppedRegion.getLowerCorner().getY(); y < croppedRegion.getUpperCorner().getY(); y++) - { - for (int32_t x = croppedRegion.getLowerCorner().getX(); x < croppedRegion.getUpperCorner().getX(); x++) - { - uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()]; - - VoxelType val = volData.getVoxelAt(x,y,z); - val.setDensity(uDensity); - volData.setVoxelAt(x,y,z,val); - } - } - } - } -} \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h index dde239b8..3e93f3ec 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h @@ -33,9 +33,10 @@ namespace PolyVox class LowPassFilter { public: - LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DestVolumeType* pVolDst, Region regDst); + LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DestVolumeType* pVolDst, Region regDst, uint32_t uKernelSize); void execute(); + void executeSAT(); private: //Source data @@ -45,6 +46,9 @@ namespace PolyVox //Destination data DestVolumeType* m_pVolDst; Region m_regDst; + + //Kernel size + uint32_t m_uKernelSize; }; }//namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 033c8af2..1c8c1a5a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -21,15 +21,28 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/RawVolume.h" + namespace PolyVox { template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> - LowPassFilter::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DestVolumeType* pVolDst, Region regDst) + LowPassFilter::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DestVolumeType* pVolDst, Region regDst, uint32_t uKernelSize) :m_pVolSrc(pVolSrc) ,m_regSrc(regSrc) ,m_pVolDst(pVolDst) ,m_regDst(regDst) + ,m_uKernelSize(uKernelSize) { + //Kernel size must be at least three + assert(m_uKernelSize >= 3); + m_uKernelSize = std::max(m_uKernelSize, static_cast(3)); //For release builds + + //Kernel size must be odd + assert(m_uKernelSize % 2 == 1); + if(m_uKernelSize % 2 == 0) //For release builds + { + m_uKernelSize++; + } } template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> @@ -103,4 +116,126 @@ namespace PolyVox } } } + + template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> + void LowPassFilter::executeSAT() + { + const int border = m_uKernelSize - 1; + + Vector3DInt32 satLowerCorner = m_regSrc.getLowerCorner() - Vector3DInt32(border+1, border+1, border+1); + Vector3DInt32 satUpperCorner = m_regSrc.getUpperCorner() + Vector3DInt32(border, border, border); + + RawVolume satVolume(Region(satLowerCorner, satUpperCorner)); + + //Clear to zeros (necessary?) + for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + { + for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) + { + for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) + { + satVolume.setVoxelAt(x,y,z,0); + } + } + } + + //Build SAT in three passes + for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + { + for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) + { + for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) + { + uint32_t previousSum = satVolume.getVoxelAt(x-1,y,z); + uint32_t currentVal = m_pVolSrc->getVoxelAt(x,y,z).getDensity(); + + satVolume.setVoxelAt(x,y,z,previousSum + currentVal); + } + } + } + + for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + { + for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) + { + for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) + { + uint32_t previousSum = satVolume.getVoxelAt(x,y-1,z); + uint32_t currentSum = satVolume.getVoxelAt(x,y,z); + + satVolume.setVoxelAt(x,y,z,previousSum + currentSum); + } + } + } + + for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + { + for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) + { + for(int32_t x = satLowerCorner.getX(); x <= satUpperCorner.getX(); x++) + { + uint32_t previousSum = satVolume.getVoxelAt(x,y,z-1); + uint32_t currentSum = satVolume.getVoxelAt(x,y,z); + + satVolume.setVoxelAt(x,y,z,previousSum + currentSum); + } + } + } + + //Now compute the average + const Vector3DInt32& v3dDestLowerCorner = m_regDst.getLowerCorner(); + const Vector3DInt32& v3dDestUpperCorner = m_regDst.getUpperCorner(); + + const Vector3DInt32& v3dSrcLowerCorner = m_regSrc.getLowerCorner(); + const Vector3DInt32& v3dSrcUpperCorner = m_regSrc.getUpperCorner(); + + for(int32_t iDstZ = v3dDestLowerCorner.getZ(), iSrcZ = v3dSrcLowerCorner.getZ(); iDstZ <= v3dDestUpperCorner.getZ(); iDstZ++, iSrcZ++) + { + for(int32_t iDstY = v3dDestLowerCorner.getY(), iSrcY = v3dSrcLowerCorner.getY(); iDstY <= v3dDestUpperCorner.getY(); iDstY++, iSrcY++) + { + for(int32_t iDstX = v3dDestLowerCorner.getX(), iSrcX = v3dSrcLowerCorner.getX(); iDstX <= v3dDestUpperCorner.getX(); iDstX++, iSrcX++) + { + int32_t satLowerX = iSrcX - border - 1; + int32_t satLowerY = iSrcY - border - 1; + int32_t satLowerZ = iSrcZ - border - 1; + + int32_t satUpperX = iSrcX + border; + int32_t satUpperY = iSrcY + border; + int32_t satUpperZ = iSrcZ + border; + + int32_t a = satVolume.getVoxelAt(satLowerX,satLowerY,satLowerZ); + int32_t b = satVolume.getVoxelAt(satUpperX,satLowerY,satLowerZ); + int32_t c = satVolume.getVoxelAt(satLowerX,satUpperY,satLowerZ); + int32_t d = satVolume.getVoxelAt(satUpperX,satUpperY,satLowerZ); + int32_t e = satVolume.getVoxelAt(satLowerX,satLowerY,satUpperZ); + int32_t f = satVolume.getVoxelAt(satUpperX,satLowerY,satUpperZ); + int32_t g = satVolume.getVoxelAt(satLowerX,satUpperY,satUpperZ); + int32_t h = satVolume.getVoxelAt(satUpperX,satUpperY,satUpperZ); + + int32_t sum = h+c-d-g-f-a+b+e; + + int32_t sideLength = border * 2 + 1; + + int32_t average = sum / (sideLength*sideLength*sideLength); + + VoxelType voxel = m_pVolSrc->getVoxelAt(iDstX, iDstY, iDstZ); + + voxel.setDensity(average); + + m_pVolDst->setVoxelAt(iDstX, iDstY, iDstZ, voxel); + + + //float maxSolid = border * 2/* + 1*/; + /*maxSolid = maxSolid * maxSolid * maxSolid; + + float percentSolid = noSolid / maxSolid; + float percentEmpty = 1.0f - percentSolid; + + (*mAmbientOcclusionVolume)[ambVolZ][ambVolY][ambVolX] = 255 * percentEmpty;*/ + + //(*mAmbientOcclusionVolume)[ambVolZ][ambVolY][ambVolX] = 255 - ((h+c-d-g-f-a+b+e) * 19); //FIXME - should not be 9 + } + } + } + } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index cbbdbec9..27257dc6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -49,6 +49,8 @@ namespace PolyVox ) :Volume(regValid) { + setBorderValue(VoxelType()); + //Create a volume of the right size. resize(regValid); } @@ -85,11 +87,16 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { + const Vector3DInt32& v3dLowerCorner = m_regValidRegion.getLowerCorner(); + int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); + int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); + int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); + return m_pData [ - uXPos + - uYPos * this->getWidth() + - uZPos * this->getWidth() * this->getHeight() + iLocalXPos + + iLocalYPos * this->getWidth() + + iLocalZPos * this->getWidth() * this->getHeight() ]; } else @@ -127,17 +134,27 @@ namespace PolyVox template bool RawVolume::setVoxelAt(int32_t uXPos, int32_t uYPos, int32_t uZPos, VoxelType tValue) { - assert(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))); + if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) + { + const Vector3DInt32& v3dLowerCorner = m_regValidRegion.getLowerCorner(); + int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); + int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); + int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); - m_pData - [ - uXPos + - uYPos * this->getWidth() + - uZPos * this->getWidth() * this->getHeight() - ] = tValue; + m_pData + [ + iLocalXPos + + iLocalYPos * this->getWidth() + + iLocalZPos * this->getWidth() * this->getHeight() + ] = tValue; - //Return true to indicate that we modified a voxel. - return true; + //Return true to indicate that we modified a voxel. + return true; + } + else + { + return false; + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index cff073fb..6d22784b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -79,13 +79,26 @@ namespace PolyVox this->mYPosInVolume = yPos; this->mZPosInVolume = zPos; - const uint32_t uVoxelIndex = xPos + - yPos * this->mVolume->getWidth() + - zPos * this->mVolume->getWidth() * this->mVolume->getHeight(); + if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos))) + { + const Vector3DInt32& v3dLowerCorner = this->mVolume->m_regValidRegion.getLowerCorner(); + int32_t iLocalXPos = xPos - v3dLowerCorner.getX(); + int32_t iLocalYPos = yPos - v3dLowerCorner.getY(); + int32_t iLocalZPos = zPos - v3dLowerCorner.getZ(); - mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; + const uint32_t uVoxelIndex = iLocalXPos + + iLocalYPos * this->mVolume->getWidth() + + iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight(); - m_bIsCurrentPositionValid = this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos)); + mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; + + m_bIsCurrentPositionValid = true; + } + else + { + mCurrentVoxel = 0; + m_bIsCurrentPositionValid = false; + } } template diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h index 51b7634a..2d5d7ba2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -140,7 +140,7 @@ namespace PolyVox /// Calculates approximatly how many bytes of memory the volume is currently using. uint32_t calculateSizeInBytes(void); -protected: + protected: //The size of the volume Region m_regValidRegion; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl index 0a7f4cad..fc17962c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl @@ -197,7 +197,6 @@ namespace PolyVox uint32_t Volume::calculateSizeInBytes(void) { return getWidth() * getHeight() * getDepth() * sizeof(VoxelType); - } - + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 39a68d7b..299ed23c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,6 +47,10 @@ ADD_TEST(ArrayReadWriteTest ${LATEST_TEST} testReadWrite) CREATE_TEST(TestAStarPathfinder.h TestAStarPathfinder.cpp TestAStarPathfinder) ADD_TEST(AStarPathfinderExecuteTest ${LATEST_TEST} testExecute) +# Low pass filter tests +CREATE_TEST(TestLowPassFilter.h TestLowPassFilter.cpp TestLowPassFilter) +ADD_TEST(LowPassFilterExecuteTest ${LATEST_TEST} testExecute) + # LargeVolume tests CREATE_TEST(testvolume.h testvolume.cpp testvolume) ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize) diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp new file mode 100644 index 00000000..604b12fd --- /dev/null +++ b/tests/TestLowPassFilter.cpp @@ -0,0 +1,66 @@ +/******************************************************************************* +Copyright (c) 2010 Matt Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "TestLowPassFilter.h" + +#include "PolyVoxCore/Density.h" +#include "PolyVoxCore/LowPassFilter.h" +#include "PolyVoxCore/RawVolume.h" + +#include + +using namespace PolyVox; + +void TestLowPassFilter::testExecute() +{ + const int32_t g_uVolumeSideLength = 16; + + Region reg(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)); + + //Create empty volume + RawVolume volData(reg); + + //Create two solid walls at opposite sides of the volume + for (int32_t z = 0; z < g_uVolumeSideLength; z++) + { + for (int32_t y = 0; y < g_uVolumeSideLength; y++) + { + for (int32_t x = 0; x < g_uVolumeSideLength; x++) + { + if(x % 2 == 0) + { + Density8 voxel(32); + volData.setVoxelAt(x, y, z, voxel); + } + } + } + } + + RawVolume resultVolume(reg); + + LowPassFilter pass1(&volData, reg, &resultVolume, reg, 5); + + pass1.executeSAT(); +} + +QTEST_MAIN(TestLowPassFilter) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Filters.h b/tests/TestLowPassFilter.h similarity index 68% rename from library/PolyVoxCore/include/PolyVoxCore/Filters.h rename to tests/TestLowPassFilter.h index 5fd543d6..84cd7404 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Filters.h +++ b/tests/TestLowPassFilter.h @@ -1,38 +1,37 @@ -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#ifndef __PolyVox_Filters_H__ -#define __PolyVox_Filters_H__ - -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/Region.h" - -namespace PolyVox -{ - template< template class VolumeType, typename VoxelType> - void smoothRegion(VolumeType& volData, const Region& regionToSmooth); -}//namespace PolyVox - -#include "PolyVoxCore/Filters.inl" - -#endif \ No newline at end of file +/******************************************************************************* +Copyright (c) 2010 Matt Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_TestLowPassFilter_H__ +#define __PolyVox_TestLowPassFilter_H__ + +#include + +class TestLowPassFilter: public QObject +{ + Q_OBJECT + + private slots: + void testExecute(); +}; + +#endif