From 03e340e7dd33ba31f40210a250452f8d5ab8ca32 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 3 Aug 2011 20:43:02 +0100 Subject: [PATCH] Initial version of LowPassFilter class, which will eventually replace the smoothRegion() function. --- library/PolyVoxCore/CMakeLists.txt | 2 + .../include/PolyVoxCore/LowPassFilter.h | 55 +++++++++ .../include/PolyVoxCore/LowPassFilter.inl | 106 ++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h create mode 100644 library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index a1bcf575..feb3bacb 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -37,6 +37,8 @@ SET(CORE_INC_FILES include/PolyVoxCore/LargeVolume.inl include/PolyVoxCore/LargeVolumeSampler.inl include/PolyVoxCore/Log.h + include/PolyVoxCore/LowPassFilter.h + include/PolyVoxCore/LowPassFilter.inl include/PolyVoxCore/Material.h include/PolyVoxCore/MaterialDensityPair.h include/PolyVoxCore/MeshDecimator.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h new file mode 100644 index 00000000..dde239b8 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h @@ -0,0 +1,55 @@ +/******************************************************************************* +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_LowPassFilter_H__ +#define __PolyVox_LowPassFilter_H__ + +#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Region.h" + +namespace PolyVox +{ + template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> + class LowPassFilter + { + public: + LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DestVolumeType* pVolDst, Region regDst); + + void execute(); + + private: + //Source data + SrcVolumeType* m_pVolSrc; + Region m_regSrc; + + //Destination data + DestVolumeType* m_pVolDst; + Region m_regDst; + }; + +}//namespace PolyVox + +#include "PolyVoxCore/LowPassFilter.inl" + +#endif //__PolyVox_LowPassFilter_H__ + diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl new file mode 100644 index 00000000..033c8af2 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -0,0 +1,106 @@ +/******************************************************************************* +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. +*******************************************************************************/ + +namespace PolyVox +{ + template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> + LowPassFilter::LowPassFilter(SrcVolumeType* pVolSrc, Region regSrc, DestVolumeType* pVolDst, Region regDst) + :m_pVolSrc(pVolSrc) + ,m_regSrc(regSrc) + ,m_pVolDst(pVolDst) + ,m_regDst(regDst) + { + } + + template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> + void LowPassFilter::execute() + { + int32_t iSrcMinX = m_regSrc.getLowerCorner().getX(); + int32_t iSrcMinY = m_regSrc.getLowerCorner().getY(); + int32_t iSrcMinZ = m_regSrc.getLowerCorner().getZ(); + + int32_t iSrcMaxX = m_regSrc.getUpperCorner().getX(); + int32_t iSrcMaxY = m_regSrc.getUpperCorner().getY(); + int32_t iSrcMaxZ = m_regSrc.getUpperCorner().getZ(); + + int32_t iDstMinX = m_regDst.getLowerCorner().getX(); + int32_t iDstMinY = m_regDst.getLowerCorner().getY(); + int32_t iDstMinZ = m_regDst.getLowerCorner().getZ(); + + //int32_t iDstMaxX = m_regDst.getUpperCorner().getX(); + //int32_t iDstMaxY = m_regDst.getUpperCorner().getY(); + //int32_t iDstMaxZ = m_regDst.getUpperCorner().getZ(); + + SrcVolumeType::Sampler srcSampler(m_pVolSrc); + + for(int32_t iSrcZ = iSrcMinZ, iDstZ = iDstMinZ; iSrcZ <= iSrcMaxZ; iSrcZ++, iDstZ++) + { + for(int32_t iSrcY = iSrcMinY, iDstY = iDstMinY; iSrcY <= iSrcMaxY; iSrcY++, iDstY++) + { + for(int32_t iSrcX = iSrcMinX, iDstX = iDstMinX; iSrcX <= iSrcMaxX; iSrcX++, iDstX++) + { + //VoxelType tSrcVoxel = m_pVolSrc->getVoxelAt(iSrcX, iSrcY, iSrcZ); + srcSampler.setPosition(iSrcX, iSrcY, iSrcZ); + + VoxelType tSrcVoxel = srcSampler.getVoxel(); + + uint32_t uDensity = 0; + uDensity += srcSampler.peekVoxel1nx1ny1nz().getDensity(); + uDensity += srcSampler.peekVoxel1nx1ny0pz().getDensity(); + uDensity += srcSampler.peekVoxel1nx1ny1pz().getDensity(); + uDensity += srcSampler.peekVoxel1nx0py1nz().getDensity(); + uDensity += srcSampler.peekVoxel1nx0py0pz().getDensity(); + uDensity += srcSampler.peekVoxel1nx0py1pz().getDensity(); + uDensity += srcSampler.peekVoxel1nx1py1nz().getDensity(); + uDensity += srcSampler.peekVoxel1nx1py0pz().getDensity(); + uDensity += srcSampler.peekVoxel1nx1py1pz().getDensity(); + + uDensity += srcSampler.peekVoxel0px1ny1nz().getDensity(); + uDensity += srcSampler.peekVoxel0px1ny0pz().getDensity(); + uDensity += srcSampler.peekVoxel0px1ny1pz().getDensity(); + uDensity += srcSampler.peekVoxel0px0py1nz().getDensity(); + uDensity += srcSampler.peekVoxel0px0py0pz().getDensity(); + uDensity += srcSampler.peekVoxel0px0py1pz().getDensity(); + uDensity += srcSampler.peekVoxel0px1py1nz().getDensity(); + uDensity += srcSampler.peekVoxel0px1py0pz().getDensity(); + uDensity += srcSampler.peekVoxel0px1py1pz().getDensity(); + + uDensity += srcSampler.peekVoxel1px1ny1nz().getDensity(); + uDensity += srcSampler.peekVoxel1px1ny0pz().getDensity(); + uDensity += srcSampler.peekVoxel1px1ny1pz().getDensity(); + uDensity += srcSampler.peekVoxel1px0py1nz().getDensity(); + uDensity += srcSampler.peekVoxel1px0py0pz().getDensity(); + uDensity += srcSampler.peekVoxel1px0py1pz().getDensity(); + uDensity += srcSampler.peekVoxel1px1py1nz().getDensity(); + uDensity += srcSampler.peekVoxel1px1py0pz().getDensity(); + uDensity += srcSampler.peekVoxel1px1py1pz().getDensity(); + + uDensity /= 27; + + tSrcVoxel.setDensity(uDensity); + m_pVolDst->setVoxelAt(iSrcX, iSrcY, iSrcZ, tSrcVoxel); + } + } + } + } +}