00001 /******************************************************************************* 00002 Copyright (c) 2005-2009 David Williams 00003 00004 This software is provided 'as-is', without any express or implied 00005 warranty. In no event will the authors be held liable for any damages 00006 arising from the use of this software. 00007 00008 Permission is granted to anyone to use this software for any purpose, 00009 including commercial applications, and to alter it and redistribute it 00010 freely, subject to the following restrictions: 00011 00012 1. The origin of this software must not be misrepresented; you must not 00013 claim that you wrote the original software. If you use this software 00014 in a product, an acknowledgment in the product documentation would be 00015 appreciated but is not required. 00016 00017 2. Altered source versions must be plainly marked as such, and must not be 00018 misrepresented as being the original software. 00019 00020 3. This notice may not be removed or altered from any source 00021 distribution. 00022 *******************************************************************************/ 00023 00024 #ifndef __PolyVox_MaterialDensityPair_H__ 00025 #define __PolyVox_MaterialDensityPair_H__ 00026 00027 #include "PolyVoxImpl/TypeDef.h" 00028 00029 namespace PolyVox 00030 { 00045 template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits> 00046 class MaterialDensityPair 00047 { 00048 public: 00049 MaterialDensityPair() : m_uMaterial(0), m_uDensity(0) {} 00050 MaterialDensityPair(Type uMaterial, Type uDensity) : m_uMaterial(uMaterial), m_uDensity(uDensity) {} 00051 00052 bool operator==(const MaterialDensityPair& rhs) const throw() 00053 { 00054 return (m_uMaterial == rhs.m_uMaterial) && (m_uDensity == rhs.m_uDensity); 00055 }; 00056 00057 bool operator!=(const MaterialDensityPair& rhs) const throw() 00058 { 00059 return !(*this == rhs); 00060 } 00061 00062 Type getDensity() const throw() { return m_uDensity; } 00063 Type getMaterial() const throw() { return m_uMaterial; } 00064 00065 void setDensity(Type uDensity) { m_uDensity = uDensity; } 00066 void setMaterial(Type uMaterial) { m_uMaterial = uMaterial; } 00067 00068 static Type getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; } 00069 static Type getMinDensity() throw() { return 0; } 00070 static Type getThreshold() throw() {return 0x01 << (NoOfDensityBits - 1);} 00071 00072 private: 00073 Type m_uMaterial : NoOfMaterialBits; 00074 Type m_uDensity : NoOfDensityBits; 00075 }; 00076 00077 typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44; 00078 typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88; 00079 } 00080 00081 #endif