Added Material8 and Density8 classes, and Thermite now uses the Material8 one.
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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" | ||||
|  | ||||
|   | ||||
							
								
								
									
										88
									
								
								library/PolyVoxCore/include/Density.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								library/PolyVoxCore/include/Density.h
									
									
									
									
									
										Normal file
									
								
							| @@ -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 <typename Type> | ||||
| 	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<uint8_t> Density8; | ||||
| } | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										101
									
								
								library/PolyVoxCore/include/Material.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								library/PolyVoxCore/include/Material.h
									
									
									
									
									
										Normal file
									
								
							| @@ -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 <typename Type> | ||||
| 	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<uint8_t> Material8; | ||||
| } | ||||
|  | ||||
| #endif | ||||
| @@ -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 | ||||
| @@ -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 <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::MaterialDensityPair() | ||||
| 		:m_uMaterial(0) | ||||
| 		,m_uDensity(0) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::MaterialDensityPair(Type uMaterial, Type uDensity) | ||||
| 		:m_uMaterial(uMaterial) | ||||
| 		,m_uDensity(uDensity) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	bool MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::operator==(const MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& rhs) const throw() | ||||
|     { | ||||
| 		return (m_uMaterial == rhs.m_uMaterial) && (m_uDensity == rhs.m_uDensity); | ||||
|     } | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	bool MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::operator!=(const MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& rhs) const throw() | ||||
|     { | ||||
| 		return !(*this == rhs); | ||||
|     } | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	bool MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::operator<(const MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>& 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 <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	Type MaterialDensityPair<Type,NoOfMaterialBits, NoOfDensityBits>::getDensity() const throw() | ||||
| 	{ | ||||
| 		return m_uDensity; | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	Type MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMaterial() const throw() | ||||
| 	{ | ||||
| 		return m_uMaterial; | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	void MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::setDensity(Type uDensity) | ||||
| 	{ | ||||
| 		m_uDensity = uDensity; | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	void MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::setMaterial(Type uMaterial) | ||||
| 	{ | ||||
| 		m_uMaterial = uMaterial; | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	Type  MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMaxDensity() throw() | ||||
| 	{ | ||||
| 		return (0x01 << NoOfDensityBits) - 1; | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	Type  MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getMinDensity() throw() | ||||
| 	{ | ||||
| 		return 0; | ||||
| 	} | ||||
|  | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> | ||||
| 	Type  MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits>::getThreshold() throw() | ||||
| 	{ | ||||
| 		return  0x01 << (NoOfDensityBits - 1); | ||||
| 	} | ||||
| } | ||||
| @@ -74,6 +74,10 @@ namespace PolyVox | ||||
| 	class MeshVertex; | ||||
| 	//--------------------------------- | ||||
|  | ||||
| 	template <typename Type> class Density; | ||||
| 	typedef Density<uint8_t> Density8; | ||||
| 	template <typename Type> class Material; | ||||
| 	typedef Material<uint8_t> Material8; | ||||
| 	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> class MaterialDensityPair; | ||||
| 	typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user