diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index 14946f08..84909732 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -94,18 +94,59 @@ namespace PolyVox // These types are here for backwards compatibility but they are a little ambiguous as the name doesn't indicate // whether the values are signed. We would recommend using one of the 8 or 16 bit predefined types above instead. - typedef Density Density8; - typedef Density Density16; + typedef DensityU8 Density8; + typedef DensityU16 Density16; // We have to define all the min and max values explicitly here rather than using std::numeric_limits because we need // compile time constants. The new 'constexpr' would help here but it's not supported by all compilers at the moment. - /*template<> - class VoxelTypeTraits< Density > + + template<> + class VoxelTypeTraits< DensityI8 > { public: - const static int8_t MinDensity; - const static int8_t MaxDensity; - };*/ + const static typename DensityI8::DensityType MinDensity; + const static typename DensityI8::DensityType MaxDensity; + }; + + template<> + class VoxelTypeTraits< DensityU8 > + { + public: + const static typename DensityU8::DensityType MinDensity; + const static typename DensityU8::DensityType MaxDensity; + }; + + template<> + class VoxelTypeTraits< DensityI16 > + { + public: + const static typename DensityI16::DensityType MinDensity; + const static typename DensityI16::DensityType MaxDensity; + }; + + template<> + class VoxelTypeTraits< DensityU16 > + { + public: + const static typename DensityU16::DensityType MinDensity; + const static typename DensityU16::DensityType MaxDensity; + }; + + template<> + class VoxelTypeTraits< DensityFloat > + { + public: + const static typename DensityFloat::DensityType MinDensity; + const static typename DensityFloat::DensityType MaxDensity; + }; + + template<> + class VoxelTypeTraits< DensityDouble > + { + public: + const static typename DensityDouble::DensityType MinDensity; + const static typename DensityDouble::DensityType MaxDensity; + }; /*template<> class VoxelTypeTraits< Density > @@ -113,9 +154,9 @@ namespace PolyVox public: const static uint8_t MinDensity; const static uint8_t MaxDensity; - };*/ + }; - /*template<> + template<> class VoxelTypeTraits< Density > { public: diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 6de6fad7..81fc4241 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -86,13 +86,21 @@ namespace PolyVox typedef MaterialDensityPair MaterialDensityPair44; typedef MaterialDensityPair MaterialDensityPair88; - /*template - class VoxelTypeTraits< MaterialDensityPair > + template<> + class VoxelTypeTraits< MaterialDensityPair44 > { public: - const static Type MinDensity = 0; - const static Type MaxDensity = (0x01 << NoOfDensityBits) - 1; - };*/ + const static typename MaterialDensityPair44::DensityType MinDensity; + const static typename MaterialDensityPair44::DensityType MaxDensity; + }; + + template<> + class VoxelTypeTraits< MaterialDensityPair88 > + { + public: + const static typename MaterialDensityPair88::DensityType MinDensity; + const static typename MaterialDensityPair88::DensityType MaxDensity; + }; } #endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h index 0d458283..d76b3365 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h @@ -68,8 +68,8 @@ namespace PolyVox class VoxelTypeTraits { public: - const static typename Type::DensityType MinDensity; - const static typename Type::DensityType MaxDensity; + const static Type MinDensity; + const static Type MaxDensity; }; } diff --git a/library/PolyVoxCore/source/Density.cpp b/library/PolyVoxCore/source/Density.cpp index 781e4d3b..4e2ef1e6 100644 --- a/library/PolyVoxCore/source/Density.cpp +++ b/library/PolyVoxCore/source/Density.cpp @@ -27,33 +27,62 @@ freely, subject to the following restrictions: namespace PolyVox { + //const typename Density8::DensityType VoxelTypeTraits< Density8 >::MinDensity = 0; + //const typename Density8::DensityType VoxelTypeTraits< Density8 >::MaxDensity = 255; + + const typename DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MinDensity = -127; + const typename DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MaxDensity = 127; + + const typename DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MinDensity = 0; + const typename DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MaxDensity = 255; + + //const typename Density16::DensityType VoxelTypeTraits< Density16 >::MinDensity = 0; + //const typename Density16::DensityType VoxelTypeTraits< Density16 >::MaxDensity = 65535; + + const typename DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MinDensity = -32767; + const typename DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MaxDensity = 32767; + + const typename DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MinDensity = 0; + const typename DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MaxDensity = 65535; + + const typename DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MinDensity = FLT_MIN; + const typename DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MaxDensity = FLT_MAX; + + const typename DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MinDensity = DBL_MIN; + const typename DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MaxDensity = DBL_MAX; + + //template<> + //const typename DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MinDensity = -127; + //template<> + //const typename DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MaxDensity = 127; + + //template<> + //const typename DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MinDensity = 0; + //template<> + //const typename DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MaxDensity = 255; + + /*template<> + const uint8_t VoxelTypeTraits< Density8 >::MinDensity = 0; template<> - const int8_t VoxelTypeTraits< Density >::MinDensity = -127; - template<> - const int8_t VoxelTypeTraits< Density >::MaxDensity = 127; + const uint8_t VoxelTypeTraits< Density8 >::MaxDensity = 255; template<> - const uint8_t VoxelTypeTraits< Density >::MinDensity = 0; + const int16_t VoxelTypeTraits< DensityI16 >::MinDensity = -32767; template<> - const uint8_t VoxelTypeTraits< Density >::MaxDensity = 255; + const int16_t VoxelTypeTraits< DensityI16 >::MaxDensity = 32767; template<> - const int16_t VoxelTypeTraits< Density >::MinDensity = -32767; + const uint16_t VoxelTypeTraits< Density16 >::MinDensity = 0; template<> - const int16_t VoxelTypeTraits< Density >::MaxDensity = 32767; + const uint16_t VoxelTypeTraits< Density16 >::MaxDensity = 65535; template<> - const uint16_t VoxelTypeTraits< Density >::MinDensity = 0; + const float VoxelTypeTraits< DensityFloat >::MinDensity = FLT_MIN; template<> - const uint16_t VoxelTypeTraits< Density >::MaxDensity = 65535; - - template<> - const float VoxelTypeTraits< Density >::MinDensity = FLT_MIN; - template<> - const float VoxelTypeTraits< Density >::MaxDensity = FLT_MAX; + const float VoxelTypeTraits< DensityFloat >::MaxDensity = FLT_MAX; template<> - const double VoxelTypeTraits< Density >::MinDensity = DBL_MIN; + const double VoxelTypeTraits< DensityDouble >::MinDensity = DBL_MIN; template<> - const double VoxelTypeTraits< Density >::MaxDensity = DBL_MAX; + const double VoxelTypeTraits< DensityDouble >::MaxDensity = DBL_MAX;*/ } \ No newline at end of file diff --git a/library/PolyVoxCore/source/MaterialDensityPair.cpp b/library/PolyVoxCore/source/MaterialDensityPair.cpp index a937aa85..f77f3666 100644 --- a/library/PolyVoxCore/source/MaterialDensityPair.cpp +++ b/library/PolyVoxCore/source/MaterialDensityPair.cpp @@ -25,13 +25,9 @@ freely, subject to the following restrictions: namespace PolyVox { - //template - //const Type VoxelTypeTraits< MaterialDensityPair >::MinDensity = 0; - //template - //const Type VoxelTypeTraits< Type >::MaxDensity = (0x01 << NoOfDensityBits) - 1; + const typename MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0; + const typename MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15; - template<> - const uint8_t VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0; - template<> - const uint8_t VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15; + const typename MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MinDensity = 0; + const typename MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MaxDensity = 255; } diff --git a/library/PolyVoxCore/source/Voxel.cpp b/library/PolyVoxCore/source/Voxel.cpp index 2940e34d..00770b82 100644 --- a/library/PolyVoxCore/source/Voxel.cpp +++ b/library/PolyVoxCore/source/Voxel.cpp @@ -26,7 +26,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - const typename Type::DensityType VoxelTypeTraits::MinDensity = 0; + const Type VoxelTypeTraits::MinDensity = 0; template - const typename Type::DensityType VoxelTypeTraits::MaxDensity = 0; + const Type VoxelTypeTraits::MaxDensity = 0; } \ No newline at end of file diff --git a/tests/TestVoxels.cpp b/tests/TestVoxels.cpp index d505cd86..665ae7c4 100644 --- a/tests/TestVoxels.cpp +++ b/tests/TestVoxels.cpp @@ -34,27 +34,45 @@ freely, subject to the following restrictions: using namespace PolyVox; void TestVoxels::testTraits() -{ - int iValue; float fValue; //Used for temporary storage as the QCOMPARE maro struggles with the complex types. +{ + QCOMPARE(VoxelTypeTraits::MinDensity, Density8::DensityType(0)); + QCOMPARE(VoxelTypeTraits::MaxDensity, Density8::DensityType(255)); + QCOMPARE(VoxelTypeTraits::MinDensity, DensityI8::DensityType(-127)); + QCOMPARE(VoxelTypeTraits::MaxDensity, DensityI8::DensityType(127)); - QCOMPARE(VoxelTypeTraits::MaxDensity, static_cast(0)); - QCOMPARE(VoxelTypeTraits::MaxDensity, static_cast(255)); + QCOMPARE(VoxelTypeTraits::MinDensity, DensityU8::DensityType(0)); + QCOMPARE(VoxelTypeTraits::MaxDensity, DensityU8::DensityType(255)); - fValue = VoxelTypeTraits::MinDensity; + QCOMPARE(VoxelTypeTraits::MinDensity, Density16::DensityType(0)); + QCOMPARE(VoxelTypeTraits::MaxDensity, Density16::DensityType(65535)); + + QCOMPARE(VoxelTypeTraits::MinDensity, DensityI16::DensityType(-32767)); + QCOMPARE(VoxelTypeTraits::MaxDensity, DensityI16::DensityType(32767)); + + QCOMPARE(VoxelTypeTraits::MinDensity, DensityU16::DensityType(0)); + QCOMPARE(VoxelTypeTraits::MaxDensity, DensityU16::DensityType(65535)); + + QCOMPARE(VoxelTypeTraits::MinDensity, FLT_MIN); + QCOMPARE(VoxelTypeTraits::MaxDensity, FLT_MAX); + + QCOMPARE(VoxelTypeTraits::MinDensity, DBL_MIN); + QCOMPARE(VoxelTypeTraits::MaxDensity, DBL_MAX); + + /*fValue = VoxelTypeTraits::MinDensity; QCOMPARE(fValue, FLT_MIN); fValue = VoxelTypeTraits::MaxDensity; - QCOMPARE(fValue, FLT_MAX); + QCOMPARE(fValue, FLT_MAX);*/ /*iValue = VoxelTypeTraits::MinDensity; QCOMPARE(iValue, 0); iValue = VoxelTypeTraits::MaxDensity; QCOMPARE(iValue, 0);*/ - iValue = VoxelTypeTraits::MinDensity; + /*iValue = VoxelTypeTraits::MinDensity; QCOMPARE(iValue, 0); iValue = VoxelTypeTraits::MaxDensity; - QCOMPARE(iValue, 15); + QCOMPARE(iValue, 15);*/ } QTEST_MAIN(TestVoxels)