From 625bd141876951fc2c598cf4afca7a76b9200891 Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 4 Nov 2010 23:12:31 +0000 Subject: [PATCH] Added Material8 and Density8 classes, and Thermite now uses the Material8 one. --- library/PolyVoxCore/CMakeLists.txt | 3 +- .../include/CubicSurfaceExtractor.h | 1 + library/PolyVoxCore/include/Density.h | 88 ++++++++++++++ library/PolyVoxCore/include/Material.h | 101 ++++++++++++++++ .../PolyVoxCore/include/MaterialDensityPair.h | 60 +++++++--- .../include/MaterialDensityPair.inl | 109 ------------------ .../include/PolyVoxForwardDeclarations.h | 4 + 7 files changed, 241 insertions(+), 125 deletions(-) create mode 100644 library/PolyVoxCore/include/Density.h create mode 100644 library/PolyVoxCore/include/Material.h delete mode 100644 library/PolyVoxCore/include/MaterialDensityPair.inl diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index 65d29e29..29414fed 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -25,12 +25,13 @@ SET(CORE_INC_FILES include/CubicSurfaceExtractor.inl include/CubicSurfaceExtractorWithNormals.h include/CubicSurfaceExtractorWithNormals.inl + include/Density.h include/Filters.h include/Filters.inl include/GradientEstimators.inl include/Log.h + include/Material.h include/MaterialDensityPair.h - include/MaterialDensityPair.inl include/Mesh.h include/MeshEdge.h include/MeshFace.h diff --git a/library/PolyVoxCore/include/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/CubicSurfaceExtractor.h index 6b55875f..b0a520f6 100644 --- a/library/PolyVoxCore/include/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/CubicSurfaceExtractor.h @@ -24,6 +24,7 @@ freely, subject to the following restrictions: #ifndef __PolyVox_CubicSurfaceExtractor_H__ #define __PolyVox_CubicSurfaceExtractor_H__ +#include "Array.h" #include "PolyVoxForwardDeclarations.h" #include "VolumeSampler.h" diff --git a/library/PolyVoxCore/include/Density.h b/library/PolyVoxCore/include/Density.h new file mode 100644 index 00000000..cf87da46 --- /dev/null +++ b/library/PolyVoxCore/include/Density.h @@ -0,0 +1,88 @@ +/******************************************************************************* +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. +*******************************************************************************/ + +#ifndef __PolyVox_MaterialDensityPair_H__ +#define __PolyVox_MaterialDensityPair_H__ + +#include "PolyVoxForwardDeclarations.h" +#include "PolyVoxImpl/TypeDef.h" + +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, although it only actually stores a density value. + /// For the getMaterial() function it just returens a constant value of '1'. + /// + /// \sa Material, MaterialDensityPair + //////////////////////////////////////////////////////////////////////////////// + template + class Density + { + public: + Density() : m_uDensity(0) {} + Density(Type uDensity) : m_uDensity(uDensity) {} + + bool operator==(const Density& rhs) const throw() + { + return (m_uDensity == rhs.m_uDensity); + }; + + bool operator!=(const Density& rhs) const throw() + { + return !(*this == rhs); + } + + bool operator<(const Density& rhs) const throw() + { + if (m_uDensity < rhs.m_uDensity) + return true; + if (rhs.m_uDensity < m_uDensity) + return false; + + return false; + } + + Type getDensity() const throw() { return m_uDensity; } + Type getMaterial() const throw() { return 1; } + + void setDensity(Type uDensity) { m_uDensity = uDensity; } + void setMaterial(Type uMaterial) { assert("Cannot set material on voxel of type 'Density'"); } + + static Type getMaxDensity() throw() { return (0x01 << (sizeof(Type) * 8)) - 1; } + static Type getMinDensity() throw() { return 0; } + static Type getThreshold() throw() {return 0x01 << ((sizeof(Type) * 8) - 1);} + + private: + Type m_uDensity; + }; + + typedef Density Density8; +} + +#endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/Material.h b/library/PolyVoxCore/include/Material.h new file mode 100644 index 00000000..3910dae9 --- /dev/null +++ b/library/PolyVoxCore/include/Material.h @@ -0,0 +1,101 @@ +/******************************************************************************* +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. +*******************************************************************************/ + +#ifndef __PolyVox_MaterialDensityPair_H__ +#define __PolyVox_MaterialDensityPair_H__ + +#include "PolyVoxForwardDeclarations.h" +#include "PolyVoxImpl/TypeDef.h" + +namespace PolyVox +{ + ///This class represents a voxel storing only a material. + //////////////////////////////////////////////////////////////////////////////// + /// 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, 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 + //////////////////////////////////////////////////////////////////////////////// + template + class Material + { + public: + Material() : m_uMaterial(0) {} + Material(Type uMaterial) : m_uMaterial(uMaterial) {} + + bool operator==(const Material& rhs) const throw() + { + return (m_uMaterial == rhs.m_uMaterial); + }; + + bool operator!=(const Material& rhs) const throw() + { + return !(*this == rhs); + } + + bool operator<(const Material& rhs) const throw() + { + if (m_uMaterial < rhs.m_uMaterial) + return true; + if (rhs.m_uMaterial < m_uMaterial) + return false; + + return false; + } + + Type getDensity() const throw() + { + //We don't actually have a density, so make one up based on the material. + if(m_uMaterial == 0) + { + return getMinDensity(); + } + else + { + return getMaxDensity(); + } + } + + Type getMaterial() const throw() { return m_uMaterial; } + + void setDensity(Type /*uDensity*/) { assert("Cannot set density on voxel of type 'Material'"); } + void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } + + static Type getMaxDensity() throw() { return 2; } + static Type getMinDensity() throw() { return 0; } + static Type getThreshold() throw() { return 1; } + + private: + Type m_uMaterial; + }; + + typedef Material Material8; +} + +#endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/MaterialDensityPair.h b/library/PolyVoxCore/include/MaterialDensityPair.h index 49370f97..65c532e7 100644 --- a/library/PolyVoxCore/include/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/MaterialDensityPair.h @@ -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 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 MaterialDensityPair44; } -#include "MaterialDensityPair.inl" - #endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/MaterialDensityPair.inl b/library/PolyVoxCore/include/MaterialDensityPair.inl deleted file mode 100644 index d5ffbcf8..00000000 --- a/library/PolyVoxCore/include/MaterialDensityPair.inl +++ /dev/null @@ -1,109 +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. -*******************************************************************************/ - -namespace PolyVox -{ - template - MaterialDensityPair::MaterialDensityPair() - :m_uMaterial(0) - ,m_uDensity(0) - { - } - - template - MaterialDensityPair::MaterialDensityPair(Type uMaterial, Type uDensity) - :m_uMaterial(uMaterial) - ,m_uDensity(uDensity) - { - } - - template - bool MaterialDensityPair::operator==(const MaterialDensityPair& rhs) const throw() - { - return (m_uMaterial == rhs.m_uMaterial) && (m_uDensity == rhs.m_uDensity); - } - - template - bool MaterialDensityPair::operator!=(const MaterialDensityPair& rhs) const throw() - { - return !(*this == rhs); - } - - template - bool MaterialDensityPair::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; - - return false; - //return m_uMaterial < rhs.m_uMaterial; - } - - template - Type MaterialDensityPair::getDensity() const throw() - { - return m_uDensity; - } - - template - Type MaterialDensityPair::getMaterial() const throw() - { - return m_uMaterial; - } - - template - void MaterialDensityPair::setDensity(Type uDensity) - { - m_uDensity = uDensity; - } - - template - void MaterialDensityPair::setMaterial(Type uMaterial) - { - m_uMaterial = uMaterial; - } - - template - Type MaterialDensityPair::getMaxDensity() throw() - { - return (0x01 << NoOfDensityBits) - 1; - } - - template - Type MaterialDensityPair::getMinDensity() throw() - { - return 0; - } - - template - Type MaterialDensityPair::getThreshold() throw() - { - return 0x01 << (NoOfDensityBits - 1); - } -} diff --git a/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h index 38ee63a6..9dd94c38 100644 --- a/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxForwardDeclarations.h @@ -74,6 +74,10 @@ namespace PolyVox class MeshVertex; //--------------------------------- + template class Density; + typedef Density Density8; + template class Material; + typedef Material Material8; template class MaterialDensityPair; typedef MaterialDensityPair MaterialDensityPair44;