Work on refactoring voxel types.
This commit is contained in:
parent
a82dc7f1ca
commit
21ce252e1e
@ -29,9 +29,6 @@ using namespace PolyVox;
|
|||||||
|
|
||||||
void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRadius, uint8_t uValue)
|
void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRadius, uint8_t uValue)
|
||||||
{
|
{
|
||||||
int maxDen = VoxelTypeTraits<MaterialDensityPair44>::MaxDensity;
|
|
||||||
int minDen = VoxelTypeTraits<MaterialDensityPair44>::MinDensity;
|
|
||||||
|
|
||||||
//This vector hold the position of the center of the volume
|
//This vector hold the position of the center of the volume
|
||||||
Vector3DInt32 v3dVolCenter = (volData.getEnclosingRegion().getUpperCorner() - volData.getEnclosingRegion().getLowerCorner()) / 2;
|
Vector3DInt32 v3dVolCenter = (volData.getEnclosingRegion().getUpperCorner() - volData.getEnclosingRegion().getLowerCorner()) / 2;
|
||||||
|
|
||||||
@ -51,7 +48,7 @@ void createSphereInVolume(LargeVolume<MaterialDensityPair44>& volData, float fRa
|
|||||||
//then we make it solid, otherwise we make it empty space.
|
//then we make it solid, otherwise we make it empty space.
|
||||||
if(fDistToCenter <= fRadius)
|
if(fDistToCenter <= fRadius)
|
||||||
{
|
{
|
||||||
volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? maxDen : VoxelTypeTraits<MaterialDensityPair44>::MinDensity));
|
//volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? VoxelTypeTraits<MaterialDensityPair44>::MaxDensity : VoxelTypeTraits<MaterialDensityPair44>::MinDensity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,12 @@ SET(CORE_SRC_FILES
|
|||||||
source/Density.cpp
|
source/Density.cpp
|
||||||
source/GradientEstimators.cpp
|
source/GradientEstimators.cpp
|
||||||
source/Log.cpp
|
source/Log.cpp
|
||||||
|
source/MaterialDensityPair.cpp
|
||||||
source/MeshDecimator.cpp
|
source/MeshDecimator.cpp
|
||||||
source/Region.cpp
|
source/Region.cpp
|
||||||
source/SimpleInterface.cpp
|
source/SimpleInterface.cpp
|
||||||
source/VertexTypes.cpp
|
source/VertexTypes.cpp
|
||||||
|
source/Voxel.cpp
|
||||||
source/VoxelFilters.cpp
|
source/VoxelFilters.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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
|
// 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.
|
// 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<int8_t> >
|
class VoxelTypeTraits< Density<int8_t> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static int8_t MinDensity = -127;
|
const static int8_t MinDensity;
|
||||||
const static int8_t MaxDensity = 127;
|
const static int8_t MaxDensity;
|
||||||
};
|
};*/
|
||||||
|
|
||||||
template<>
|
/*template<>
|
||||||
class VoxelTypeTraits< Density<uint8_t> >
|
class VoxelTypeTraits< Density<uint8_t> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static uint8_t MinDensity = 0;
|
const static uint8_t MinDensity;
|
||||||
const static uint8_t MaxDensity = 255;
|
const static uint8_t MaxDensity;
|
||||||
};
|
};*/
|
||||||
|
|
||||||
template<>
|
/*template<>
|
||||||
class VoxelTypeTraits< Density<int16_t> >
|
class VoxelTypeTraits< Density<int16_t> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static int16_t MinDensity = -32767;
|
const static int16_t MinDensity;
|
||||||
const static int16_t MaxDensity = 32767;
|
const static int16_t MaxDensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class VoxelTypeTraits< Density<uint16_t> >
|
class VoxelTypeTraits< Density<uint16_t> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static uint16_t MinDensity = 0;
|
const static uint16_t MinDensity;
|
||||||
const static uint16_t MaxDensity = 65535;
|
const static uint16_t MaxDensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Constants for float defined in .cpp file as they are not integers.
|
//Constants for float defined in .cpp file as they are not integers.
|
||||||
@ -147,7 +147,7 @@ namespace PolyVox
|
|||||||
public:
|
public:
|
||||||
const static double MinDensity;
|
const static double MinDensity;
|
||||||
const static double MaxDensity;
|
const static double MaxDensity;
|
||||||
};
|
};*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,13 +86,13 @@ namespace PolyVox
|
|||||||
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
|
typedef MaterialDensityPair<uint8_t, 4, 4> MaterialDensityPair44;
|
||||||
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
|
typedef MaterialDensityPair<uint16_t, 8, 8> MaterialDensityPair88;
|
||||||
|
|
||||||
template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
|
/*template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
|
||||||
class VoxelTypeTraits< MaterialDensityPair<Type, NoOfDensityBits, NoOfMaterialBits> >
|
class VoxelTypeTraits< MaterialDensityPair<Type, NoOfDensityBits, NoOfMaterialBits> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static Type MinDensity = 0;
|
const static Type MinDensity = 0;
|
||||||
const static Type MaxDensity = (0x01 << NoOfDensityBits) - 1;
|
const static Type MaxDensity = (0x01 << NoOfDensityBits) - 1;
|
||||||
};
|
};*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -68,8 +68,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits
|
class VoxelTypeTraits
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static typename Type::DensityType MinDensity = 0;
|
const static typename Type::DensityType MinDensity;
|
||||||
const static typename Type::DensityType MaxDensity = 0;
|
const static typename Type::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,33 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
template<>
|
||||||
|
const int8_t VoxelTypeTraits< Density<int8_t> >::MinDensity = -127;
|
||||||
|
template<>
|
||||||
|
const int8_t VoxelTypeTraits< Density<int8_t> >::MaxDensity = 127;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
const uint8_t VoxelTypeTraits< Density<uint8_t> >::MinDensity = 0;
|
||||||
|
template<>
|
||||||
|
const uint8_t VoxelTypeTraits< Density<uint8_t> >::MaxDensity = 255;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
const int16_t VoxelTypeTraits< Density<int16_t> >::MinDensity = -32767;
|
||||||
|
template<>
|
||||||
|
const int16_t VoxelTypeTraits< Density<int16_t> >::MaxDensity = 32767;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
const uint16_t VoxelTypeTraits< Density<uint16_t> >::MinDensity = 0;
|
||||||
|
template<>
|
||||||
|
const uint16_t VoxelTypeTraits< Density<uint16_t> >::MaxDensity = 65535;
|
||||||
|
|
||||||
|
template<>
|
||||||
const float VoxelTypeTraits< Density<float> >::MinDensity = FLT_MIN;
|
const float VoxelTypeTraits< Density<float> >::MinDensity = FLT_MIN;
|
||||||
|
template<>
|
||||||
const float VoxelTypeTraits< Density<float> >::MaxDensity = FLT_MAX;
|
const float VoxelTypeTraits< Density<float> >::MaxDensity = FLT_MAX;
|
||||||
|
|
||||||
|
template<>
|
||||||
const double VoxelTypeTraits< Density<double> >::MinDensity = DBL_MIN;
|
const double VoxelTypeTraits< Density<double> >::MinDensity = DBL_MIN;
|
||||||
|
template<>
|
||||||
const double VoxelTypeTraits< Density<double> >::MaxDensity = DBL_MAX;
|
const double VoxelTypeTraits< Density<double> >::MaxDensity = DBL_MAX;
|
||||||
}
|
}
|
37
library/PolyVoxCore/source/MaterialDensityPair.cpp
Normal file
37
library/PolyVoxCore/source/MaterialDensityPair.cpp
Normal file
@ -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<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
|
||||||
|
//const Type VoxelTypeTraits< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >::MinDensity = 0;
|
||||||
|
//template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
|
||||||
|
//const Type VoxelTypeTraits< Type >::MaxDensity = (0x01 << NoOfDensityBits) - 1;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
const uint8_t VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0;
|
||||||
|
template<>
|
||||||
|
const uint8_t VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15;
|
||||||
|
}
|
32
library/PolyVoxCore/source/Voxel.cpp
Normal file
32
library/PolyVoxCore/source/Voxel.cpp
Normal file
@ -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<typename Type>
|
||||||
|
const typename Type::DensityType VoxelTypeTraits<Type>::MinDensity = 0;
|
||||||
|
template<typename Type>
|
||||||
|
const typename Type::DensityType VoxelTypeTraits<Type>::MaxDensity = 0;
|
||||||
|
}
|
@ -27,10 +27,10 @@ freely, subject to the following restrictions:
|
|||||||
#include "PolyVoxCore/Material.h"
|
#include "PolyVoxCore/Material.h"
|
||||||
#include "PolyVoxCore/MaterialDensityPair.h"
|
#include "PolyVoxCore/MaterialDensityPair.h"
|
||||||
|
|
||||||
#include "PolyVoxCore/Vector.h"
|
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include <cfloat>
|
||||||
|
|
||||||
using namespace PolyVox;
|
using namespace PolyVox;
|
||||||
|
|
||||||
void TestVoxels::testTraits()
|
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.
|
int iValue; float fValue; //Used for temporary storage as the QCOMPARE maro struggles with the complex types.
|
||||||
|
|
||||||
|
|
||||||
iValue = VoxelTypeTraits<Density8>::MinDensity;
|
QCOMPARE(VoxelTypeTraits<Density8>::MaxDensity, static_cast<uint8_t>(0));
|
||||||
QCOMPARE(iValue, 0);
|
QCOMPARE(VoxelTypeTraits<Density8>::MaxDensity, static_cast<uint8_t>(255));
|
||||||
iValue = VoxelTypeTraits<Density8>::MaxDensity;
|
|
||||||
QCOMPARE(iValue, 255);
|
|
||||||
|
|
||||||
fValue = VoxelTypeTraits<DensityFloat>::MinDensity;
|
fValue = VoxelTypeTraits<DensityFloat>::MinDensity;
|
||||||
QCOMPARE(fValue, -1000000.0f);
|
QCOMPARE(fValue, FLT_MIN);
|
||||||
fValue = VoxelTypeTraits<DensityFloat>::MaxDensity;
|
fValue = VoxelTypeTraits<DensityFloat>::MaxDensity;
|
||||||
QCOMPARE(fValue, 1000000.0f);
|
QCOMPARE(fValue, FLT_MAX);
|
||||||
|
|
||||||
iValue = VoxelTypeTraits<Material8>::MinDensity;
|
/*iValue = VoxelTypeTraits<Material8>::MinDensity;
|
||||||
QCOMPARE(iValue, 0);
|
QCOMPARE(iValue, 0);
|
||||||
iValue = VoxelTypeTraits<Material8>::MaxDensity;
|
iValue = VoxelTypeTraits<Material8>::MaxDensity;
|
||||||
QCOMPARE(iValue, 0);
|
QCOMPARE(iValue, 0);*/
|
||||||
|
|
||||||
iValue = VoxelTypeTraits<MaterialDensityPair44>::MinDensity;
|
iValue = VoxelTypeTraits<MaterialDensityPair44>::MinDensity;
|
||||||
QCOMPARE(iValue, 0);
|
QCOMPARE(iValue, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user