Work on refactoring basic voxel types.
Also, this will probably cause a compile error on Linux but I'm committing anyway so I remember to investigate it...
This commit is contained in:
@ -83,23 +83,70 @@ namespace PolyVox
|
||||
DensityType m_uDensity;
|
||||
};
|
||||
|
||||
typedef Density<uint8_t> Density8;
|
||||
// These are the predefined density types. The 8-bit types are sufficient for many purposes (including
|
||||
// most games) but 16-bit and float types do have uses particularly in medical/scientific visualisation.
|
||||
typedef Density<int8_t> DensityI8;
|
||||
typedef Density<uint8_t> DensityU8;
|
||||
typedef Density<int16_t> DensityI16;
|
||||
typedef Density<uint16_t> DensityU16;
|
||||
typedef Density<float> DensityFloat;
|
||||
typedef Density<double> DensityDouble;
|
||||
|
||||
// These types are here for backwards compatibility but they are a little ambiguous as the name doesn't indicate
|
||||
// whether the values are signed. We would recommend using one of the 8 or 16 bit predefined types above instead.
|
||||
typedef Density<uint8_t> Density8;
|
||||
typedef Density<uint16_t> Density16;
|
||||
|
||||
template<typename Type>
|
||||
class VoxelTypeTraits< Density<Type> >
|
||||
// We have to define all the min and max values explicitly here rather than using std::numeric_limits because we need
|
||||
// compile time constants. The new 'constexpr' would help here but it's not supported by all compilers at the moment.
|
||||
template<>
|
||||
class VoxelTypeTraits< Density<int8_t> >
|
||||
{
|
||||
public:
|
||||
const static Type MinDensity = 0;
|
||||
const static Type MaxDensity = 255;
|
||||
const static int8_t MinDensity = -127;
|
||||
const static int8_t MaxDensity = 127;
|
||||
};
|
||||
|
||||
template<>
|
||||
class VoxelTypeTraits< Density<uint8_t> >
|
||||
{
|
||||
public:
|
||||
const static uint8_t MinDensity = 0;
|
||||
const static uint8_t MaxDensity = 255;
|
||||
};
|
||||
|
||||
template<>
|
||||
class VoxelTypeTraits< Density<int16_t> >
|
||||
{
|
||||
public:
|
||||
const static int16_t MinDensity = -32767;
|
||||
const static int16_t MaxDensity = 32767;
|
||||
};
|
||||
|
||||
template<>
|
||||
class VoxelTypeTraits< Density<uint16_t> >
|
||||
{
|
||||
public:
|
||||
const static uint16_t MinDensity = 0;
|
||||
const static uint16_t MaxDensity = 65535;
|
||||
};
|
||||
|
||||
//Constants for float defined in .cpp file as they are not integers.
|
||||
template<>
|
||||
class VoxelTypeTraits< DensityFloat >
|
||||
class VoxelTypeTraits< Density<float> >
|
||||
{
|
||||
public:
|
||||
const static float MinDensity = -1000000.0f;
|
||||
const static float MaxDensity = 1000000.0f;
|
||||
const static float MinDensity;
|
||||
const static float MaxDensity;
|
||||
};
|
||||
|
||||
//Constants for double defined in .cpp file as they are not integers.
|
||||
template<>
|
||||
class VoxelTypeTraits< Density<double> >
|
||||
{
|
||||
public:
|
||||
const static double MinDensity;
|
||||
const static double MaxDensity;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ namespace PolyVox
|
||||
class Voxel
|
||||
{
|
||||
public:
|
||||
//We expose DensityType and MaterialType in this way so that, when code is
|
||||
//templatised on voxel type, it can determine the underlying storage type
|
||||
//using code such as 'VoxelType::DensityType value = voxel.getDensity()'
|
||||
//or 'VoxelType::MaterialType value = voxel.getMaterial()'.
|
||||
// We expose DensityType and MaterialType in this way so that, when code is
|
||||
// templatised on voxel type, it can determine the underlying storage type
|
||||
// using code such as 'VoxelType::DensityType value = voxel.getDensity()'
|
||||
// or 'VoxelType::MaterialType value = voxel.getMaterial()'.
|
||||
typedef DenType DensityType;
|
||||
typedef MatType MaterialType;
|
||||
|
||||
@ -53,6 +53,16 @@ namespace PolyVox
|
||||
void setMaterial(MaterialType /*uMaterial*/) { assert(false); }
|
||||
};
|
||||
|
||||
// Various properties of the voxel types can be expressed via types traits, similar to the way std::numeric_limits is implemented.
|
||||
// This has some advantages compared to storing the properties directly in the voxel class. For example, by using traits it is possible
|
||||
// to also apply these properties to primative types which might be desirable (the Volume classes do accept primative types as template
|
||||
// parameters). Also, properties such as MinDensity and MaxDensity would be difficult to represent though class members because they
|
||||
// depend ont the type (float has a very different range from int8_t for example).
|
||||
//
|
||||
// The properties are currently exposed as constants because we need access to them at compile time. Ideally we would like to make them
|
||||
// functions flagged with 'constexpr' as we could then make use of the max() and min() functions in std::numric_limits, but this is not
|
||||
// widely supported by compilers yet. We may change this in the future.
|
||||
//
|
||||
// Syntax for templatised traits classes: http://stackoverflow.com/q/8606302/849083
|
||||
template <typename Type>
|
||||
class VoxelTypeTraits
|
||||
|
Reference in New Issue
Block a user