Refactoring of basic voxel types.

This commit is contained in:
p265186
2012-01-12 17:14:45 +01:00
parent 396e1fea30
commit 49b5fb3f67
13 changed files with 176 additions and 28 deletions

View File

@ -75,8 +75,8 @@ namespace PolyVox
void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density
static DensityType getMaxDensity() throw() { return (std::numeric_limits<DensityType>::max)(); }
static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); }
//static DensityType getMaxDensity() throw() { return (std::numeric_limits<DensityType>::max)(); }
//static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); }
static DensityType getThreshold() throw() { return (std::numeric_limits<DensityType>::max)() / 2; }
private:
@ -84,6 +84,24 @@ namespace PolyVox
};
typedef Density<uint8_t> Density8;
typedef Density<float> DensityFloat;
template<typename Type>
class VoxelTypeTraits< Density<Type> >
{
public:
const static Type MinDensity = 0;
const static Type MaxDensity = 255;
};
template<>
class VoxelTypeTraits< DensityFloat >
{
public:
const static float MinDensity = -1000000.0f;
const static float MaxDensity = 1000000.0f;
};
}
#endif //__PolyVox_Density_H__

View File

@ -74,11 +74,13 @@ namespace PolyVox
//We don't actually have a density, so make one up based on the material.
if(m_uMaterial == 0)
{
return getMinDensity();
//return getMinDensity();
return 0;
}
else
{
return getMaxDensity();
//return getMaxDensity();
return 2;
}
}
@ -87,8 +89,8 @@ namespace PolyVox
void setDensity(DensityType /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
static DensityType getMaxDensity() throw() { return 2; }
static DensityType getMinDensity() throw() { return 0; }
//static DensityType getMaxDensity() throw() { return 2; }
//static DensityType getMinDensity() throw() { return 0; }
static DensityType getThreshold() throw() { return 1; }
private:

View File

@ -74,8 +74,8 @@ namespace PolyVox
void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
static DensityType getMinDensity() throw() { return 0; }
//static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
//static DensityType getMinDensity() throw() { return 0; }
static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);}
private:
@ -85,6 +85,14 @@ namespace PolyVox
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class VoxelTypeTraits< MaterialDensityPair<Type, NoOfDensityBits, NoOfMaterialBits> >
{
public:
const static Type MinDensity = 0;
const static Type MaxDensity = (0x01 << NoOfDensityBits) - 1;
};
}
#endif

View File

@ -52,6 +52,16 @@ namespace PolyVox
void setDensity(DensityType uDensity) { assert(false); }
void setMaterial(MaterialType /*uMaterial*/) { assert(false); }
};
// Syntax for templatised traits classes: http://stackoverflow.com/q/8606302/849083
template <typename Type>
class VoxelTypeTraits
{
public:
const static typename Type::DensityType MinDensity = 0;
const static typename Type::DensityType MaxDensity = 0;
};
}
#endif //__PolyVox_Voxel_H__