From 03e340e7dd33ba31f40210a250452f8d5ab8ca32 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 3 Aug 2011 20:43:02 +0100 Subject: [PATCH 01/11] 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); + } + } + } + } +} From c73b45b7215cd308d8e44eb9dcdb0a3322b542b2 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 13 Aug 2011 08:57:45 +0100 Subject: [PATCH 02/11] 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 From 90063354bdf10b8bfd9fa0012ba3d1ffc3ef7e85 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 15 Aug 2011 21:10:09 +0100 Subject: [PATCH 03/11] Added setVoxel() funtion to volume iterators. Fixed bugs with RawVolume iterator movement funtions. Proper implementation of RawVolume peek...() functions. --- .../include/PolyVoxCore/LargeVolume.h | 1 + .../PolyVoxCore/LargeVolumeSampler.inl | 15 +- .../include/PolyVoxCore/RawVolume.h | 6 +- .../include/PolyVoxCore/RawVolumeSampler.inl | 176 +++++++++++++++--- .../PolyVoxCore/include/PolyVoxCore/Region.h | 7 + .../include/PolyVoxCore/SimpleVolume.h | 2 + .../include/PolyVoxCore/SimpleVolume.inl | 9 +- .../PolyVoxCore/SimpleVolumeSampler.inl | 23 ++- .../PolyVoxCore/include/PolyVoxCore/Volume.h | 3 +- .../include/PolyVoxCore/VolumeSampler.inl | 7 + library/PolyVoxCore/source/Region.cpp | 36 ++++ 11 files changed, 254 insertions(+), 31 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 2fb4fd0e..323c7054 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -162,6 +162,7 @@ namespace PolyVox void setPosition(const Vector3DInt32& v3dNewPos); void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); + inline bool setVoxel(VoxelType tValue); void movePositiveX(void); void movePositiveY(void); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 994a9ff3..f89d4c1b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -26,12 +26,13 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Region.h" +#include + #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) -#include namespace PolyVox { template @@ -159,6 +160,15 @@ namespace PolyVox } } + template + bool LargeVolume::Sampler::setVoxel(VoxelType tValue) + { + //*mCurrentVoxel = tValue; + //Need to think what effect this has on any existing iterators. + assert(false); + return false; + } + template void LargeVolume::Sampler::movePositiveX(void) { @@ -525,3 +535,6 @@ namespace PolyVox return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } } + +#undef BORDER_LOW +#undef BORDER_HIGH \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index d7d2b1bf..83a287d1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -52,6 +52,7 @@ namespace PolyVox void setPosition(const Vector3DInt32& v3dNewPos); void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); + inline bool setVoxel(VoxelType tValue); void movePositiveX(void); void movePositiveY(void); @@ -96,7 +97,10 @@ namespace PolyVox VoxelType* mCurrentVoxel; //Whether the current position is inside the volume - bool m_bIsCurrentPositionValid; + //FIXME - Replace these with flags + bool m_bIsCurrentPositionValidInX; + bool m_bIsCurrentPositionValidInY; + bool m_bIsCurrentPositionValidInZ; }; #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 6d22784b..bf4f97b1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -27,13 +27,23 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Region.h" #include + +#define BORDER_LOWX(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) +#define BORDER_HIGHX(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) +#define BORDER_LOWY(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) +#define BORDER_HIGHY(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) +#define BORDER_LOWZ(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) +#define BORDER_HIGHZ(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) + namespace PolyVox { template RawVolume::Sampler::Sampler(RawVolume* volume) :Volume::template Sampler< RawVolume >(volume) ,mCurrentVoxel(0) - ,m_bIsCurrentPositionValid(false) + ,m_bIsCurrentPositionValidInX(false) + ,m_bIsCurrentPositionValidInY(false) + ,m_bIsCurrentPositionValidInZ(false) { } @@ -63,7 +73,7 @@ namespace PolyVox template VoxelType RawVolume::Sampler::getVoxel(void) const { - return m_bIsCurrentPositionValid ? *mCurrentVoxel : this->mVolume->getBorderValue(); + return (m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ) ? *mCurrentVoxel : this->mVolume->getBorderValue(); } template @@ -79,25 +89,34 @@ namespace PolyVox this->mYPosInVolume = yPos; this->mZPosInVolume = zPos; - 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(); + + const int32_t uVoxelIndex = iLocalXPos + + iLocalYPos * this->mVolume->getWidth() + + iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight(); + + mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; + + m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos); + m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos); + m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos); + } + + template + bool RawVolume::Sampler::setVoxel(VoxelType tValue) + { + //return m_bIsCurrentPositionValid ? *mCurrentVoxel : this->mVolume->getBorderValue(); + if(m_bIsCurrentPositionValidInX && m_bIsCurrentPositionValidInY && m_bIsCurrentPositionValidInZ) { - 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(); - - const uint32_t uVoxelIndex = iLocalXPos + - iLocalYPos * this->mVolume->getWidth() + - iLocalZPos * this->mVolume->getWidth() * this->mVolume->getHeight(); - - mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; - - m_bIsCurrentPositionValid = true; + *mCurrentVoxel = tValue; + return true; } else { - mCurrentVoxel = 0; - m_bIsCurrentPositionValid = false; + return false; } } @@ -106,7 +125,7 @@ namespace PolyVox { this->mXPosInVolume++; ++mCurrentVoxel; - m_bIsCurrentPositionValid = this->mXPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getX(); + m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume); } template @@ -114,7 +133,7 @@ namespace PolyVox { this->mYPosInVolume++; mCurrentVoxel += this->mVolume->getWidth(); - m_bIsCurrentPositionValid = this->mYPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getY(); + m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume); } template @@ -122,7 +141,7 @@ namespace PolyVox { this->mZPosInVolume++; mCurrentVoxel += this->mVolume->getWidth() * this->mVolume->getHeight(); - m_bIsCurrentPositionValid = this->mZPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getZ(); + m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume); } template @@ -130,7 +149,7 @@ namespace PolyVox { this->mXPosInVolume--; --mCurrentVoxel; - m_bIsCurrentPositionValid = this->mXPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getX(); + m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume); } template @@ -138,7 +157,7 @@ namespace PolyVox { this->mYPosInVolume--; mCurrentVoxel -= this->mVolume->getWidth(); - m_bIsCurrentPositionValid = this->mYPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getY(); + m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(this->mYPosInVolume); } template @@ -146,60 +165,96 @@ namespace PolyVox { this->mZPosInVolume--; mCurrentVoxel -= this->mVolume->getWidth() * this->mVolume->getHeight(); - m_bIsCurrentPositionValid =this->mZPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getZ(); + m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx1ny1nz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - 1 - this->mVolume->getWidth() - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1nx1ny0pz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) ) + { + return *(mCurrentVoxel - 1 - this->mVolume->getWidth()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx1ny1pz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - 1 - this->mVolume->getWidth() + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1nx0py1nz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - 1 - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1nx0py0pz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) ) + { + return *(mCurrentVoxel - 1); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx0py1pz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - 1 + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1nx1py1nz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mYPosInVolume) ) + { + return *(mCurrentVoxel - 1 + this->mVolume->getWidth() - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1nx1py0pz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) ) + { + return *(mCurrentVoxel - 1 + this->mVolume->getWidth()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1nx1py1pz(void) const { + if( BORDER_LOWX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - 1 + this->mVolume->getWidth() + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume-1,this->mYPosInVolume+1,this->mZPosInVolume+1); } @@ -208,24 +263,40 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel0px1ny1nz(void) const { + if( BORDER_LOWX(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - this->mVolume->getWidth() - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel0px1ny0pz(void) const { + if( BORDER_LOWY(this->mYPosInVolume) ) + { + return *(mCurrentVoxel - this->mVolume->getWidth()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel0px1ny1pz(void) const { + if( BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - this->mVolume->getWidth() + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel0px0py1nz(void) const { + if( BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume-1); } @@ -238,24 +309,40 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel0px0py1pz(void) const { + if( BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel0px1py1nz(void) const { + if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + this->mVolume->getWidth() - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel0px1py0pz(void) const { + if( BORDER_HIGHY(this->mYPosInVolume) ) + { + return *(mCurrentVoxel + this->mVolume->getWidth()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel0px1py1pz(void) const { + if( BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + this->mVolume->getWidth() + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume,this->mYPosInVolume+1,this->mZPosInVolume+1); } @@ -264,54 +351,97 @@ namespace PolyVox template VoxelType RawVolume::Sampler::peekVoxel1px1ny1nz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + 1 - this->mVolume->getWidth() - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1px1ny0pz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) ) + { + return *(mCurrentVoxel + 1 - this->mVolume->getWidth()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1px1ny1pz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + 1 - this->mVolume->getWidth() + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume-1,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1px0py1nz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + 1 - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1px0py0pz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) ) + { + return *(mCurrentVoxel + 1); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1px0py1pz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + 1 + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume,this->mZPosInVolume+1); } template VoxelType RawVolume::Sampler::peekVoxel1px1py1nz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_LOWZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + 1 + this->mVolume->getWidth() - this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume-1); } template VoxelType RawVolume::Sampler::peekVoxel1px1py0pz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) ) + { + return *(mCurrentVoxel + 1 + this->mVolume->getWidth()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume); } template VoxelType RawVolume::Sampler::peekVoxel1px1py1pz(void) const { + if( BORDER_HIGHX(this->mXPosInVolume) && BORDER_HIGHY(this->mYPosInVolume) && BORDER_HIGHZ(this->mZPosInVolume) ) + { + return *(mCurrentVoxel + 1 + this->mVolume->getWidth() + this->mVolume->getHeight() * this->mVolume->getHeight()); + } return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } } + +#undef BORDER_LOWX +#undef BORDER_HIGHX +#undef BORDER_LOWY +#undef BORDER_HIGHY +#undef BORDER_LOWZ +#undef BORDER_HIGHZ \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index 5888df0d..e9297492 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -51,6 +51,13 @@ namespace PolyVox bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const; bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const; + //FIXME - Don't like these. Make containsPoint take flags indicating which axes to check? + bool containsPointInX(float pos, float boundary = 0.0f) const; + bool containsPointInX(int32_t pos, uint8_t boundary = 0) const; + bool containsPointInY(float pos, float boundary = 0.0f) const; + bool containsPointInY(int32_t pos, uint8_t boundary = 0) const; + bool containsPointInZ(float pos, float boundary = 0.0f) const; + bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const; void cropTo(const Region& other); /// Deprecated and misleading int32_t depth(void) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index b75cd367..c11674f5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -77,6 +77,7 @@ namespace PolyVox void setPosition(const Vector3DInt32& v3dNewPos); void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); + inline bool setVoxel(VoxelType tValue); void movePositiveX(void); void movePositiveY(void); @@ -179,6 +180,7 @@ private: uint16_t m_uDepthInBlocks; //The size of the blocks + uint32_t m_uNoOfVoxelsPerBlock; uint16_t m_uBlockSideLength; uint8_t m_uBlockSideLengthPower; }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index a401ec95..75133e32 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -143,7 +143,7 @@ namespace PolyVox { /*Block* pUncompressedBorderBlock = getUncompressedBlock(&m_pBorderBlock); return pUncompressedBorderBlock->fill(tBorder);*/ - std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength, tBorder); + std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, tBorder); } //////////////////////////////////////////////////////////////////////////////// @@ -205,6 +205,7 @@ namespace PolyVox } m_uBlockSideLength = uBlockSideLength; + m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; m_pUncompressedBorderData = 0; this->m_regValidRegion = regValidRegion; @@ -230,8 +231,8 @@ namespace PolyVox } //Create the border block - m_pUncompressedBorderData = new VoxelType[m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength]; - std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength, VoxelType()); + m_pUncompressedBorderData = new VoxelType[m_uNoOfVoxelsPerBlock]; + std::fill(m_pUncompressedBorderData, m_pUncompressedBorderData + m_uNoOfVoxelsPerBlock, VoxelType()); //Other properties we might find useful later this->m_uLongestSideLength = (std::max)((std::max)(this->getWidth(),this->getHeight()),this->getDepth()); @@ -266,7 +267,7 @@ namespace PolyVox { uint32_t uSizeInBytes = sizeof(SimpleVolume); - uint32_t uSizeOfBlockInBytes = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); + uint32_t uSizeOfBlockInBytes = m_uNoOfVoxelsPerBlock * sizeof(VoxelType); //Memory used by the blocks ( + 1 is for border) uSizeInBytes += uSizeOfBlockInBytes * (m_uNoOfBlocksInVolume + 1); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index ba8bdb1a..7148b510 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -26,12 +26,13 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Region.h" +#include + #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) -#include namespace PolyVox { template @@ -159,6 +160,23 @@ namespace PolyVox } } + template + bool SimpleVolume::Sampler::setVoxel(VoxelType tValue) + { + VoxelType* pBorderDataEndPlusOne = this->mVolume->m_pUncompressedBorderData + this->mVolume->m_uNoOfVoxelsPerBlock; + + //Make sure we're not trying to write to the border data + if((mCurrentVoxel < this->mVolume->m_pUncompressedBorderData) || (mCurrentVoxel >= pBorderDataEndPlusOne)) + { + *mCurrentVoxel = tValue; + return true; + } + else + { + return false; + } + } + template void SimpleVolume::Sampler::movePositiveX(void) { @@ -525,3 +543,6 @@ namespace PolyVox return this->mVolume->getVoxelAt(this->mXPosInVolume+1,this->mYPosInVolume+1,this->mZPosInVolume+1); } } + +#undef BORDER_LOW +#undef BORDER_HIGH diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h index 2d5d7ba2..298b90af 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -47,10 +47,11 @@ namespace PolyVox int32_t getPosX(void) const; int32_t getPosY(void) const; int32_t getPosZ(void) const; - inline VoxelType getVoxel(void) const; + inline VoxelType getVoxel(void) const; void setPosition(const Vector3DInt32& v3dNewPos); void setPosition(int32_t xPos, int32_t yPos, int32_t zPos); + inline bool setVoxel(VoxelType tValue); void movePositiveX(void); void movePositiveY(void); diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl index 68b2e314..0dbf6ac1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl @@ -91,6 +91,13 @@ namespace PolyVox mZPosInVolume = zPos; } + template + template + bool Volume::Sampler::setVoxel(VoxelType tValue) + { + return mVolume->setVoxelAt(mXPosInVolume, mYPosInVolume, mZPosInVolume, tValue); + } + template template void Volume::Sampler::movePositiveX(void) diff --git a/library/PolyVoxCore/source/Region.cpp b/library/PolyVoxCore/source/Region.cpp index 8b6491d5..fcb4f6fd 100644 --- a/library/PolyVoxCore/source/Region.cpp +++ b/library/PolyVoxCore/source/Region.cpp @@ -100,6 +100,42 @@ namespace PolyVox && (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary); } + bool Region::containsPointInX(float pos, float boundary) const + { + return (pos <= m_v3dUpperCorner.getX() - boundary) + && (pos >= m_v3dLowerCorner.getX() + boundary); + } + + bool Region::containsPointInX(int32_t pos, uint8_t boundary) const + { + return (pos <= m_v3dUpperCorner.getX() - boundary) + && (pos >= m_v3dLowerCorner.getX() + boundary); + } + + bool Region::containsPointInY(float pos, float boundary) const + { + return (pos <= m_v3dUpperCorner.getY() - boundary) + && (pos >= m_v3dLowerCorner.getY() + boundary); + } + + bool Region::containsPointInY(int32_t pos, uint8_t boundary) const + { + return (pos <= m_v3dUpperCorner.getY() - boundary) + && (pos >= m_v3dLowerCorner.getY() + boundary); + } + + bool Region::containsPointInZ(float pos, float boundary) const + { + return (pos <= m_v3dUpperCorner.getZ() - boundary) + && (pos >= m_v3dLowerCorner.getZ() + boundary); + } + + bool Region::containsPointInZ(int32_t pos, uint8_t boundary) const + { + return (pos <= m_v3dUpperCorner.getZ() - boundary) + && (pos >= m_v3dLowerCorner.getZ() + boundary); + } + void Region::cropTo(const Region& other) { m_v3dLowerCorner.setX((std::max)(m_v3dLowerCorner.getX(), other.m_v3dLowerCorner.getX())); From e8b3fd16e24434f3f810eb2bbb4530251f1e4578 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 15 Aug 2011 21:31:52 +0100 Subject: [PATCH 04/11] Initial version of IteratorController and making LowPassFilter use iterators. --- library/PolyVoxCore/CMakeLists.txt | 2 ++ .../include/PolyVoxCore/LowPassFilter.inl | 31 +++++++++++++++++-- tests/TestLowPassFilter.cpp | 4 +++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index eb848533..b5d63110 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -31,6 +31,8 @@ SET(CORE_INC_FILES include/PolyVoxCore/Density.h include/PolyVoxCore/GradientEstimators.h include/PolyVoxCore/GradientEstimators.inl + include/PolyVoxCore/IteratorController.h + include/PolyVoxCore/IteratorController.inl include/PolyVoxCore/LargeVolume.h include/PolyVoxCore/LargeVolume.inl include/PolyVoxCore/LargeVolumeSampler.inl diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index 1c8c1a5a..affa90f2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -21,6 +21,7 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +#include "PolyVoxCore/IteratorController.h" #include "PolyVoxCore/RawVolume.h" namespace PolyVox @@ -139,8 +140,34 @@ namespace PolyVox } } + RawVolume::Sampler satVolumeIter(&satVolume); + + IteratorController::Sampler> satIterCont; + satIterCont.m_regValid = Region(satLowerCorner, satUpperCorner); + satIterCont.m_Iter = &satVolumeIter; + satIterCont.reset(); + + SrcVolumeType::Sampler srcVolumeIter(m_pVolSrc); + + IteratorController::Sampler> srcIterCont; + srcIterCont.m_regValid = Region(satLowerCorner, satUpperCorner); + srcIterCont.m_Iter = &srcVolumeIter; + srcIterCont.reset(); + + do + { + uint32_t previousSum = satVolumeIter.peekVoxel1nx0py0pz(); + + uint32_t currentVal = srcVolumeIter.getVoxel().getDensity(); + + satVolumeIter.setVoxel(previousSum + currentVal); + + srcIterCont.moveForward(); + + }while(satIterCont.moveForward()); + //Build SAT in three passes - for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) + /*for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { for(int32_t y = satLowerCorner.getY(); y <= satUpperCorner.getY(); y++) { @@ -152,7 +179,7 @@ namespace PolyVox satVolume.setVoxelAt(x,y,z,previousSum + currentVal); } } - } + }*/ for(int32_t z = satLowerCorner.getZ(); z <= satUpperCorner.getZ(); z++) { diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp index 604b12fd..f4129253 100644 --- a/tests/TestLowPassFilter.cpp +++ b/tests/TestLowPassFilter.cpp @@ -61,6 +61,10 @@ void TestLowPassFilter::testExecute() LowPassFilter pass1(&volData, reg, &resultVolume, reg, 5); pass1.executeSAT(); + + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(1,2,3).getDensity()) << std::endl; // 7 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(10,6,7).getDensity()) << std::endl; // 17 + std::cout << "Voxel = " << static_cast(resultVolume.getVoxelAt(15,2,12).getDensity()) << std::endl; // 4 } QTEST_MAIN(TestLowPassFilter) From 7515186b476473d509b7e99c7c56ebe32f4a9558 Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 17 Aug 2011 22:49:20 +0100 Subject: [PATCH 05/11] Initial checkin of IteratorController --- .../include/PolyVoxCore/IteratorController.h | 44 +++++++++++++ .../PolyVoxCore/IteratorController.inl | 63 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 library/PolyVoxCore/include/PolyVoxCore/IteratorController.h create mode 100644 library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl diff --git a/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h new file mode 100644 index 00000000..527263eb --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h @@ -0,0 +1,44 @@ +/******************************************************************************* +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_IteratorController_H__ +#define __PolyVox_IteratorController_H__ + +namespace PolyVox +{ + template + class IteratorController + { + public: + void reset(void); + bool moveForward(void); + + public: + Region m_regValid; + IteratorType* m_Iter; + }; +} + +#include "PolyVoxCore/IteratorController.inl" + +#endif //__PolyVox_IteratorController_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl new file mode 100644 index 00000000..82fbdd08 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl @@ -0,0 +1,63 @@ +/******************************************************************************* +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 + void IteratorController::reset(void) + { + m_Iter->setPosition(m_regValid.getLowerCorner()); + } + + template + bool IteratorController::moveForward(void) + { + Vector3DInt32 v3dInitialPosition(m_Iter->getPosX(), m_Iter->getPosY(), m_Iter->getPosZ()); + + if(v3dInitialPosition.getX() < m_regValid.getUpperCorner().getX()) + { + m_Iter->movePositiveX(); + return true; + } + + v3dInitialPosition.setX(m_regValid.getLowerCorner().getX()); + + if(v3dInitialPosition.getY() < m_regValid.getUpperCorner().getY()) + { + v3dInitialPosition.setY(v3dInitialPosition.getY() + 1); + m_Iter->setPosition(v3dInitialPosition); + return true; + } + + v3dInitialPosition.setY(m_regValid.getLowerCorner().getY()); + + if(v3dInitialPosition.getZ() < m_regValid.getUpperCorner().getZ()) + { + v3dInitialPosition.setZ(v3dInitialPosition.getZ() + 1); + m_Iter->setPosition(v3dInitialPosition); + return true; + } + + return false; + } +} From bdc2770cba68244a2f1aa0e70be97072e4f282a2 Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 18 Aug 2011 22:45:39 +0100 Subject: [PATCH 06/11] G++ compile fixes. --- examples/OpenGL/main.cpp | 2 +- library/PolyVoxCore/include/PolyVoxCore/Density.h | 4 +++- library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl | 6 +++--- library/PolyVoxCore/include/PolyVoxCore/Material.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl | 4 ++-- .../PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl | 6 +++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 22ad8e6f..9930082a 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -102,7 +102,7 @@ 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 - RawVolume tempVolume(Region(0,0,0,128, 128, 128)); + RawVolume tempVolume(PolyVox::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); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index a2084c3e..368b5234 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -27,6 +27,8 @@ freely, subject to the following restrictions: #include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxImpl/TypeDef.h" +#include + namespace PolyVox { ///This class represents a voxel storing only a density. @@ -62,7 +64,7 @@ namespace PolyVox Type getMaterial() const throw() { return 1; } void setDensity(Type uDensity) { m_uDensity = uDensity; } - void setMaterial(Type uMaterial) { assert("Cannot set material on voxel of type 'Density'"); } + void setMaterial(Type uMaterial) { assert(false); } //Cannot set material on voxel of type Density static Type getMaxDensity() throw() { return (0x01 << (sizeof(Type) * 8)) - 1; } static Type getMinDensity() throw() { return 0; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index affa90f2..04dc3f93 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -65,7 +65,7 @@ namespace PolyVox //int32_t iDstMaxY = m_regDst.getUpperCorner().getY(); //int32_t iDstMaxZ = m_regDst.getUpperCorner().getZ(); - SrcVolumeType::Sampler srcSampler(m_pVolSrc); + typename SrcVolumeType::Sampler srcSampler(m_pVolSrc); for(int32_t iSrcZ = iSrcMinZ, iDstZ = iDstMinZ; iSrcZ <= iSrcMaxZ; iSrcZ++, iDstZ++) { @@ -147,9 +147,9 @@ namespace PolyVox satIterCont.m_Iter = &satVolumeIter; satIterCont.reset(); - SrcVolumeType::Sampler srcVolumeIter(m_pVolSrc); + typename SrcVolumeType::Sampler srcVolumeIter(m_pVolSrc); - IteratorController::Sampler> srcIterCont; + IteratorController::Sampler> srcIterCont; srcIterCont.m_regValid = Region(satLowerCorner, satUpperCorner); srcIterCont.m_Iter = &srcVolumeIter; srcIterCont.reset(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 8f6ff962..54fbd848 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -76,7 +76,7 @@ namespace PolyVox Type getMaterial() const throw() { return m_uMaterial; } - void setDensity(Type /*uDensity*/) { assert("Cannot set density on voxel of type 'Material'"); } + void setDensity(Type /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } static Type getMaxDensity() throw() { return 2; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 27257dc6..6e1e8875 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -87,7 +87,7 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { - const Vector3DInt32& v3dLowerCorner = m_regValidRegion.getLowerCorner(); + const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); @@ -136,7 +136,7 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { - const Vector3DInt32& v3dLowerCorner = m_regValidRegion.getLowerCorner(); + const Vector3DInt32& v3dLowerCorner = this->m_regValidRegion.getLowerCorner(); int32_t iLocalXPos = uXPos - v3dLowerCorner.getX(); int32_t iLocalYPos = uYPos - v3dLowerCorner.getY(); int32_t iLocalZPos = uZPos - v3dLowerCorner.getZ(); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index bf4f97b1..2feac83f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -100,9 +100,9 @@ namespace PolyVox mCurrentVoxel = this->mVolume->m_pData + uVoxelIndex; - m_bIsCurrentPositionValidInX = mVolume->getEnclosingRegion().containsPointInX(xPos); - m_bIsCurrentPositionValidInY = mVolume->getEnclosingRegion().containsPointInY(yPos); - m_bIsCurrentPositionValidInZ = mVolume->getEnclosingRegion().containsPointInZ(zPos); + m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(xPos); + m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(yPos); + m_bIsCurrentPositionValidInZ = this->mVolume->getEnclosingRegion().containsPointInZ(zPos); } template From 894455e35f8891f862465399c2f6941484978e0b Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 4 Sep 2011 12:12:30 +0100 Subject: [PATCH 07/11] Tidying up of headers and #includes. --- examples/OpenGL/Shapes.h | 2 +- .../include/PolyVoxCore/AStarPathfinder.h | 8 +++--- .../include/PolyVoxCore/AStarPathfinder.inl | 2 -- .../PolyVoxCore/AmbientOcclusionCalculator.h | 10 +++++-- .../AmbientOcclusionCalculator.inl | 9 ------- .../PolyVoxCore/include/PolyVoxCore/Array.h | 4 +-- .../include/PolyVoxCore/ConstVolumeProxy.h | 2 +- .../PolyVoxCore/CubicSurfaceExtractor.h | 7 +++-- .../PolyVoxCore/CubicSurfaceExtractor.inl | 6 ----- .../CubicSurfaceExtractorWithNormals.h | 6 ++--- .../CubicSurfaceExtractorWithNormals.inl | 6 ----- .../PolyVoxCore/include/PolyVoxCore/Density.h | 1 - .../include/PolyVoxCore/GradientEstimators.h | 5 ++-- .../PolyVoxCore/GradientEstimators.inl | 4 --- .../include/PolyVoxCore/IteratorController.h | 2 ++ .../include/PolyVoxCore/LargeVolume.h | 12 +++++++-- .../include/PolyVoxCore/LargeVolume.inl | 12 +-------- .../PolyVoxCore/LargeVolumeSampler.inl | 7 ----- .../include/PolyVoxCore/LowPassFilter.h | 3 ++- .../include/PolyVoxCore/LowPassFilter.inl | 3 --- .../include/PolyVoxCore/Material.h | 1 - .../include/PolyVoxCore/MaterialDensityPair.h | 1 - .../include/PolyVoxCore/MeshDecimator.h | 2 ++ .../include/PolyVoxCore/MeshDecimator.inl | 2 -- .../PolyVoxCore/PolyVoxForwardDeclarations.h | 8 ------ .../include/PolyVoxCore/RawVolume.h | 6 ++++- .../include/PolyVoxCore/RawVolume.inl | 11 -------- .../include/PolyVoxCore/RawVolumeSampler.inl | 7 ----- .../PolyVoxCore/include/PolyVoxCore/Raycast.h | 2 ++ .../include/PolyVoxCore/Raycast.inl | 1 + .../include/PolyVoxCore/RaycastWithCallback.h | 2 ++ .../PolyVoxCore/RaycastWithCallback.inl | 1 + .../PolyVoxCore/include/PolyVoxCore/Region.h | 1 + .../include/PolyVoxCore/SimpleVolume.h | 9 ++++++- .../include/PolyVoxCore/SimpleVolume.inl | 11 -------- .../include/PolyVoxCore/SimpleVolumeBlock.inl | 8 ------ .../PolyVoxCore/SimpleVolumeSampler.inl | 7 ----- .../include/PolyVoxCore/SurfaceExtractor.h | 7 ++--- .../include/PolyVoxCore/SurfaceExtractor.inl | 6 ----- .../include/PolyVoxCore/SurfaceMesh.h | 17 +++++++----- .../include/PolyVoxCore/SurfaceMesh.inl | 10 ++----- .../PolyVoxCore/include/PolyVoxCore/Vector.h | 5 +++- .../include/PolyVoxCore/Vector.inl | 5 ---- .../include/PolyVoxCore/VertexTypes.h | 1 + .../PolyVoxCore/include/PolyVoxCore/Volume.h | 5 ++-- .../include/PolyVoxCore/Volume.inl | 6 ----- .../include/PolyVoxCore/VolumeResampler.h | 3 --- .../include/PolyVoxCore/VolumeSampler.inl | 6 ----- .../include/PolyVoxCore/VoxelFilters.h | 3 --- .../include/PolyVoxImpl/AStarPathfinderImpl.h | 1 + .../PolyVoxCore/include/PolyVoxImpl/Block.h | 6 ++--- .../PolyVoxCore/include/PolyVoxImpl/Block.inl | 1 - .../include/PolyVoxImpl/RandomUnitVectors.h | 2 ++ .../include/PolyVoxImpl/RandomVectors.h | 2 ++ .../include/PolyVoxImpl/SubArray.h | 2 ++ .../PolyVoxCore/source/AStarPathfinder.cpp | 2 -- .../PolyVoxCore/source/GradientEstimators.cpp | 5 +--- library/PolyVoxCore/source/MeshDecimator.cpp | 26 ++++++++++++++++++- library/PolyVoxCore/source/VertexTypes.cpp | 2 -- .../include/PolyVoxUtil/Serialization.h | 3 ++- .../include/PolyVoxUtil/Serialization.inl | 2 -- .../include/PolyVoxUtil/VolumeChangeTracker.h | 5 ++-- .../PolyVoxUtil/VolumeChangeTracker.inl | 8 ------ tests/TestAStarPathfinder.cpp | 1 + 64 files changed, 128 insertions(+), 205 deletions(-) diff --git a/examples/OpenGL/Shapes.h b/examples/OpenGL/Shapes.h index c25c5f8f..93f047fd 100644 --- a/examples/OpenGL/Shapes.h +++ b/examples/OpenGL/Shapes.h @@ -24,8 +24,8 @@ freely, subject to the following restrictions: #ifndef __OpenGLExample_Shapes_H__ #define __OpenGLExample_Shapes_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxCore/MaterialDensityPair.h" void createSphereInVolume(PolyVox::LargeVolume& volData, float fRadius, uint8_t uValue); void createCubeInVolume(PolyVox::LargeVolume& volData, PolyVox::Vector3DInt32 lowerCorner, PolyVox::Vector3DInt32 upperCorner, uint8_t uValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h index 1518c18e..24499451 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h @@ -24,13 +24,13 @@ freely, subject to the following restrictions: #ifndef __PolyVox_AStarPathfinder_H__ #define __PolyVox_AStarPathfinder_H__ -#include "PolyVoxCore/Array.h" #include "PolyVoxImpl/AStarPathfinderImpl.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/LargeVolume.h" - #include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/Array.h" + +#include + namespace PolyVox { const float sqrt_1 = 1.0f; diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl index 9159b02f..54a5a826 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl @@ -21,8 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Material.h" - namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h index 8b02d03b..c1310c4c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h @@ -24,8 +24,14 @@ freely, subject to the following restrictions: #ifndef __AmbientOcclusionCalculator_H__ #define __AmbientOcclusionCalculator_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxImpl/RandomUnitVectors.h" +#include "PolyVoxImpl/RandomVectors.h" + +#include "PolyVoxCore/Array.h" +#include "PolyVoxCore/Region.h" +#include "PolyVoxCore/Raycast.h" + +#include namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index 9c3453de..29e7e4ae 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -21,15 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/Raycast.h" -#include "PolyVoxCore/LargeVolume.h" - -#include "PolyVoxImpl/RandomUnitVectors.h" -#include "PolyVoxImpl/RandomVectors.h" - -#include - namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/Array.h b/library/PolyVoxCore/include/PolyVoxCore/Array.h index f4a701b8..acb061bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Array.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Array.h @@ -24,10 +24,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Array_H__ #define __PolyVox_Array_H__ -#include "PolyVoxCore/ArraySizes.h" //Not strictly required, but convienient - #include "PolyVoxImpl/SubArray.h" +#include "PolyVoxCore/ArraySizes.h" //Not strictly required, but convienient + namespace PolyVox { ///Provides an efficient implementation of a multidimensional array. diff --git a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h index 51861073..bde93f4d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h +++ b/library/PolyVoxCore/include/PolyVoxCore/ConstVolumeProxy.h @@ -24,8 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_ConstVolumeProxy_H__ #define __PolyVox_ConstVolumeProxy_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxCore/Region.h" +#include "PolyVoxCore/Vector.h" namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 17b6189d..c6d362dd 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -24,12 +24,11 @@ freely, subject to the following restrictions: #ifndef __PolyVox_CubicSurfaceExtractor_H__ #define __PolyVox_CubicSurfaceExtractor_H__ -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/LargeVolume.h" - #include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/Array.h" +#include "PolyVoxCore/SurfaceMesh.h" + namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index fae71749..68c00255 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -21,12 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxImpl/MarchingCubesTables.h" -#include "PolyVoxCore/VertexTypes.h" - namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h index 0f8f6c62..dfba9482 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h @@ -24,10 +24,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_CubicSurfaceExtractorWithNormals_H__ #define __PolyVox_CubicSurfaceExtractorWithNormals_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxImpl/MarchingCubesTables.h" -#include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/Array.h" +#include "PolyVoxCore/SurfaceMesh.h" namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index 9401eebc..da0ebf7e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -21,12 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxImpl/MarchingCubesTables.h" -#include "PolyVoxCore/VertexTypes.h" - namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index a2084c3e..5994b0f3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -24,7 +24,6 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Density_H__ #define __PolyVox_Density_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxImpl/TypeDef.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h index 641c9dc2..3f374308 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h +++ b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.h @@ -24,9 +24,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_GradientEstimators_H__ #define __PolyVox_GradientEstimators_H__ -#include - #include "PolyVoxCore/Vector.h" +#include "PolyVoxCore/VoxelFilters.h" + +#include namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl index f3b7116c..eec70eca 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/GradientEstimators.inl @@ -21,10 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/VoxelFilters.h" - -#include "PolyVoxCore/LargeVolume.h" - namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h index 527263eb..935cc845 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h +++ b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_IteratorController_H__ #define __PolyVox_IteratorController_H__ +#include "PolyVoxCore/Region.h" + namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 323c7054..3a232997 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -25,14 +25,19 @@ freely, subject to the following restrictions: #define __PolyVox_LargeVolume_H__ #include "PolyVoxImpl/Block.h" +#include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Volume.h" #include +#include +#include //For abort() +#include //For memcpy +#include #include -#include #include +#include //For invalid_argument #include namespace PolyVox @@ -141,6 +146,9 @@ namespace PolyVox /// This is true even if you are only reading data from the volume, as concurrently reading from different threads can invalidate the contents /// of the block cache (amoung other problems). //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + template class ConstVolumeProxy; + template class LargeVolume : public Volume { diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index b041685c..75486746 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -21,18 +21,8 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ +//Included here rather than in the .h because it refers to LargeVolume (avoids forward declaration) #include "PolyVoxCore/ConstVolumeProxy.h" -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/Log.h" -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/Vector.h" - -#include -#include -#include //For abort() -#include //For memcpy -#include -#include //For invalid_argument namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index f89d4c1b..86f9dcac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -21,13 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/LargeVolume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" - -#include - #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) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h index 3e93f3ec..6379b13b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h @@ -24,7 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_LowPassFilter_H__ #define __PolyVox_LowPassFilter_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/IteratorController.h" +#include "PolyVoxCore/RawVolume.h" //Is this desirable? #include "PolyVoxCore/Region.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index affa90f2..b3f6fce5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -21,9 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/IteratorController.h" -#include "PolyVoxCore/RawVolume.h" - namespace PolyVox { template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 8f6ff962..040c482a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -24,7 +24,6 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Material_H__ #define __PolyVox_Material_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxImpl/TypeDef.h" #include diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 4ca6d5ba..03bff183 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -24,7 +24,6 @@ freely, subject to the following restrictions: #ifndef __PolyVox_MaterialDensityPair_H__ #define __PolyVox_MaterialDensityPair_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxImpl/TypeDef.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.h b/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.h index dbfe89ce..8c3218ad 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.h @@ -24,7 +24,9 @@ freely, subject to the following restrictions: #ifndef __PolyVox_MeshDecimator_H__ #define __PolyVox_MeshDecimator_H__ +#include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/Vector.h" +#include "PolyVoxCore/VertexTypes.h" #include #include diff --git a/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl b/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl index 381b5ef5..367c5379 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl @@ -21,8 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/SurfaceMesh.h" - namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h index 656b3e1e..83b9b4df 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h @@ -60,18 +60,10 @@ namespace PolyVox template class Block; - template class ConstVolumeProxy; - //---------- LargeVolume ---------- template class LargeVolume; //--------------------------------- - //---------- Mesh ---------- - class Mesh; - class MeshEdge; - class MeshFace; - class MeshVertex; - //--------------------------------- template class Density; typedef Density Density8; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index 83a287d1..fb73f6ea 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -24,12 +24,16 @@ freely, subject to the following restrictions: #ifndef __PolyVox_RawVolume_H__ #define __PolyVox_RawVolume_H__ +#include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Volume.h" +#include +#include //For abort() #include #include +#include //For invalid_argument namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index 27257dc6..c6d0f62e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl @@ -21,17 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/ConstVolumeProxy.h" -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/Log.h" -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/Vector.h" - -#include -#include -#include //For abort() -#include //For invalid_argument - namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index bf4f97b1..7f2d70f7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -21,13 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/RawVolume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" - -#include - #define BORDER_LOWX(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) #define BORDER_HIGHX(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) #define BORDER_LOWY(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index 9282b26b..b94cf5f8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Raycast_H__ #define __PolyVox_Raycast_H__ +#include "PolyVoxCore/Vector.h" + namespace PolyVox { /// Stores the result of a raycast operation. diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl index ccca4113..fb0f99ef 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl @@ -20,6 +20,7 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. *******************************************************************************/ + namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.h b/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.h index fdf8746d..bb53812f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_RaycastWithCallback_H__ #define __PolyVox_RaycastWithCallback_H__ +#include "PolyVoxCore/Vector.h" + namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.inl b/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.inl index df50c7bd..4e29cff5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RaycastWithCallback.inl @@ -20,6 +20,7 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. *******************************************************************************/ + namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/Region.h b/library/PolyVoxCore/include/PolyVoxCore/Region.h index e9297492..3668d847 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Region.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Region.h @@ -25,6 +25,7 @@ freely, subject to the following restrictions: #define __PolyVox_Region_H__ #include "PolyVoxImpl/TypeDef.h" + #include "PolyVoxCore/Vector.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index c11674f5..b9af204e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -24,12 +24,19 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SimpleVolume_H__ #define __PolyVox_SimpleVolume_H__ +#include "PolyVoxImpl/Utility.h" + +#include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Vector.h" #include "PolyVoxCore/Volume.h" +#include +#include //For abort() +#include //For memcpy #include #include +#include //For invalid_argument namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 75133e32..ace3929e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -21,17 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/ConstVolumeProxy.h" -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/Log.h" -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/Vector.h" - -#include -#include -#include //For abort() -#include //For invalid_argument - namespace PolyVox { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl index 4d3eb709..9b2d0c85 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl @@ -21,14 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Utility.h" -#include "Vector.h" - -#include -#include //For memcpy -#include -#include //for std::invalid_argument - namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 7148b510..6b1bf725 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -21,13 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/SimpleVolume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" - -#include - #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) diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h index 3a6b985a..484944fc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h @@ -24,11 +24,12 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SurfaceExtractor_H__ #define __PolyVox_SurfaceExtractor_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/LargeVolume.h" - +#include "PolyVoxImpl/MarchingCubesTables.h" #include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/Array.h" +#include "PolyVoxCore/SurfaceMesh.h" + namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl index a040fbc6..24b8178d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.inl @@ -21,12 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Array.h" -#include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxImpl/MarchingCubesTables.h" -#include "PolyVoxCore/VertexTypes.h" - namespace PolyVox { template< template class VolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h index d51b399f..c0833d5a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h @@ -24,15 +24,18 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SurfaceMesh_H__ #define __PolyVox_SurfaceMesh_H__ -#include -#include -#include - -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/VertexTypes.h" #include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/Region.h" +#include "PolyVoxCore/VertexTypes.h" //Should probably do away with this on in the future... + +#include +#include +#include +#include +#include +#include + namespace PolyVox { class LodRecord diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl index 033388c1..83fc97ab 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl @@ -21,12 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include -#include -#include - -using namespace std; - namespace PolyVox { template @@ -366,7 +360,7 @@ namespace PolyVox template void SurfaceMesh::removeUnusedVertices(void) { - vector isVertexUsed(m_vecVertices.size()); + std::vector isVertexUsed(m_vecVertices.size()); fill(isVertexUsed.begin(), isVertexUsed.end(), false); for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) @@ -376,7 +370,7 @@ namespace PolyVox } int noOfUsedVertices = 0; - vector newPos(m_vecVertices.size()); + std::vector newPos(m_vecVertices.size()); for(uint32_t vertCt = 0; vertCt < m_vecVertices.size(); vertCt++) { if(isVertexUsed[vertCt]) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.h b/library/PolyVoxCore/include/PolyVoxCore/Vector.h index 82c2fdbf..1269fe73 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.h @@ -24,8 +24,11 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Vector_H__ #define __PolyVox_Vector_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxImpl/TypeDef.h" +#include +#include +#include #include namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 6c0f3b19..bd9dd88e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -21,11 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include -#include -#include -#include - namespace PolyVox { //-------------------------- Constructors, etc --------------------------------- diff --git a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h index 3c2fd6ad..3e0df0b4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h @@ -25,6 +25,7 @@ freely, subject to the following restrictions: #define __PolyVox_SurfaceVertex_H__ #include "PolyVoxImpl/TypeDef.h" + #include "PolyVoxCore/Vector.h" #include diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.h b/library/PolyVoxCore/include/PolyVoxCore/Volume.h index 298b90af..3a3368b5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.h @@ -24,11 +24,12 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Volume_H__ #define __PolyVox_Volume_H__ +#include "PolyVoxCore/Log.h" #include "PolyVoxCore/Region.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxCore/Vector.h" +#include #include -#include namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl index fc17962c..0db51e3a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Volume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Volume.inl @@ -21,12 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/Log.h" -#include "PolyVoxCore/Region.h" -#include "PolyVoxCore/Vector.h" - -#include - namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h index fce4c5e9..1e0fa526 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h @@ -24,8 +24,6 @@ freely, subject to the following restrictions: #ifndef __PolyVox_VolumeResampler_H__ #define __PolyVox_VolumeResampler_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" - namespace PolyVox { template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> @@ -38,7 +36,6 @@ namespace PolyVox private: void resampleSameSize(); - void resampleHalfSize(); void resampleArbitrary(); //Source data diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl index 0dbf6ac1..57fdeb09 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl @@ -21,12 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/Volume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" - -#include namespace PolyVox { template diff --git a/library/PolyVoxCore/include/PolyVoxCore/VoxelFilters.h b/library/PolyVoxCore/include/PolyVoxCore/VoxelFilters.h index f680a875..17d65e59 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VoxelFilters.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VoxelFilters.h @@ -24,11 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_VoxelFilters_H__ #define __PolyVox_VoxelFilters_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxImpl/TypeDef.h" -#include "PolyVoxCore/LargeVolume.h" - namespace PolyVox { template< template class VolumeType> diff --git a/library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h b/library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h index 311b6f85..e4a03498 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/AStarPathfinderImpl.h @@ -26,6 +26,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Vector.h" +#include #include //For numeric_limits #include #include diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.h b/library/PolyVoxCore/include/PolyVoxImpl/Block.h index 34f0a6d9..c102ffa7 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.h @@ -24,7 +24,9 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Block_H__ #define __PolyVox_Block_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxImpl/TypeDef.h" +#include "PolyVoxCore/Vector.h" + #include #include @@ -44,8 +46,6 @@ namespace PolyVox static uint32_t maxRunlength(void) {return (std::numeric_limits::max)();} }; - //Make Sampler a friend - friend class LargeVolume::Sampler; public: Block(uint16_t uSideLength = 0); diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl index 1d389c68..147e8fab 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl @@ -23,7 +23,6 @@ freely, subject to the following restrictions: #include "PolyVoxImpl/Utility.h" #include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/LargeVolume.h" #include #include //For memcpy diff --git a/library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h b/library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h index 8702f865..7e1c237d 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/RandomUnitVectors.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_RandomUnitVectors_H__ #define __PolyVox_RandomUnitVectors_H__ +#include "PolyVoxImpl/TypeDef.h" + #include "PolyVoxCore/Vector.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h b/library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h index 2544d97d..6df39f08 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/RandomVectors.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_RandomVectors_H__ #define __PolyVox_RandomVectors_H__ +#include "PolyVoxImpl/TypeDef.h" + #include "PolyVoxCore/Vector.h" namespace PolyVox diff --git a/library/PolyVoxCore/include/PolyVoxImpl/SubArray.h b/library/PolyVoxCore/include/PolyVoxImpl/SubArray.h index 2b30eefd..9055429a 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/SubArray.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/SubArray.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_SubArray_H__ #define __PolyVox_SubArray_H__ +#include "PolyVoxImpl/TypeDef.h" + namespace PolyVox { template class Array; diff --git a/library/PolyVoxCore/source/AStarPathfinder.cpp b/library/PolyVoxCore/source/AStarPathfinder.cpp index 848245ce..95c680a1 100644 --- a/library/PolyVoxCore/source/AStarPathfinder.cpp +++ b/library/PolyVoxCore/source/AStarPathfinder.cpp @@ -23,8 +23,6 @@ freely, subject to the following restrictions: #include "PolyVoxCore/AStarPathfinder.h" -#include "PolyVoxCore/Material.h" - using namespace PolyVox; namespace PolyVox diff --git a/library/PolyVoxCore/source/GradientEstimators.cpp b/library/PolyVoxCore/source/GradientEstimators.cpp index 0ee44a5f..74417667 100644 --- a/library/PolyVoxCore/source/GradientEstimators.cpp +++ b/library/PolyVoxCore/source/GradientEstimators.cpp @@ -21,12 +21,9 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/GradientEstimators.h" -#include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxCore/VertexTypes.h" #include "PolyVoxImpl/TypeDef.h" -#include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxCore/GradientEstimators.h" using namespace std; diff --git a/library/PolyVoxCore/source/MeshDecimator.cpp b/library/PolyVoxCore/source/MeshDecimator.cpp index 1908f5ac..686e62c2 100644 --- a/library/PolyVoxCore/source/MeshDecimator.cpp +++ b/library/PolyVoxCore/source/MeshDecimator.cpp @@ -1,7 +1,31 @@ -#include "PolyVoxCore/MeshDecimator.h" +/******************************************************************************* +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. +*******************************************************************************/ + +#include "PolyVoxCore/MeshDecimator.h" #include "PolyVoxCore/SurfaceMesh.h" +using namespace std; + namespace PolyVox { template<> diff --git a/library/PolyVoxCore/source/VertexTypes.cpp b/library/PolyVoxCore/source/VertexTypes.cpp index d966fc9f..db41759e 100644 --- a/library/PolyVoxCore/source/VertexTypes.cpp +++ b/library/PolyVoxCore/source/VertexTypes.cpp @@ -21,8 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include - #include "PolyVoxCore/VertexTypes.h" namespace PolyVox diff --git a/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.h b/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.h index 17241db1..61eebfb7 100644 --- a/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.h +++ b/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.h @@ -24,7 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Serialization_H__ #define __PolyVox_Serialization_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include "PolyVoxImpl/Utility.h" + #include "PolyVoxCore/Region.h" #include diff --git a/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.inl b/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.inl index e7fc630b..054a8f7f 100644 --- a/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.inl +++ b/library/PolyVoxUtil/include/PolyVoxUtil/Serialization.inl @@ -21,8 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Utility.h" - namespace PolyVox { //Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller. diff --git a/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.h b/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.h index 98aca8af..a10b2951 100644 --- a/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.h +++ b/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.h @@ -24,10 +24,11 @@ freely, subject to the following restrictions: #ifndef __PolyVox_VolumeChangeTracker_H__ #define __PolyVox_VolumeChangeTracker_H__ -#include +#include "PolyVoxImpl/Utility.h" -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxCore/Region.h" +#include "PolyVoxCore/SurfaceMesh.h" +#include "PolyVoxCore/Vector.h" namespace PolyVox { diff --git a/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.inl b/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.inl index 1f9eff8d..a426e653 100644 --- a/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.inl +++ b/library/PolyVoxUtil/include/PolyVoxUtil/VolumeChangeTracker.inl @@ -21,14 +21,6 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxCore/GradientEstimators.h" -#include "PolyVoxCore/SurfaceMesh.h" -#include "PolyVoxImpl/MarchingCubesTables.h" -#include "PolyVoxCore/VertexTypes.h" -#include "PolyVoxImpl/Utility.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/LargeVolume.h" - namespace PolyVox { template diff --git a/tests/TestAStarPathfinder.cpp b/tests/TestAStarPathfinder.cpp index cdbceddd..7df04a0a 100644 --- a/tests/TestAStarPathfinder.cpp +++ b/tests/TestAStarPathfinder.cpp @@ -24,6 +24,7 @@ freely, subject to the following restrictions: #include "TestAStarPathfinder.h" #include "PolyVoxCore/AStarPathfinder.h" +#include "PolyVoxCore/Material.h" #include "PolyVoxCore/RawVolume.h" #include From b84147f6501f1461f4929db5aff29a846e2baf61 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 4 Sep 2011 13:57:24 +0100 Subject: [PATCH 08/11] Replaced template 'hack' with preprocessor 'fix' to allow compilation on both GCC and Visual Studio. The previous approach was causing problems on VS2008. --- .../PolyVoxCore/include/PolyVoxCore/LargeVolume.h | 14 ++++++++++++-- .../PolyVoxCore/include/PolyVoxCore/RawVolume.h | 14 ++++++++++++-- .../PolyVoxCore/include/PolyVoxCore/SimpleVolume.h | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 3a232997..dac1004e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -153,8 +153,18 @@ namespace PolyVox class LargeVolume : public Volume { public: - typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn - class Sampler : public VolumeOfVoxelType::template Sampler< LargeVolume > + //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. + //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but + //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler + //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated + //in the future + //typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. + //class Sampler : public VolumeOfVoxelType::template Sampler< LargeVolume > +#if defined(_MSC_VER) + class Sampler : public Volume::Sampler< LargeVolume > //This line works on VS2010 +#else + class Sampler : public Volume::Sampler Nested< LargeVolume > //This line works on GCC +#endif { public: Sampler(LargeVolume* volume); diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index fb73f6ea..de56e31e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -42,8 +42,18 @@ namespace PolyVox { public: #ifndef SWIG - typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn - class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume > + //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. + //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but + //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler + //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated + //in the future + //typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. + //class Sampler : public VolumeOfVoxelType::template Sampler< RawVolume > +#if defined(_MSC_VER) + class Sampler : public Volume::Sampler< RawVolume > //This line works on VS2010 +#else + class Sampler : public Volume::Sampler Nested< RawVolume > //This line works on GCC +#endif { public: Sampler(RawVolume* volume); diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index b9af204e..58efadc6 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -67,8 +67,18 @@ namespace PolyVox uint8_t m_uSideLengthPower; }; - typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. See http://goo.gl/qu1wn - class Sampler : public VolumeOfVoxelType::template Sampler< SimpleVolume > + //There seems to be some descrepency between Visual Studio and GCC about how the following class should be declared. + //There is a work around (see also See http://goo.gl/qu1wn) given below which appears to work on VS2010 and GCC, but + //which seems to cause internal compiler errors on VS2008 when building with the /Gm 'Enable Minimal Rebuild' compiler + //option. For now it seems best to 'fix' it with the preprocessor insstead, but maybe the workaround can be reinstated + //in the future + //typedef Volume VolumeOfVoxelType; //Workaround for GCC/VS2010 differences. + //class Sampler : public VolumeOfVoxelType::template Sampler< SimpleVolume > +#if defined(_MSC_VER) + class Sampler : public Volume::Sampler< SimpleVolume > //This line works on VS2010 +#else + class Sampler : public Volume::Sampler Nested< SimpleVolume > //This line works on GCC +#endif { public: Sampler(SimpleVolume* volume); From 0c97756a0caa28d75e5f512b1513a94abe6318a2 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 5 Sep 2011 21:44:02 +0100 Subject: [PATCH 09/11] GCC fixes --- library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h | 1 + library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl | 4 ++-- library/PolyVoxCore/include/PolyVoxCore/RawVolume.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h | 2 ++ library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl | 3 ++- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h index 24499451..572cb0f1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h @@ -30,6 +30,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Array.h" #include +#include //For runtime_error namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index dac1004e..ba6e5523 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -163,7 +163,7 @@ namespace PolyVox #if defined(_MSC_VER) class Sampler : public Volume::Sampler< LargeVolume > //This line works on VS2010 #else - class Sampler : public Volume::Sampler Nested< LargeVolume > //This line works on GCC + class Sampler : public Volume::template Sampler< LargeVolume > //This line works on GCC #endif { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl b/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl index 367c5379..211e281b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MeshDecimator.inl @@ -259,9 +259,9 @@ namespace PolyVox bool MeshDecimator::collapseChangesFaceNormals(uint32_t uSrc, uint32_t uDst, float fThreshold) { bool faceFlipped = false; - vector& triangles = trianglesUsingVertex[uSrc]; + std::vector& triangles = trianglesUsingVertex[uSrc]; - for(vector::iterator triIter = triangles.begin(); triIter != triangles.end(); triIter++) + for(std::vector::iterator triIter = triangles.begin(); triIter != triangles.end(); triIter++) { uint32_t tri = *triIter; diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h index de56e31e..f5106e7d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.h @@ -52,7 +52,7 @@ namespace PolyVox #if defined(_MSC_VER) class Sampler : public Volume::Sampler< RawVolume > //This line works on VS2010 #else - class Sampler : public Volume::Sampler Nested< RawVolume > //This line works on GCC + class Sampler : public Volume::template Sampler< RawVolume > //This line works on GCC #endif { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 58efadc6..6ddeedb5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -77,7 +77,7 @@ namespace PolyVox #if defined(_MSC_VER) class Sampler : public Volume::Sampler< SimpleVolume > //This line works on VS2010 #else - class Sampler : public Volume::Sampler Nested< SimpleVolume > //This line works on GCC + class Sampler : public Volume::template Sampler< SimpleVolume > //This line works on GCC #endif { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h index 1e0fa526..f223f41b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h @@ -24,6 +24,8 @@ freely, subject to the following restrictions: #ifndef __PolyVox_VolumeResampler_H__ #define __PolyVox_VolumeResampler_H__ +#include + namespace PolyVox { template< template class SrcVolumeType, template class DestVolumeType, typename VoxelType> diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl index 6842c78f..9a5ffdeb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl @@ -119,7 +119,8 @@ namespace PolyVox uint8_t voxel110Den = voxel110.getDensity(); uint8_t voxel111Den = voxel111.getDensity(); - float dummy; + //FIXME - should accept all float parameters, but GCC complains? + double dummy; sx = modf(sx, &dummy); sy = modf(sy, &dummy); sz = modf(sz, &dummy); From df035d523734cc392d131fa9103126dffa5caaff Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 8 Sep 2011 21:29:23 +0100 Subject: [PATCH 10/11] Fixed memory leaks. --- library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl | 1 + library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h | 1 + library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl | 2 +- .../PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl | 6 ++++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 75486746..721488e0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -103,6 +103,7 @@ namespace PolyVox LargeVolume::~LargeVolume() { flushAll(); + delete[] m_pUncompressedBorderData; } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h index 6ddeedb5..0a45eb0b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.h @@ -49,6 +49,7 @@ namespace PolyVox { public: Block(uint16_t uSideLength = 0); + ~Block(); uint16_t getSideLength(void) const; VoxelType getVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index ace3929e..21f960a9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -71,7 +71,7 @@ namespace PolyVox SimpleVolume::~SimpleVolume() { delete[] m_pBlocks; - m_pBlocks = 0; + delete[] m_pUncompressedBorderData; } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl index 9b2d0c85..03e8c687 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl @@ -35,6 +35,12 @@ namespace PolyVox } } + template + SimpleVolume::Block::~Block() + { + delete[] m_tUncompressedData; + } + template uint16_t SimpleVolume::Block::getSideLength(void) const { From e4535b1255d85b4d13b8dc54e98632fb1e7d096c Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 21 Sep 2011 00:19:35 +0200 Subject: [PATCH 11/11] Add previousVoxel to raycast result. Thanks to Sceptrix for the patch http://thermite3d.org/phpBB3/viewtopic.php?t=243 --- library/PolyVoxCore/include/PolyVoxCore/Raycast.h | 1 + library/PolyVoxCore/include/PolyVoxCore/Raycast.inl | 2 ++ 2 files changed, 3 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index b94cf5f8..860f4efb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h @@ -41,6 +41,7 @@ namespace PolyVox bool foundIntersection; ///If an intersection was found then this field holds the intersecting voxel, otherwise it is undefined. Vector3DInt32 intersectionVoxel; + Vector3DInt32 previousVoxel; }; /// The Raycast class can be used to find the fist filled voxel along a given path. diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl index fb0f99ef..2c051073 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl @@ -143,6 +143,7 @@ namespace PolyVox m_result.intersectionVoxel = Vector3DInt32(i,j,k); return; } + m_result.previousVoxel = Vector3DInt32(i,j,k); if(tx <= ty && tx <= tz) { @@ -174,5 +175,6 @@ namespace PolyVox //Didn't hit anything m_result.foundIntersection = false; m_result.intersectionVoxel = Vector3DInt32(0,0,0); + m_result.previousVoxel = Vector3DInt32(0,0,0); } } \ No newline at end of file