diff --git a/examples/OpenGL/Shapes.cpp b/examples/OpenGL/Shapes.cpp index 65bb361f..949523ac 100644 --- a/examples/OpenGL/Shapes.cpp +++ b/examples/OpenGL/Shapes.cpp @@ -29,9 +29,6 @@ using namespace PolyVox; void createSphereInVolume(LargeVolume& volData, float fRadius, uint8_t uValue) { - int maxDen = VoxelTypeTraits::MaxDensity; - int minDen = VoxelTypeTraits::MinDensity; - //This vector hold the position of the center of the volume Vector3DInt32 v3dVolCenter = (volData.getEnclosingRegion().getUpperCorner() - volData.getEnclosingRegion().getLowerCorner()) / 2; @@ -51,7 +48,7 @@ void createSphereInVolume(LargeVolume& volData, float fRa //then we make it solid, otherwise we make it empty space. if(fDistToCenter <= fRadius) { - volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? maxDen : VoxelTypeTraits::MinDensity)); + //volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? VoxelTypeTraits::MaxDensity : VoxelTypeTraits::MinDensity)); } } } diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index dc787a4d..5c73631e 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -9,10 +9,12 @@ SET(CORE_SRC_FILES source/Density.cpp source/GradientEstimators.cpp source/Log.cpp + source/MaterialDensityPair.cpp source/MeshDecimator.cpp source/Region.cpp source/SimpleInterface.cpp source/VertexTypes.cpp + source/Voxel.cpp source/VoxelFilters.cpp ) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Density.h b/library/PolyVoxCore/include/PolyVoxCore/Density.h index ae570351..14946f08 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Density.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Density.h @@ -99,36 +99,36 @@ namespace PolyVox // 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<> + /*template<> class VoxelTypeTraits< Density > { public: - const static int8_t MinDensity = -127; - const static int8_t MaxDensity = 127; - }; + const static int8_t MinDensity; + const static int8_t MaxDensity; + };*/ - template<> + /*template<> class VoxelTypeTraits< Density > { public: - const static uint8_t MinDensity = 0; - const static uint8_t MaxDensity = 255; - }; + const static uint8_t MinDensity; + const static uint8_t MaxDensity; + };*/ - template<> + /*template<> class VoxelTypeTraits< Density > { public: - const static int16_t MinDensity = -32767; - const static int16_t MaxDensity = 32767; + const static int16_t MinDensity; + const static int16_t MaxDensity; }; template<> class VoxelTypeTraits< Density > { public: - const static uint16_t MinDensity = 0; - const static uint16_t MaxDensity = 65535; + const static uint16_t MinDensity; + const static uint16_t MaxDensity; }; //Constants for float defined in .cpp file as they are not integers. @@ -147,7 +147,7 @@ namespace PolyVox public: const static double MinDensity; const static double MaxDensity; - }; + };*/ } diff --git a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h index 5d7ea364..6de6fad7 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MaterialDensityPair.h @@ -86,13 +86,13 @@ namespace PolyVox typedef MaterialDensityPair MaterialDensityPair44; typedef MaterialDensityPair MaterialDensityPair88; - template + /*template class VoxelTypeTraits< MaterialDensityPair > { public: const static Type MinDensity = 0; const static Type MaxDensity = (0x01 << NoOfDensityBits) - 1; - }; + };*/ } #endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/PolyVoxCore/Voxel.h b/library/PolyVoxCore/include/PolyVoxCore/Voxel.h index e3ddb32b..0d458283 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 = 0; - const static typename Type::DensityType MaxDensity = 0; + const static typename Type::DensityType MinDensity; + const static typename Type::DensityType MaxDensity; }; } diff --git a/library/PolyVoxCore/source/Density.cpp b/library/PolyVoxCore/source/Density.cpp index d12c132e..781e4d3b 100644 --- a/library/PolyVoxCore/source/Density.cpp +++ b/library/PolyVoxCore/source/Density.cpp @@ -27,9 +27,33 @@ freely, subject to the following restrictions: namespace PolyVox { + template<> + const int8_t VoxelTypeTraits< Density >::MinDensity = -127; + template<> + const int8_t VoxelTypeTraits< Density >::MaxDensity = 127; + + template<> + const uint8_t VoxelTypeTraits< Density >::MinDensity = 0; + template<> + const uint8_t VoxelTypeTraits< Density >::MaxDensity = 255; + + template<> + const int16_t VoxelTypeTraits< Density >::MinDensity = -32767; + template<> + const int16_t VoxelTypeTraits< Density >::MaxDensity = 32767; + + template<> + const uint16_t VoxelTypeTraits< Density >::MinDensity = 0; + template<> + const uint16_t VoxelTypeTraits< Density >::MaxDensity = 65535; + + template<> const float VoxelTypeTraits< Density >::MinDensity = FLT_MIN; + template<> const float VoxelTypeTraits< Density >::MaxDensity = FLT_MAX; + template<> const double VoxelTypeTraits< Density >::MinDensity = DBL_MIN; + template<> const double VoxelTypeTraits< Density >::MaxDensity = DBL_MAX; } \ No newline at end of file diff --git a/library/PolyVoxCore/source/MaterialDensityPair.cpp b/library/PolyVoxCore/source/MaterialDensityPair.cpp new file mode 100644 index 00000000..a937aa85 --- /dev/null +++ b/library/PolyVoxCore/source/MaterialDensityPair.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* +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 +{ + //template + //const Type VoxelTypeTraits< MaterialDensityPair >::MinDensity = 0; + //template + //const Type VoxelTypeTraits< Type >::MaxDensity = (0x01 << NoOfDensityBits) - 1; + + template<> + const uint8_t VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0; + template<> + const uint8_t VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15; +} diff --git a/library/PolyVoxCore/source/Voxel.cpp b/library/PolyVoxCore/source/Voxel.cpp new file mode 100644 index 00000000..2940e34d --- /dev/null +++ b/library/PolyVoxCore/source/Voxel.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* +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 + const typename Type::DensityType VoxelTypeTraits::MinDensity = 0; + template + const typename Type::DensityType VoxelTypeTraits::MaxDensity = 0; +} \ No newline at end of file diff --git a/tests/TestVoxels.cpp b/tests/TestVoxels.cpp index ac5d239c..d505cd86 100644 --- a/tests/TestVoxels.cpp +++ b/tests/TestVoxels.cpp @@ -27,10 +27,10 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Material.h" #include "PolyVoxCore/MaterialDensityPair.h" -#include "PolyVoxCore/Vector.h" - #include +#include + using namespace PolyVox; void TestVoxels::testTraits() @@ -38,20 +38,18 @@ void TestVoxels::testTraits() int iValue; float fValue; //Used for temporary storage as the QCOMPARE maro struggles with the complex types. - iValue = VoxelTypeTraits::MinDensity; - QCOMPARE(iValue, 0); - iValue = VoxelTypeTraits::MaxDensity; - QCOMPARE(iValue, 255); + QCOMPARE(VoxelTypeTraits::MaxDensity, static_cast(0)); + QCOMPARE(VoxelTypeTraits::MaxDensity, static_cast(255)); fValue = VoxelTypeTraits::MinDensity; - QCOMPARE(fValue, -1000000.0f); + QCOMPARE(fValue, FLT_MIN); fValue = VoxelTypeTraits::MaxDensity; - QCOMPARE(fValue, 1000000.0f); + QCOMPARE(fValue, FLT_MAX); - iValue = VoxelTypeTraits::MinDensity; + /*iValue = VoxelTypeTraits::MinDensity; QCOMPARE(iValue, 0); iValue = VoxelTypeTraits::MaxDensity; - QCOMPARE(iValue, 0); + QCOMPARE(iValue, 0);*/ iValue = VoxelTypeTraits::MinDensity; QCOMPARE(iValue, 0);