Added Material8 and Density8 classes, and Thermite now uses the Material8 one.

This commit is contained in:
David Williams
2010-11-04 23:12:31 +00:00
parent 0b410eaed3
commit 625bd14187
7 changed files with 241 additions and 125 deletions

View File

@ -29,28 +29,60 @@ freely, subject to the following restrictions:
namespace PolyVox
{
///This class represents a voxel storing only a density.
////////////////////////////////////////////////////////////////////////////////
/// In order to perform a surface extraction on a Volume, PolyVox needs the underlying
/// voxel type to provide both getDensity() and getMaterial() functions. The getDensity()
/// function is used to determine if a voxel is 'solid', and if it is then the getMaterial()
/// funtion is used to determine what material should be assigned to the resulting mesh.
///
/// This class meets these requirements, and does so by storing and returning both a material
/// and a density value. Via the template parameters it is possible to control how much
/// precision is given to each. For example, if you create a class with 8 bits of storage,
/// you might choose to allocate 6 bits for the density and 2 bits for the material.
///
/// \sa Density, Material
////////////////////////////////////////////////////////////////////////////////
template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
class MaterialDensityPair
{
public:
MaterialDensityPair();
MaterialDensityPair(Type uMaterial, Type uDensity);
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
//Why are both of these needed?!
bool operator==(const MaterialDensityPair& rhs) const throw();
bool operator!=(const MaterialDensityPair& rhs) const throw();
bool operator==(const MaterialDensityPair& rhs) const throw()
{
return (m_uMaterial == rhs.m_uMaterial) && (m_uDensity == rhs.m_uDensity);
};
bool operator<(const MaterialDensityPair& rhs) const throw();
bool operator!=(const MaterialDensityPair& rhs) const throw()
{
return !(*this == rhs);
}
Type getDensity() const throw();
Type getMaterial() const throw();
bool operator<(const MaterialDensityPair& rhs) const throw()
{
if (m_uMaterial < rhs.m_uMaterial)
return true;
if (rhs.m_uMaterial < m_uMaterial)
return false;
if (m_uDensity < rhs.m_uDensity)
return true;
if (rhs.m_uDensity < m_uDensity)
return false;
void setDensity(Type uDensity);
void setMaterial(Type uMaterial);
return false;
}
static Type getMaxDensity() throw();
static Type getMinDensity() throw();
static Type getThreshold() throw();
Type getDensity() const throw() { return m_uDensity; }
Type getMaterial() const throw() { return m_uMaterial; }
void setDensity(Type uDensity) { m_uDensity = uDensity; }
void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
static Type getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
static Type getMinDensity() throw() { return 0; }
static Type getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);}
private:
Type m_uMaterial : NoOfMaterialBits;
@ -60,6 +92,4 @@ namespace PolyVox
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
}
#include "MaterialDensityPair.inl"
#endif