From 8d3a66a08cb6eca2b1cd3769d130b5bb656f4228 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Feb 2012 12:51:54 +0100 Subject: [PATCH] Removed redundant hasMaterial and hasDensity traits. Changed AStar default validator. --- .../include/PolyVoxCore/AStarPathfinder.inl | 21 --------- .../PolyVoxCore/include/PolyVoxCore/Density.h | 4 -- .../include/PolyVoxCore/Material.h | 8 ---- .../include/PolyVoxCore/MaterialDensityPair.h | 8 ---- .../include/PolyVoxCore/SurfaceExtractor.h | 4 -- .../PolyVoxCore/include/PolyVoxCore/Voxel.h | 5 --- tests/TestAStarPathfinder.cpp | 43 ++++++++++++++++--- 7 files changed, 38 insertions(+), 55 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl index c7084341..64a873d3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AStarPathfinder.inl @@ -37,27 +37,6 @@ namespace PolyVox return false; } - if(VoxelTypeTraits::hasDensity()) - { - //and if their density is above the threshold. - VoxelType voxel = volData->getVoxelAt(v3dPos); - typename VoxelType::DensityType tThreshold = (VoxelTypeTraits::minDensity() + VoxelTypeTraits::maxDensity()) / 2; - if(voxel.getDensity() >= tThreshold) - { - return false; - } - } - - if(VoxelTypeTraits::hasMaterial()) - { - //and if their material is not zero. - VoxelType voxel = volData->getVoxelAt(v3dPos); - if(voxel.getMaterial() != 0) - { - return false; - } - } - return true; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 11864da4..acce62b1 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -99,10 +99,6 @@ namespace PolyVox public: typedef uint8_t DensityType; typedef uint8_t MaterialType; - static const bool HasDensity = true; - static const bool HasMaterial = false; - static bool hasDensity() { return true; } - static bool hasMaterial() { return false; } static Density8::DensityType minDensity() { return std::numeric_limits::min(); } static Density8::DensityType maxDensity() { return std::numeric_limits::max(); } }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index c50b3092..30e47f09 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -109,10 +109,6 @@ namespace PolyVox public: typedef uint8_t DensityType; typedef uint8_t MaterialType; - static const bool HasDensity = false; - static const bool HasMaterial = true; - static bool hasDensity() { return false; } - static bool hasMaterial() { return true; } static int minDensity() { assert(false); return 0; } static int maxDensity() { assert(false); return 0; } }; @@ -122,10 +118,6 @@ namespace PolyVox { public: typedef uint8_t DensityType; - static const bool HasDensity = false; - static const bool HasMaterial = true; - static bool hasDensity() { return false; } - static bool hasMaterial() { return true; } static int minDensity() { assert(false); return 0; } static int maxDensity() { assert(false); return 0; } }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index a7ff429c..4eb5167d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -92,10 +92,6 @@ namespace PolyVox public: typedef uint8_t DensityType; typedef uint8_t MaterialType; - static const bool HasDensity = true; - static const bool HasMaterial = true; - static bool hasDensity() { return true; } - static bool hasMaterial() { return true; } static MaterialDensityPair44::DensityType minDensity() { return 0; } static MaterialDensityPair44::DensityType maxDensity() { return 15; } }; @@ -106,10 +102,6 @@ namespace PolyVox public: typedef uint8_t DensityType; typedef uint8_t MaterialType; - static const bool HasDensity = true; - static const bool HasMaterial = true; - static bool hasDensity() { return true; } - static bool hasMaterial() { return true; } static MaterialDensityPair88::DensityType minDensity() { return 0; } static MaterialDensityPair88::DensityType maxDensity() { return 255; } }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h index aa42dc53..ceddf628 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceExtractor.h @@ -38,10 +38,6 @@ namespace PolyVox public: typedef uint8_t DensityType; typedef uint8_t MaterialType; - static const bool HasDensity = true; - static const bool HasMaterial = false; - static bool hasDensity() { return true; } - static bool hasMaterial() { return false; } static uint8_t minDensity() { return 0; } static uint8_t maxDensity() { return 255; } }; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h index 2bf47a7b..82c228f9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h @@ -48,11 +48,6 @@ namespace PolyVox public: typedef uint8_t DensityType; typedef uint8_t MaterialType; - static const bool HasDensity = false; - static const bool HasMaterial = false; - - static bool hasDensity() { return false; } - static bool hasMaterial() { return false; } // These default implementations return an int32_t rather than void so that the result can be // assigned to a variable for all voxel types (even those without density components). Calls diff --git a/tests/TestAStarPathfinder.cpp b/tests/TestAStarPathfinder.cpp index 667f12ad..3f092ec6 100644 --- a/tests/TestAStarPathfinder.cpp +++ b/tests/TestAStarPathfinder.cpp @@ -31,6 +31,24 @@ freely, subject to the following restrictions: using namespace PolyVox; +template< template class VolumeType, typename VoxelType> +bool testVoxelValidator(const VolumeType* volData, const Vector3DInt32& v3dPos) +{ + //Voxels are considered valid candidates for the path if they are inside the volume... + if(volData->getEnclosingRegion().containsPoint(v3dPos) == false) + { + return false; + } + + VoxelType voxel = volData->getVoxelAt(v3dPos); + if(voxel != 0) + { + return false; + } + + return true; +} + void TestAStarPathfinder::testExecute() { //The expected path @@ -97,8 +115,23 @@ void TestAStarPathfinder::testExecute() }; #endif //_MSC_VER - //Create an empty volume - RawVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 15, 15))); + const int32_t uVolumeSideLength = 16; + + //Create a volume + RawVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1))); + + //Clear the volume + for(int z = 0; z < uVolumeSideLength; z++) + { + for(int y = 0; y < uVolumeSideLength; y++) + { + for(int x = 0; x < uVolumeSideLength; x++) + { + uint8_t solidVoxel(0); + volData.setVoxelAt(x,y,z,solidVoxel); + } + } + } //Place a solid cube in the middle of it for(int z = 4; z < 12; z++) @@ -107,7 +140,7 @@ void TestAStarPathfinder::testExecute() { for(int x = 4; x < 12; x++) { - Material8 solidVoxel(1); + uint8_t solidVoxel(1); volData.setVoxelAt(x,y,z,solidVoxel); } } @@ -117,8 +150,8 @@ void TestAStarPathfinder::testExecute() std::list result; //Create an AStarPathfinder - AStarPathfinderParams params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result); - AStarPathfinder pathfinder(params); + AStarPathfinderParams params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result, 1.0f, 10000, TwentySixConnected, &testVoxelValidator); + AStarPathfinder pathfinder(params); //Execute the pathfinder. pathfinder.execute();