Material/Density types are no longer exposed on voxels. This is because primitive types don't have them anyway.

This commit is contained in:
David Williams 2012-09-28 18:38:44 +02:00
parent 7189abb603
commit 2fbe418259
3 changed files with 21 additions and 56 deletions

View File

@ -47,19 +47,13 @@ namespace PolyVox
class Density class Density
{ {
public: 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()'.
typedef Type DensityType;
typedef int32_t MaterialType; //Shouldn't define this one...
/// Constructor /// Constructor
Density() : m_uDensity(0) {} Density() : m_uDensity(0) {}
/// Copy constructor /// Copy constructor
Density(DensityType uDensity) : m_uDensity(uDensity) {} Density(Type uDensity) : m_uDensity(uDensity) {}
// The LowPassFilter uses this to convert between normal and accumulated types.
/// Copy constructor with cast /// Copy constructor with cast
template <typename CastType> explicit Density(const Density<CastType>& density) throw() template <typename CastType> explicit Density(const Density<CastType>& density) throw()
{ {
@ -98,14 +92,14 @@ namespace PolyVox
return *this; return *this;
} }
DensityType getDensity() const throw() { return m_uDensity; } Type getDensity() const throw() { return m_uDensity; }
void setDensity(DensityType uDensity) { m_uDensity = uDensity; } void setDensity(Type uDensity) { m_uDensity = uDensity; }
static DensityType getMaxDensity() throw() { return (std::numeric_limits<DensityType>::max)(); } static Type getMaxDensity() throw() { return (std::numeric_limits<Type>::max)(); }
static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); } static Type getMinDensity() throw() { return (std::numeric_limits<Type>::min)(); }
private: private:
DensityType m_uDensity; Type m_uDensity;
}; };
template <typename Type> template <typename Type>

View File

@ -34,14 +34,7 @@ namespace PolyVox
{ {
///This class represents a voxel storing only a material. ///This class represents a voxel storing only a material.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// In order to perform a surface extraction on a LargeVolume, PolyVox needs the underlying /// Detailed description...
/// 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, although it only actually stores a material value.
/// For the getDensity() function it simply returns the smallest possible density if the
/// material is zero and the largest possible density if the material is not zero.
/// ///
/// \sa Density, MaterialDensityPair /// \sa Density, MaterialDensityPair
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -52,15 +45,8 @@ namespace PolyVox
class Material class Material
{ {
public: 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()'.
typedef int32_t DensityType;
typedef Type MaterialType;
Material() : m_uMaterial(0) {} Material() : m_uMaterial(0) {}
Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {} Material(Type uMaterial) : m_uMaterial(uMaterial) {}
bool operator==(const Material& rhs) const throw() bool operator==(const Material& rhs) const throw()
{ {
@ -72,11 +58,11 @@ namespace PolyVox
return !(*this == rhs); return !(*this == rhs);
} }
MaterialType getMaterial() const throw() { return m_uMaterial; } Type getMaterial() const throw() { return m_uMaterial; }
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
private: private:
MaterialType m_uMaterial; Type m_uMaterial;
}; };
typedef Material<uint8_t> Material8; typedef Material<uint8_t> Material8;

View File

@ -33,15 +33,7 @@ namespace PolyVox
{ {
/// This class represents a voxel storing only a density. /// This class represents a voxel storing only a density.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// In order to perform a surface extraction on a LargeVolume, PolyVox needs the underlying /// Detailed description...
/// 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 /// \sa Density, Material
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -49,13 +41,6 @@ namespace PolyVox
class MaterialDensityPair class MaterialDensityPair
{ {
public: 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()'.
typedef Type DensityType;
typedef Type MaterialType;
MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {} MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {}
MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {} MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {}
@ -87,18 +72,18 @@ namespace PolyVox
return *this; return *this;
} }
DensityType getDensity() const throw() { return m_uDensity; } Type getDensity() const throw() { return m_uDensity; }
MaterialType getMaterial() const throw() { return m_uMaterial; } Type getMaterial() const throw() { return m_uMaterial; }
void setDensity(DensityType uDensity) { m_uDensity = uDensity; } void setDensity(Type uDensity) { m_uDensity = uDensity; }
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; }
static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } static Type getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
static DensityType getMinDensity() throw() { return 0; } static Type getMinDensity() throw() { return 0; }
private: private:
MaterialType m_uMaterial : NoOfMaterialBits; Type m_uMaterial : NoOfMaterialBits;
DensityType m_uDensity : NoOfDensityBits; Type m_uDensity : NoOfDensityBits;
}; };
template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>