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/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 63861e4e..9930082a 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(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); + 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 a1bcf575..b5d63110 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -29,14 +29,16 @@ 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/IteratorController.h + include/PolyVoxCore/IteratorController.inl include/PolyVoxCore/LargeVolume.h 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/AStarPathfinder.h b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h index 1518c18e..572cb0f1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.h @@ -24,13 +24,14 @@ 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 +#include //For runtime_error + 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..da0d14c7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -24,9 +24,10 @@ freely, subject to the following restrictions: #ifndef __PolyVox_Density_H__ #define __PolyVox_Density_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" #include "PolyVoxImpl/TypeDef.h" +#include + namespace PolyVox { ///This class represents a voxel storing only a density. @@ -62,7 +63,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/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/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/Filters.h b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h similarity index 73% rename from library/PolyVoxCore/include/PolyVoxCore/Filters.h rename to library/PolyVoxCore/include/PolyVoxCore/IteratorController.h index 5fd543d6..935cc845 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Filters.h +++ b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.h @@ -21,18 +21,26 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#ifndef __PolyVox_Filters_H__ -#define __PolyVox_Filters_H__ +#ifndef __PolyVox_IteratorController_H__ +#define __PolyVox_IteratorController_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 + template + class IteratorController + { + public: + void reset(void); + bool moveForward(void); -#include "PolyVoxCore/Filters.inl" + public: + Region m_regValid; + IteratorType* m_Iter; + }; +} -#endif \ No newline at end of file +#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; + } +} diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 2fb4fd0e..ba6e5523 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,12 +146,25 @@ 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 { 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::template Sampler< LargeVolume > //This line works on GCC +#endif { public: Sampler(LargeVolume* volume); @@ -162,6 +180,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/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index b041685c..721488e0 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 { @@ -113,6 +103,7 @@ namespace PolyVox LargeVolume::~LargeVolume() { flushAll(); + delete[] m_pUncompressedBorderData; } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 994a9ff3..86f9dcac 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -21,17 +21,11 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/LargeVolume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" - #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 +153,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 +528,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/LowPassFilter.h b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h new file mode 100644 index 00000000..6379b13b --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.h @@ -0,0 +1,60 @@ +/******************************************************************************* +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/IteratorController.h" +#include "PolyVoxCore/RawVolume.h" //Is this desirable? +#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, uint32_t uKernelSize); + + void execute(); + void executeSAT(); + + private: + //Source data + SrcVolumeType* m_pVolSrc; + Region m_regSrc; + + //Destination data + DestVolumeType* m_pVolDst; + Region m_regDst; + + //Kernel size + uint32_t m_uKernelSize; + }; + +}//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..9e6bc66d --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -0,0 +1,265 @@ +/******************************************************************************* +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, 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> + 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(); + + typename 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); + } + } + } + } + + 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); + } + } + } + + RawVolume::Sampler satVolumeIter(&satVolume); + + IteratorController::Sampler> satIterCont; + satIterCont.m_regValid = Region(satLowerCorner, satUpperCorner); + satIterCont.m_Iter = &satVolumeIter; + satIterCont.reset(); + + typename 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 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/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 8f6ff962..445961b0 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 @@ -76,7 +75,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/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..211e281b 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 { //////////////////////////////////////////////////////////////////////////////// @@ -261,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/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 d7d2b1bf..f5106e7d 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 { @@ -38,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::template Sampler< RawVolume > //This line works on GCC +#endif { public: Sampler(RawVolume* volume); @@ -52,6 +66,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 +111,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/RawVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolume.inl index cbbdbec9..93e41ca1 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 { //////////////////////////////////////////////////////////////////////////////// @@ -49,6 +38,8 @@ namespace PolyVox ) :Volume(regValid) { + setBorderValue(VoxelType()); + //Create a volume of the right size. resize(regValid); } @@ -85,11 +76,16 @@ namespace PolyVox { if(this->m_regValidRegion.containsPoint(Vector3DInt32(uXPos, uYPos, uZPos))) { + 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(); + return m_pData [ - uXPos + - uYPos * this->getWidth() + - uZPos * this->getWidth() * this->getHeight() + iLocalXPos + + iLocalYPos * this->getWidth() + + iLocalZPos * this->getWidth() * this->getHeight() ]; } else @@ -127,17 +123,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 = this->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..3d40273c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -21,19 +21,22 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/RawVolume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" +#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()) -#include 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 +66,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,13 +82,35 @@ namespace PolyVox this->mYPosInVolume = yPos; this->mZPosInVolume = zPos; - const uint32_t uVoxelIndex = xPos + - yPos * this->mVolume->getWidth() + - zPos * this->mVolume->getWidth() * this->mVolume->getHeight(); + 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_bIsCurrentPositionValid = this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos)); + m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(xPos); + m_bIsCurrentPositionValidInY = this->mVolume->getEnclosingRegion().containsPointInY(yPos); + m_bIsCurrentPositionValidInZ = this->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) + { + *mCurrentVoxel = tValue; + return true; + } + else + { + return false; + } } template @@ -93,7 +118,7 @@ namespace PolyVox { this->mXPosInVolume++; ++mCurrentVoxel; - m_bIsCurrentPositionValid = this->mXPosInVolume <= this->mVolume->getEnclosingRegion().getUpperCorner().getX(); + m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume); } template @@ -101,7 +126,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 @@ -109,7 +134,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 @@ -117,7 +142,7 @@ namespace PolyVox { this->mXPosInVolume--; --mCurrentVoxel; - m_bIsCurrentPositionValid = this->mXPosInVolume >= this->mVolume->getEnclosingRegion().getLowerCorner().getX(); + m_bIsCurrentPositionValidInX = this->mVolume->getEnclosingRegion().containsPointInX(this->mXPosInVolume); } template @@ -125,7 +150,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 @@ -133,60 +158,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); } @@ -195,24 +256,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); } @@ -225,24 +302,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); } @@ -251,54 +344,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/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index 9282b26b..860f4efb 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. @@ -39,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 ccca4113..2c051073 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 { //////////////////////////////////////////////////////////////////////////////// @@ -142,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) { @@ -173,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 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 5888df0d..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 @@ -51,6 +52,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..0a45eb0b 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 { @@ -42,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; @@ -60,8 +68,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::template Sampler< SimpleVolume > //This line works on GCC +#endif { public: Sampler(SimpleVolume* volume); @@ -77,6 +95,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 +198,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..21f960a9 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 { //////////////////////////////////////////////////////////////////////////////// @@ -82,7 +71,7 @@ namespace PolyVox SimpleVolume::~SimpleVolume() { delete[] m_pBlocks; - m_pBlocks = 0; + delete[] m_pUncompressedBorderData; } //////////////////////////////////////////////////////////////////////////////// @@ -143,7 +132,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 +194,7 @@ namespace PolyVox } m_uBlockSideLength = uBlockSideLength; + m_uNoOfVoxelsPerBlock = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength; m_pUncompressedBorderData = 0; this->m_regValidRegion = regValidRegion; @@ -230,8 +220,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 +256,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/SimpleVolumeBlock.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeBlock.inl index 4d3eb709..03e8c687 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 @@ -43,6 +35,12 @@ namespace PolyVox } } + template + SimpleVolume::Block::~Block() + { + delete[] m_tUncompressedData; + } + template uint16_t SimpleVolume::Block::getSideLength(void) const { diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index ba8bdb1a..6b1bf725 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -21,17 +21,11 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#include "PolyVoxImpl/Block.h" -#include "PolyVoxCore/SimpleVolume.h" -#include "PolyVoxCore/Vector.h" -#include "PolyVoxCore/Region.h" - #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 +153,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 +536,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/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 51b7634a..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 { @@ -47,10 +48,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); @@ -140,7 +142,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..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 @@ -197,7 +191,6 @@ namespace PolyVox uint32_t Volume::calculateSizeInBytes(void) { return getWidth() * getHeight() * getDepth() * sizeof(VoxelType); - } - + } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h index fce4c5e9..f223f41b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h @@ -24,7 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_VolumeResampler_H__ #define __PolyVox_VolumeResampler_H__ -#include "PolyVoxCore/PolyVoxForwardDeclarations.h" +#include namespace PolyVox { @@ -38,7 +38,6 @@ namespace PolyVox private: void resampleSameSize(); - void resampleHalfSize(); void resampleArbitrary(); //Source data 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); diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeSampler.inl index 68b2e314..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 @@ -91,6 +85,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/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/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())); 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/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/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 diff --git a/tests/TestLowPassFilter.cpp b/tests/TestLowPassFilter.cpp new file mode 100644 index 00000000..f4129253 --- /dev/null +++ b/tests/TestLowPassFilter.cpp @@ -0,0 +1,70 @@ +/******************************************************************************* +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(); + + 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) diff --git a/tests/TestLowPassFilter.h b/tests/TestLowPassFilter.h new file mode 100644 index 00000000..84cd7404 --- /dev/null +++ b/tests/TestLowPassFilter.h @@ -0,0 +1,37 @@ +/******************************************************************************* +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