From b972a2ceaf790d9b625f6f5d1e0a696f4f4d6eef Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 30 Nov 2011 22:50:52 +0000 Subject: [PATCH] Exposed DensityType and MaterialType on voxels. --- .../PolyVoxCore/include/PolyVoxCore/Density.h | 15 ++++++++--- .../include/PolyVoxCore/Material.h | 19 +++++++++----- .../include/PolyVoxCore/MaterialDensityPair.h | 25 ++++++++++++------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 82aab7b4..308310bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -39,14 +39,21 @@ namespace PolyVox /// 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 density value. - /// For the getMaterial() function it just returens a constant value of '1'. + /// For the getMaterial() function it just returns a constant value of '1'. /// /// \sa Material, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// - template + template class Density { 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 uint8_t MaterialType; + Density() : m_uDensity(0) {} Density(DensityType uDensity) : m_uDensity(uDensity) {} @@ -61,10 +68,10 @@ namespace PolyVox } DensityType getDensity() const throw() { return m_uDensity; } - uint32_t getMaterial() const throw() { return 1; } + MaterialType getMaterial() const throw() { return 1; } void setDensity(DensityType uDensity) { m_uDensity = uDensity; } - void setMaterial(uint32_t uMaterial) { assert(false); } //Cannot set material on voxel of type Density + void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density static DensityType getMaxDensity() throw() { return (std::numeric_limits::max)(); } static DensityType getMinDensity() throw() { return (std::numeric_limits::min)(); } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Material.h b/library/PolyVoxCore/include/PolyVoxCore/Material.h index 09d978e9..390dfd71 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Material.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Material.h @@ -43,10 +43,17 @@ namespace PolyVox /// /// \sa Density, MaterialDensityPair //////////////////////////////////////////////////////////////////////////////// - template + template class Material { 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 uint8_t DensityType; + typedef Type MaterialType; + Material() : m_uMaterial(0) {} Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {} @@ -60,7 +67,7 @@ namespace PolyVox return !(*this == rhs); } - uint32_t getDensity() const throw() + DensityType getDensity() const throw() { //We don't actually have a density, so make one up based on the material. if(m_uMaterial == 0) @@ -75,12 +82,12 @@ namespace PolyVox MaterialType getMaterial() const throw() { return m_uMaterial; } - void setDensity(uint32_t /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material + void setDensity(DensityType /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } - static uint32_t getMaxDensity() throw() { return 2; } - static uint32_t getMinDensity() throw() { return 0; } - static uint32_t getThreshold() throw() { return 1; } + static DensityType getMaxDensity() throw() { return 2; } + static DensityType getMinDensity() throw() { return 0; } + static DensityType getThreshold() throw() { return 1; } private: MaterialType m_uMaterial; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 1bb3a31f..663eded5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -46,6 +46,13 @@ namespace PolyVox class MaterialDensityPair { 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(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {} @@ -59,19 +66,19 @@ namespace PolyVox return !(*this == rhs); } - Type getDensity() const throw() { return m_uDensity; } - Type getMaterial() const throw() { return m_uMaterial; } + DensityType getDensity() const throw() { return m_uDensity; } + MaterialType getMaterial() const throw() { return m_uMaterial; } - void setDensity(Type uDensity) { m_uDensity = uDensity; } - void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } + void setDensity(DensityType uDensity) { m_uDensity = uDensity; } + void setMaterial(MaterialType 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);} + static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } + static DensityType getMinDensity() throw() { return 0; } + static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);} private: - Type m_uMaterial : NoOfMaterialBits; - Type m_uDensity : NoOfDensityBits; + MaterialType m_uMaterial : NoOfMaterialBits; + DensityType m_uDensity : NoOfDensityBits; }; typedef MaterialDensityPair MaterialDensityPair44;