Removed redundant hasMaterial and hasDensity traits.

Changed AStar default validator.
This commit is contained in:
unknown 2012-02-20 12:51:54 +01:00
parent a20db7d7cf
commit 8d3a66a08c
7 changed files with 38 additions and 55 deletions

View File

@ -37,27 +37,6 @@ namespace PolyVox
return false;
}
if(VoxelTypeTraits<VoxelType>::hasDensity())
{
//and if their density is above the threshold.
VoxelType voxel = volData->getVoxelAt(v3dPos);
typename VoxelType::DensityType tThreshold = (VoxelTypeTraits<VoxelType>::minDensity() + VoxelTypeTraits<VoxelType>::maxDensity()) / 2;
if(voxel.getDensity() >= tThreshold)
{
return false;
}
}
if(VoxelTypeTraits<VoxelType>::hasMaterial())
{
//and if their material is not zero.
VoxelType voxel = volData->getVoxelAt(v3dPos);
if(voxel.getMaterial() != 0)
{
return false;
}
}
return true;
}

View File

@ -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<Density8::DensityType>::min(); }
static Density8::DensityType maxDensity() { return std::numeric_limits<Density8::DensityType>::max(); }
};

View File

@ -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; }
};

View File

@ -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; }
};

View File

@ -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; }
};

View File

@ -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

View File

@ -31,6 +31,24 @@ freely, subject to the following restrictions:
using namespace PolyVox;
template< template<typename> class VolumeType, typename VoxelType>
bool testVoxelValidator(const VolumeType<VoxelType>* 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<Material8> volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 15, 15)));
const int32_t uVolumeSideLength = 16;
//Create a volume
RawVolume<uint8_t> 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<Vector3DInt32> result;
//Create an AStarPathfinder
AStarPathfinderParams<RawVolume, Material8> params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result);
AStarPathfinder<RawVolume, Material8> pathfinder(params);
AStarPathfinderParams<RawVolume, uint8_t> params(&volData, Vector3DInt32(0,0,0), Vector3DInt32(15,15,15), &result, 1.0f, 10000, TwentySixConnected, &testVoxelValidator<RawVolume, uint8_t>);
AStarPathfinder<RawVolume, uint8_t> pathfinder(params);
//Execute the pathfinder.
pathfinder.execute();