Replaced constants with functions for type traits.

This commit is contained in:
unknown 2012-02-06 17:51:37 +01:00
parent 1ab1d9bed3
commit c483b44a41
18 changed files with 125 additions and 292 deletions

View File

@ -54,7 +54,7 @@ void createSphereInVolume(SimpleVolume<MaterialDensityPair44>& volData, float fR
if(fDistToCenter <= fRadius) if(fDistToCenter <= fRadius)
{ {
//Our new density value //Our new density value
uint8_t uDensity = VoxelTypeTraits<MaterialDensityPair44>::MaxDensity; uint8_t uDensity = VoxelTypeTraits<MaterialDensityPair44>::maxDensity();
//Get the old voxel //Get the old voxel
MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);

View File

@ -48,7 +48,7 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRa
//then we make it solid, otherwise we make it empty space. //then we make it solid, otherwise we make it empty space.
if(fDistToCenter <= fRadius) if(fDistToCenter <= fRadius)
{ {
volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? VoxelTypeTraits<MaterialDensityPair44>::MaxDensity : VoxelTypeTraits<MaterialDensityPair44>::MinDensity)); volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? VoxelTypeTraits<MaterialDensityPair44>::maxDensity() : VoxelTypeTraits<MaterialDensityPair44>::minDensity()));
} }
} }
} }
@ -57,8 +57,8 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRa
void createCubeInVolume(LargeVolume<MaterialDensityPair44>& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue) void createCubeInVolume(LargeVolume<MaterialDensityPair44>& volData, Vector3DInt32 lowerCorner, Vector3DInt32 upperCorner, uint8_t uValue)
{ {
int maxDen = VoxelTypeTraits<MaterialDensityPair44>::MaxDensity; int maxDen = VoxelTypeTraits<MaterialDensityPair44>::maxDensity();
int minDen = VoxelTypeTraits<MaterialDensityPair44>::MinDensity; int minDen = VoxelTypeTraits<MaterialDensityPair44>::minDensity();
//This three-level for loop iterates over every voxel between the specified corners //This three-level for loop iterates over every voxel between the specified corners
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++) for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
{ {

View File

@ -97,9 +97,9 @@ int main(int argc, char *argv[])
createCubeInVolume(volData, Vector3DInt32(midPos+1, minPos, midPos+1), Vector3DInt32(maxPos, midPos-1, maxPos), 0); createCubeInVolume(volData, Vector3DInt32(midPos+1, minPos, midPos+1), Vector3DInt32(maxPos, midPos-1, maxPos), 0);
createCubeInVolume(volData, Vector3DInt32(minPos, midPos+1, midPos+1), Vector3DInt32(midPos-1, maxPos, maxPos), 0); createCubeInVolume(volData, Vector3DInt32(minPos, midPos+1, midPos+1), Vector3DInt32(midPos-1, maxPos, maxPos), 0);
createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); createCubeInVolume(volData, Vector3DInt32(1, midPos-10, midPos-10), Vector3DInt32(maxPos-1, midPos+10, midPos+10), VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); createCubeInVolume(volData, Vector3DInt32(midPos-10, 1, midPos-10), Vector3DInt32(midPos+10, maxPos-1, midPos+10), VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); createCubeInVolume(volData, Vector3DInt32(midPos-10, midPos-10 ,1), Vector3DInt32(midPos+10, midPos+10, maxPos-1), VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
//Smooth part of the volume //Smooth part of the volume
RawVolume<MaterialDensityPair44> tempVolume(PolyVox::Region(0,0,0,128, 128, 128)); RawVolume<MaterialDensityPair44> tempVolume(PolyVox::Region(0,0,0,128, 128, 128));

View File

@ -50,7 +50,7 @@ void createPerlinVolumeSlow(LargeVolume<MaterialDensityPair44>& volData)
perlinVal += 1.0f; perlinVal += 1.0f;
perlinVal *= 0.5f; perlinVal *= 0.5f;
perlinVal *= VoxelTypeTraits<MaterialDensityPair44>::MaxDensity; perlinVal *= VoxelTypeTraits<MaterialDensityPair44>::maxDensity();
MaterialDensityPair44 voxel; MaterialDensityPair44 voxel;
@ -60,12 +60,12 @@ void createPerlinVolumeSlow(LargeVolume<MaterialDensityPair44>& volData)
/*if(perlinVal < 0.0f) /*if(perlinVal < 0.0f)
{ {
voxel.setMaterial(245); voxel.setMaterial(245);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
} }
else else
{ {
voxel.setMaterial(0); voxel.setMaterial(0);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MinDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::minDensity());
}*/ }*/
volData.setVoxelAt(x, y, z, voxel); volData.setVoxelAt(x, y, z, voxel);
@ -105,12 +105,12 @@ void createPerlinVolumeSlow(LargeVolume<MaterialDensityPair44>& volData)
if(perlinVal < 0.0f) if(perlinVal < 0.0f)
{ {
voxel.setMaterial(245); voxel.setMaterial(245);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
} }
else else
{ {
voxel.setMaterial(0); voxel.setMaterial(0);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MinDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::minDensity());
} }
volData.setVoxelAt(x, y, z, voxel); volData.setVoxelAt(x, y, z, voxel);
@ -143,12 +143,12 @@ void createPerlinTerrain(LargeVolume<MaterialDensityPair44>& volData)
if(z < perlinVal) if(z < perlinVal)
{ {
voxel.setMaterial(245); voxel.setMaterial(245);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
} }
else else
{ {
voxel.setMaterial(0); voxel.setMaterial(0);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MinDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::minDensity());
} }
volData.setVoxelAt(x, y, z, voxel); volData.setVoxelAt(x, y, z, voxel);
@ -181,7 +181,7 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, Vector3DF
if(fDistToCenter <= fRadius) if(fDistToCenter <= fRadius)
{ {
//Our new density value //Our new density value
uint8_t uDensity = VoxelTypeTraits<MaterialDensityPair44>::MaxDensity; uint8_t uDensity = VoxelTypeTraits<MaterialDensityPair44>::maxDensity();
//Get the old voxel //Get the old voxel
MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z); MaterialDensityPair44 voxel = volData.getVoxelAt(x,y,z);
@ -219,17 +219,17 @@ void load(const ConstVolumeProxy<MaterialDensityPair44>& volume, const PolyVox::
if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) { if((x-xpos)*(x-xpos) + (z-zpos)*(z-zpos) < 200) {
// tunnel // tunnel
voxel.setMaterial(0); voxel.setMaterial(0);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MinDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::minDensity());
} else { } else {
// solid // solid
voxel.setMaterial(245); voxel.setMaterial(245);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MaxDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::maxDensity());
} }
} }
else else
{ {
voxel.setMaterial(0); voxel.setMaterial(0);
voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::MinDensity); voxel.setDensity(VoxelTypeTraits<MaterialDensityPair44>::minDensity());
} }
volume.setVoxelAt(x, y, z, voxel); volume.setVoxelAt(x, y, z, voxel);

View File

@ -55,8 +55,8 @@ void createSphereInVolume(SimpleVolume<Density8>& volData, float fRadius)
if(fDistToCenter <= fRadius) if(fDistToCenter <= fRadius)
{ {
//Our new density value //Our new density value
//uint8_t uDensity = Density8::getMaxDensity(); //uint8_t uDensity = Density8::getmaxDensity()();
uint8_t uDensity = VoxelTypeTraits<Density8>::MaxDensity; uint8_t uDensity = VoxelTypeTraits<Density8>::maxDensity();
//Get the old voxel //Get the old voxel
Density8 voxel = volData.getVoxelAt(x,y,z); Density8 voxel = volData.getVoxelAt(x,y,z);

View File

@ -6,16 +6,12 @@ PROJECT(PolyVoxCore)
SET(CORE_SRC_FILES SET(CORE_SRC_FILES
source/ArraySizes.cpp source/ArraySizes.cpp
source/AStarPathfinder.cpp source/AStarPathfinder.cpp
source/Density.cpp
source/GradientEstimators.cpp source/GradientEstimators.cpp
source/Log.cpp source/Log.cpp
source/Material.cpp
source/MaterialDensityPair.cpp
source/MeshDecimator.cpp source/MeshDecimator.cpp
source/Region.cpp source/Region.cpp
source/SimpleInterface.cpp source/SimpleInterface.cpp
source/VertexTypes.cpp source/VertexTypes.cpp
source/Voxel.cpp
source/VoxelFilters.cpp source/VoxelFilters.cpp
) )

View File

@ -37,18 +37,18 @@ namespace PolyVox
return false; return false;
} }
if(VoxelTypeTraits<VoxelType>::HasDensity) if(VoxelTypeTraits<VoxelType>::hasDensity())
{ {
//and if their density is above the threshold. //and if their density is above the threshold.
VoxelType voxel = volData->getVoxelAt(v3dPos); VoxelType voxel = volData->getVoxelAt(v3dPos);
VoxelType::DensityType tThreshold = (VoxelTypeTraits<VoxelType>::MinDensity + VoxelTypeTraits<VoxelType>::MaxDensity) / 2; VoxelType::DensityType tThreshold = (VoxelTypeTraits<VoxelType>::minDensity() + VoxelTypeTraits<VoxelType>::maxDensity()) / 2;
if(voxel.getDensity() >= tThreshold) if(voxel.getDensity() >= tThreshold)
{ {
return false; return false;
} }
} }
if(VoxelTypeTraits<VoxelType>::HasMaterial) if(VoxelTypeTraits<VoxelType>::hasMaterial())
{ {
//and if their material is not zero. //and if their material is not zero.
VoxelType voxel = volData->getVoxelAt(v3dPos); VoxelType voxel = volData->getVoxelAt(v3dPos);

View File

@ -31,6 +31,9 @@ freely, subject to the following restrictions:
#include <cassert> #include <cassert>
#include <limits> #include <limits>
#undef min
#undef max
namespace PolyVox namespace PolyVox
{ {
///This class represents a voxel storing only a density. ///This class represents a voxel storing only a density.
@ -45,8 +48,11 @@ namespace PolyVox
/// ///
/// \sa Material, MaterialDensityPair /// \sa Material, MaterialDensityPair
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// int32_t template parameter is a dummy, required as the compiler expects to be able to declare an
// instance of VoxelType::MaterialType without knowing that VoxelType doesn't actually have a material.
template <typename Type> template <typename Type>
class Density : public Voxel<Type, uint8_t> class Density : public Voxel<Type, int32_t>
{ {
public: public:
//We expose DensityType and MaterialType in this way so that, when code is //We expose DensityType and MaterialType in this way so that, when code is
@ -54,7 +60,7 @@ namespace PolyVox
//using code such as 'VoxelType::DensityType value = voxel.getDensity()' //using code such as 'VoxelType::DensityType value = voxel.getDensity()'
//or 'VoxelType::MaterialType value = voxel.getMaterial()'. //or 'VoxelType::MaterialType value = voxel.getMaterial()'.
typedef Type DensityType; typedef Type DensityType;
typedef uint8_t MaterialType; //Shouldn't define this one... typedef int32_t MaterialType; //Shouldn't define this one...
Density() : m_uDensity(0) {} Density() : m_uDensity(0) {}
Density(DensityType uDensity) : m_uDensity(uDensity) {} Density(DensityType uDensity) : m_uDensity(uDensity) {}
@ -75,8 +81,8 @@ namespace PolyVox
void setDensity(DensityType uDensity) { m_uDensity = uDensity; } void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
//void setMaterial(MaterialType /*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<DensityType>::max)(); } //static DensityType getmaxDensity()() throw() { return (std::numeric_limits<DensityType>::max)(); }
//static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); } //static DensityType getminDensity()() throw() { return (std::numeric_limits<DensityType>::min)(); }
static DensityType getThreshold() throw() { return (std::numeric_limits<DensityType>::max)() / 2; } static DensityType getThreshold() throw() { return (std::numeric_limits<DensityType>::max)() / 2; }
private: private:
@ -103,60 +109,60 @@ namespace PolyVox
class VoxelTypeTraits< DensityI8 > class VoxelTypeTraits< DensityI8 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static DensityI8::DensityType MinDensity; static DensityI8::DensityType minDensity() { return -std::numeric_limits<DensityI8::DensityType>::max(); }
const static DensityI8::DensityType MaxDensity; static DensityI8::DensityType maxDensity() { return std::numeric_limits<DensityI8::DensityType>::max(); }
}; };
template<> template<>
class VoxelTypeTraits< DensityU8 > class VoxelTypeTraits< DensityU8 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static DensityU8::DensityType MinDensity; static DensityU8::DensityType minDensity() { return std::numeric_limits<DensityU8::DensityType>::min(); }
const static DensityU8::DensityType MaxDensity; static DensityU8::DensityType maxDensity() { return std::numeric_limits<DensityU8::DensityType>::max(); }
}; };
template<> template<>
class VoxelTypeTraits< DensityI16 > class VoxelTypeTraits< DensityI16 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static DensityI16::DensityType MinDensity; static DensityI16::DensityType minDensity() { return -std::numeric_limits<DensityI16::DensityType>::max(); }
const static DensityI16::DensityType MaxDensity; static DensityI16::DensityType maxDensity() { return std::numeric_limits<DensityI16::DensityType>::max(); }
}; };
template<> template<>
class VoxelTypeTraits< DensityU16 > class VoxelTypeTraits< DensityU16 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static DensityU16::DensityType MinDensity; static DensityU16::DensityType minDensity() { return std::numeric_limits<DensityU16::DensityType>::min(); }
const static DensityU16::DensityType MaxDensity; static DensityU16::DensityType maxDensity() { return std::numeric_limits<DensityU16::DensityType>::max(); }
}; };
template<> template<>
class VoxelTypeTraits< DensityFloat > class VoxelTypeTraits< DensityFloat >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static DensityFloat::DensityType MinDensity; static DensityFloat::DensityType minDensity() { return -std::numeric_limits<DensityFloat::DensityType>::max(); }
const static DensityFloat::DensityType MaxDensity; static DensityFloat::DensityType maxDensity() { return std::numeric_limits<DensityFloat::DensityType>::max(); }
}; };
template<> template<>
class VoxelTypeTraits< DensityDouble > class VoxelTypeTraits< DensityDouble >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static DensityDouble::DensityType MinDensity; static DensityDouble::DensityType minDensity() { return -std::numeric_limits<DensityDouble::DensityType>::max(); }
const static DensityDouble::DensityType MaxDensity; static DensityDouble::DensityType maxDensity() { return std::numeric_limits<DensityDouble::DensityType>::max(); }
}; };
} }

View File

@ -45,15 +45,18 @@ namespace PolyVox
/// ///
/// \sa Density, MaterialDensityPair /// \sa Density, MaterialDensityPair
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// int32_t template parameter is a dummy, required as the compiler expects to be able to declare an
// instance of VoxelType::DensityType without knowing that VoxelType doesn't actually have a density.
template <typename Type> template <typename Type>
class Material : public Voxel<uint8_t, Type> class Material : public Voxel<int32_t, Type>
{ {
public: public:
//We expose DensityType and MaterialType in this way so that, when code is //We expose DensityType and MaterialType in this way so that, when code is
//templatised on voxel type, it can determine the underlying storage type //templatised on voxel type, it can determine the underlying storage type
//using code such as 'VoxelType::DensityType value = voxel.getDensity()' //using code such as 'VoxelType::DensityType value = voxel.getDensity()'
//or 'VoxelType::MaterialType value = voxel.getMaterial()'. //or 'VoxelType::MaterialType value = voxel.getMaterial()'.
typedef uint8_t DensityType; //Shouldn't define this one... typedef int32_t DensityType;
typedef Type MaterialType; typedef Type MaterialType;
Material() : m_uMaterial(0) {} Material() : m_uMaterial(0) {}
@ -74,12 +77,12 @@ namespace PolyVox
//We don't actually have a density, so make one up based on the material. //We don't actually have a density, so make one up based on the material.
if(m_uMaterial == 0) if(m_uMaterial == 0)
{ {
//return getMinDensity(); //return getminDensity()();
return 0; return 0;
} }
else else
{ {
//return getMaxDensity(); //return getmaxDensity()();
return 2; return 2;
} }
} }
@ -89,8 +92,8 @@ namespace PolyVox
void setDensity(DensityType /*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; } void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
//static DensityType getMaxDensity() throw() { return 2; } //static DensityType getmaxDensity()() throw() { return 2; }
//static DensityType getMinDensity() throw() { return 0; } //static DensityType getminDensity()() throw() { return 0; }
static DensityType getThreshold() throw() { return 1; } static DensityType getThreshold() throw() { return 1; }
private: private:
@ -111,30 +114,30 @@ namespace PolyVox
class VoxelTypeTraits< MaterialU8 > class VoxelTypeTraits< MaterialU8 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return false; }
const static bool HasMaterial; static bool hasMaterial() { return true; }
const static MaterialU8::DensityType MinDensity; static int minDensity() { assert(false); return 0; }
const static MaterialU8::DensityType MaxDensity; static int maxDensity() { assert(false); return 0; }
}; };
template<> template<>
class VoxelTypeTraits< MaterialU16 > class VoxelTypeTraits< MaterialU16 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return false; }
const static bool HasMaterial; static bool hasMaterial() { return true; }
const static MaterialU16::DensityType MinDensity; static int minDensity() { assert(false); return 0; }
const static MaterialU16::DensityType MaxDensity; static int maxDensity() { assert(false); return 0; }
}; };
template<> template<>
class VoxelTypeTraits< MaterialU32 > class VoxelTypeTraits< MaterialU32 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return false; }
const static bool HasMaterial; static bool hasMaterial() { return true; }
const static MaterialU32::DensityType MinDensity; static int minDensity() { assert(false); return 0; }
const static MaterialU32::DensityType MaxDensity; static int maxDensity() { assert(false); return 0; }
}; };
} }

View File

@ -74,8 +74,8 @@ namespace PolyVox
void setDensity(DensityType uDensity) { m_uDensity = uDensity; } void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
//static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } //static DensityType getmaxDensity()() throw() { return (0x01 << NoOfDensityBits) - 1; }
//static DensityType getMinDensity() throw() { return 0; } //static DensityType getminDensity()() throw() { return 0; }
static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);} static DensityType getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);}
private: private:
@ -90,20 +90,20 @@ namespace PolyVox
class VoxelTypeTraits< MaterialDensityPair44 > class VoxelTypeTraits< MaterialDensityPair44 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return true; }
const static MaterialDensityPair44::DensityType MinDensity; static MaterialDensityPair44::DensityType minDensity() { return 0; }
const static MaterialDensityPair44::DensityType MaxDensity; static MaterialDensityPair44::DensityType maxDensity() { return 15; }
}; };
template<> template<>
class VoxelTypeTraits< MaterialDensityPair88 > class VoxelTypeTraits< MaterialDensityPair88 >
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return true; }
const static bool HasMaterial; static bool hasMaterial() { return true; }
const static MaterialDensityPair88::DensityType MinDensity; static MaterialDensityPair88::DensityType minDensity() { return 0; }
const static MaterialDensityPair88::DensityType MaxDensity; static MaterialDensityPair88::DensityType maxDensity() { return 255; }
}; };
} }

View File

@ -36,7 +36,7 @@ namespace PolyVox
class SurfaceExtractor class SurfaceExtractor
{ {
public: public:
SurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, typename VoxelType::DensityType tThreshold = (VoxelTypeTraits<VoxelType>::MinDensity + VoxelTypeTraits<VoxelType>::MaxDensity) / 2); SurfaceExtractor(VolumeType<VoxelType>* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, typename VoxelType::DensityType tThreshold = (VoxelTypeTraits<VoxelType>::minDensity() + VoxelTypeTraits<VoxelType>::maxDensity()) / 2);
void execute(); void execute();

View File

@ -433,7 +433,7 @@ namespace PolyVox
const VoxelType v100 = m_sampVolume.getVoxel(); const VoxelType v100 = m_sampVolume.getVoxel();
const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume); const Vector3DFloat n100 = computeCentralDifferenceGradient(m_sampVolume);
//float fInterp = static_cast<float>(v100.getDensity() - VoxelType::getMinDensity()) / static_cast<float>(VoxelType::getMaxDensity() - VoxelType::getMinDensity()); //float fInterp = static_cast<float>(v100.getDensity() - VoxelType::getminDensity()()) / static_cast<float>(VoxelType::getmaxDensity()() - VoxelType::getminDensity()());
float fInterp = static_cast<float>(m_tThreshold - v000.getDensity()) / static_cast<float>(v100.getDensity() - v000.getDensity()); float fInterp = static_cast<float>(m_tThreshold - v000.getDensity()) / static_cast<float>(v100.getDensity() - v000.getDensity());
//fInterp = 0.5f; //fInterp = 0.5f;
@ -447,7 +447,7 @@ namespace PolyVox
//material IDs does not make sense). We take the largest, so that if we are working on a material-only //material IDs does not make sense). We take the largest, so that if we are working on a material-only
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
uint32_t uMaterial = 0; uint32_t uMaterial = 0;
if(VoxelTypeTraits<VoxelType>::HasMaterial) if(VoxelTypeTraits<VoxelType>::hasMaterial())
{ {
uMaterial = (std::max)(v000.getMaterial(), v100.getMaterial()); uMaterial = (std::max)(v000.getMaterial(), v100.getMaterial());
} }
@ -477,7 +477,7 @@ namespace PolyVox
//material IDs does not make sense). We take the largest, so that if we are working on a material-only //material IDs does not make sense). We take the largest, so that if we are working on a material-only
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
uint32_t uMaterial = 0; uint32_t uMaterial = 0;
if(VoxelTypeTraits<VoxelType>::HasMaterial) if(VoxelTypeTraits<VoxelType>::hasMaterial())
{ {
uMaterial = (std::max)(v000.getMaterial(), v010.getMaterial()); uMaterial = (std::max)(v000.getMaterial(), v010.getMaterial());
} }
@ -507,7 +507,7 @@ namespace PolyVox
//material IDs does not make sense). We take the largest, so that if we are working on a material-only //material IDs does not make sense). We take the largest, so that if we are working on a material-only
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. //volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
uint32_t uMaterial = 0; uint32_t uMaterial = 0;
if(VoxelTypeTraits<VoxelType>::HasMaterial) if(VoxelTypeTraits<VoxelType>::hasMaterial())
{ {
uMaterial = (std::max)(v000.getMaterial(), v001.getMaterial()); uMaterial = (std::max)(v000.getMaterial(), v001.getMaterial());
} }

View File

@ -56,7 +56,7 @@ namespace PolyVox
// Various properties of the voxel types can be expressed via types traits, similar to the way std::numeric_limits is implemented. // 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 // 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 // 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 // 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). // 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 // The properties are currently exposed as constants because we need access to them at compile time. Ideally we would like to make them
@ -68,10 +68,15 @@ namespace PolyVox
class VoxelTypeTraits class VoxelTypeTraits
{ {
public: public:
const static bool HasDensity; static bool hasDensity() { return false; }
const static bool HasMaterial; static bool hasMaterial() { return false; }
const static typename Type::DensityType MinDensity;
const static typename Type::DensityType MaxDensity; // These default implementations return an int32_t rather than void so that the result can be
// assigned to a variable for all voxel types (even those without density coponents). Calls
// to these functions should be protected by calls to hasDensity(), but the compiler still
// needs to ensure the assignment is compilable even if hasDensity() returns false.
static int32_t minDensity() { assert(false); return 0; }
static int32_t maxDensity() { assert(false); return 0; }
}; };
} }

View File

@ -1,59 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Density.h"
#include <cfloat> //Can't use <limits> as we need compile time constants.
namespace PolyVox
{
const bool VoxelTypeTraits< DensityI8 >::HasDensity = true;
const bool VoxelTypeTraits< DensityI8 >::HasMaterial = false;
const DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MinDensity = -127;
const DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MaxDensity = 127;
const bool VoxelTypeTraits< DensityU8 >::HasDensity = true;
const bool VoxelTypeTraits< DensityU8 >::HasMaterial = false;
const DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MinDensity = 0;
const DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MaxDensity = 255;
const bool VoxelTypeTraits< DensityI16 >::HasDensity = true;
const bool VoxelTypeTraits< DensityI16 >::HasMaterial = false;
const DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MinDensity = -32767;
const DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MaxDensity = 32767;
const bool VoxelTypeTraits< DensityU16 >::HasDensity = true;
const bool VoxelTypeTraits< DensityU16 >::HasMaterial = false;
const DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MinDensity = 0;
const DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MaxDensity = 65535;
const bool VoxelTypeTraits< DensityFloat >::HasDensity = true;
const bool VoxelTypeTraits< DensityFloat >::HasMaterial = false;
const DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MinDensity = -FLT_MAX;
const DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MaxDensity = FLT_MAX;
const bool VoxelTypeTraits< DensityDouble >::HasDensity = true;
const bool VoxelTypeTraits< DensityDouble >::HasMaterial = false;
const DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MinDensity = -DBL_MAX;
const DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MaxDensity = DBL_MAX;
}

View File

@ -1,44 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Material.h"
#include <cfloat> //Can't use <limits> as we need compile time constants.
namespace PolyVox
{
const bool VoxelTypeTraits< MaterialU8 >::HasDensity = false;
const bool VoxelTypeTraits< MaterialU8 >::HasMaterial = true;
const MaterialU8::DensityType VoxelTypeTraits< MaterialU8 >::MinDensity = 0;
const MaterialU8::DensityType VoxelTypeTraits< MaterialU8 >::MaxDensity = 0;
const bool VoxelTypeTraits< MaterialU16 >::HasDensity = false;
const bool VoxelTypeTraits< MaterialU16 >::HasMaterial = true;
const MaterialU16::DensityType VoxelTypeTraits< MaterialU16 >::MinDensity = 0;
const MaterialU16::DensityType VoxelTypeTraits< MaterialU16 >::MaxDensity = 0;
const bool VoxelTypeTraits< MaterialU32 >::HasDensity = false;
const bool VoxelTypeTraits< MaterialU32 >::HasMaterial = true;
const MaterialU32::DensityType VoxelTypeTraits< MaterialU32 >::MinDensity = 0;
const MaterialU32::DensityType VoxelTypeTraits< MaterialU32 >::MaxDensity = 0;
}

View File

@ -1,37 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/MaterialDensityPair.h"
namespace PolyVox
{
const bool VoxelTypeTraits< MaterialDensityPair44 >::HasDensity = true;
const bool VoxelTypeTraits< MaterialDensityPair44 >::HasMaterial = true;
const MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0;
const MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15;
const bool VoxelTypeTraits< MaterialDensityPair88 >::HasDensity = true;
const bool VoxelTypeTraits< MaterialDensityPair88 >::HasMaterial = true;
const MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MinDensity = 0;
const MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MaxDensity = 255;
}

View File

@ -1,37 +0,0 @@
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#include "PolyVoxCore/Voxel.h"
namespace PolyVox
{
template<typename Type>
const bool VoxelTypeTraits<Type>::HasDensity = false;
template<typename Type>
const bool VoxelTypeTraits<Type>::HasMaterial = false;
template<typename Type>
const typename Type::DensityType VoxelTypeTraits< Type >::MinDensity = 0;
template<typename Type>
const typename Type::DensityType VoxelTypeTraits< Type >::MaxDensity = 0;
}

View File

@ -38,43 +38,43 @@ void TestVoxels::testVoxelTypeLimits()
// It's worth testing these as they are not all explictily defined (e.g. Density8 is just a // It's worth testing these as they are not all explictily defined (e.g. Density8 is just a
// typedef of DensityI8), and in the future we might define then with bitwise magic or something. // typedef of DensityI8), and in the future we might define then with bitwise magic or something.
QCOMPARE(VoxelTypeTraits<Density8>::MinDensity, Density8::DensityType(0)); QCOMPARE(VoxelTypeTraits<Density8>::minDensity(), Density8::DensityType(0));
QCOMPARE(VoxelTypeTraits<Density8>::MaxDensity, Density8::DensityType(255)); QCOMPARE(VoxelTypeTraits<Density8>::maxDensity(), Density8::DensityType(255));
QCOMPARE(VoxelTypeTraits<DensityI8>::MinDensity, DensityI8::DensityType(-127)); QCOMPARE(VoxelTypeTraits<DensityI8>::minDensity(), DensityI8::DensityType(-127));
QCOMPARE(VoxelTypeTraits<DensityI8>::MaxDensity, DensityI8::DensityType(127)); QCOMPARE(VoxelTypeTraits<DensityI8>::maxDensity(), DensityI8::DensityType(127));
QCOMPARE(VoxelTypeTraits<DensityU8>::MinDensity, DensityU8::DensityType(0)); QCOMPARE(VoxelTypeTraits<DensityU8>::minDensity(), DensityU8::DensityType(0));
QCOMPARE(VoxelTypeTraits<DensityU8>::MaxDensity, DensityU8::DensityType(255)); QCOMPARE(VoxelTypeTraits<DensityU8>::maxDensity(), DensityU8::DensityType(255));
QCOMPARE(VoxelTypeTraits<Density16>::MinDensity, Density16::DensityType(0)); QCOMPARE(VoxelTypeTraits<Density16>::minDensity(), Density16::DensityType(0));
QCOMPARE(VoxelTypeTraits<Density16>::MaxDensity, Density16::DensityType(65535)); QCOMPARE(VoxelTypeTraits<Density16>::maxDensity(), Density16::DensityType(65535));
QCOMPARE(VoxelTypeTraits<DensityI16>::MinDensity, DensityI16::DensityType(-32767)); QCOMPARE(VoxelTypeTraits<DensityI16>::minDensity(), DensityI16::DensityType(-32767));
QCOMPARE(VoxelTypeTraits<DensityI16>::MaxDensity, DensityI16::DensityType(32767)); QCOMPARE(VoxelTypeTraits<DensityI16>::maxDensity(), DensityI16::DensityType(32767));
QCOMPARE(VoxelTypeTraits<DensityU16>::MinDensity, DensityU16::DensityType(0)); QCOMPARE(VoxelTypeTraits<DensityU16>::minDensity(), DensityU16::DensityType(0));
QCOMPARE(VoxelTypeTraits<DensityU16>::MaxDensity, DensityU16::DensityType(65535)); QCOMPARE(VoxelTypeTraits<DensityU16>::maxDensity(), DensityU16::DensityType(65535));
QCOMPARE(VoxelTypeTraits<DensityFloat>::MinDensity, FLT_MIN); QCOMPARE(VoxelTypeTraits<DensityFloat>::minDensity(), FLT_MIN);
QCOMPARE(VoxelTypeTraits<DensityFloat>::MaxDensity, FLT_MAX); QCOMPARE(VoxelTypeTraits<DensityFloat>::maxDensity(), FLT_MAX);
QCOMPARE(VoxelTypeTraits<DensityDouble>::MinDensity, DBL_MIN); QCOMPARE(VoxelTypeTraits<DensityDouble>::minDensity(), DBL_MIN);
QCOMPARE(VoxelTypeTraits<DensityDouble>::MaxDensity, DBL_MAX); QCOMPARE(VoxelTypeTraits<DensityDouble>::maxDensity(), DBL_MAX);
/*fValue = VoxelTypeTraits<DensityFloat>::MinDensity; /*fValue = VoxelTypeTraits<DensityFloat>::minDensity();
QCOMPARE(fValue, -FLT_MAX); QCOMPARE(fValue, -FLT_MAX);
fValue = VoxelTypeTraits<DensityFloat>::MaxDensity; fValue = VoxelTypeTraits<DensityFloat>::maxDensity();
QCOMPARE(fValue, FLT_MAX);*/ QCOMPARE(fValue, FLT_MAX);*/
/*iValue = VoxelTypeTraits<Material8>::MinDensity; /*iValue = VoxelTypeTraits<Material8>::minDensity();
QCOMPARE(iValue, 0); QCOMPARE(iValue, 0);
iValue = VoxelTypeTraits<Material8>::MaxDensity; iValue = VoxelTypeTraits<Material8>::maxDensity();
QCOMPARE(iValue, 0);*/ QCOMPARE(iValue, 0);*/
/*iValue = VoxelTypeTraits<MaterialDensityPair44>::MinDensity; /*iValue = VoxelTypeTraits<MaterialDensityPair44>::minDensity();
QCOMPARE(iValue, 0); QCOMPARE(iValue, 0);
iValue = VoxelTypeTraits<MaterialDensityPair44>::MaxDensity; iValue = VoxelTypeTraits<MaterialDensityPair44>::maxDensity();
QCOMPARE(iValue, 15);*/ QCOMPARE(iValue, 15);*/
} }