Work on refactoring voxel type.
This commit is contained in:
parent
3c0bbf1d4b
commit
d2cd3e7c62
@ -9,6 +9,7 @@ SET(CORE_SRC_FILES
|
|||||||
source/Density.cpp
|
source/Density.cpp
|
||||||
source/GradientEstimators.cpp
|
source/GradientEstimators.cpp
|
||||||
source/Log.cpp
|
source/Log.cpp
|
||||||
|
source/Material.cpp
|
||||||
source/MaterialDensityPair.cpp
|
source/MaterialDensityPair.cpp
|
||||||
source/MeshDecimator.cpp
|
source/MeshDecimator.cpp
|
||||||
source/Region.cpp
|
source/Region.cpp
|
||||||
|
@ -70,10 +70,10 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
DensityType getDensity() const throw() { return m_uDensity; }
|
DensityType getDensity() const throw() { return m_uDensity; }
|
||||||
MaterialType getMaterial() const throw() { return 1; }
|
//MaterialType getMaterial() const throw() { return 1; }
|
||||||
|
|
||||||
void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
|
void setDensity(DensityType uDensity) { m_uDensity = uDensity; }
|
||||||
void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density
|
//void setMaterial(MaterialType /*uMaterial*/) { assert(false); } //Cannot set material on voxel of type Density
|
||||||
|
|
||||||
//static DensityType getMaxDensity() throw() { return (std::numeric_limits<DensityType>::max)(); }
|
//static DensityType getMaxDensity() throw() { return (std::numeric_limits<DensityType>::max)(); }
|
||||||
//static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); }
|
//static DensityType getMinDensity() throw() { return (std::numeric_limits<DensityType>::min)(); }
|
||||||
@ -103,6 +103,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< DensityI8 >
|
class VoxelTypeTraits< DensityI8 >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static DensityI8::DensityType MinDensity;
|
const static DensityI8::DensityType MinDensity;
|
||||||
const static DensityI8::DensityType MaxDensity;
|
const static DensityI8::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
@ -111,6 +113,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< DensityU8 >
|
class VoxelTypeTraits< DensityU8 >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static DensityU8::DensityType MinDensity;
|
const static DensityU8::DensityType MinDensity;
|
||||||
const static DensityU8::DensityType MaxDensity;
|
const static DensityU8::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
@ -119,6 +123,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< DensityI16 >
|
class VoxelTypeTraits< DensityI16 >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static DensityI16::DensityType MinDensity;
|
const static DensityI16::DensityType MinDensity;
|
||||||
const static DensityI16::DensityType MaxDensity;
|
const static DensityI16::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
@ -127,6 +133,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< DensityU16 >
|
class VoxelTypeTraits< DensityU16 >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static DensityU16::DensityType MinDensity;
|
const static DensityU16::DensityType MinDensity;
|
||||||
const static DensityU16::DensityType MaxDensity;
|
const static DensityU16::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
@ -135,6 +143,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< DensityFloat >
|
class VoxelTypeTraits< DensityFloat >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static DensityFloat::DensityType MinDensity;
|
const static DensityFloat::DensityType MinDensity;
|
||||||
const static DensityFloat::DensityType MaxDensity;
|
const static DensityFloat::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
@ -143,6 +153,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< DensityDouble >
|
class VoxelTypeTraits< DensityDouble >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static DensityDouble::DensityType MinDensity;
|
const static DensityDouble::DensityType MinDensity;
|
||||||
const static DensityDouble::DensityType MaxDensity;
|
const static DensityDouble::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
|
@ -97,9 +97,39 @@ namespace PolyVox
|
|||||||
MaterialType m_uMaterial;
|
MaterialType m_uMaterial;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Material<uint8_t> Material8;
|
typedef Material<uint8_t> MaterialU8;
|
||||||
typedef Material<uint16_t> Material16;
|
typedef Material<uint16_t> MaterialU16;
|
||||||
typedef Material<uint32_t> Material32;
|
typedef Material<uint32_t> MaterialU32;
|
||||||
|
|
||||||
|
// 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, 16, or 32 bit predefined types above instead.
|
||||||
|
typedef MaterialU8 Material8;
|
||||||
|
typedef MaterialU16 Material16;
|
||||||
|
typedef MaterialU32 Material32;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class VoxelTypeTraits< MaterialU8 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class VoxelTypeTraits< MaterialU16 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class VoxelTypeTraits< MaterialU32 >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //__PolyVox_Material_H__
|
#endif //__PolyVox_Material_H__
|
||||||
|
@ -90,6 +90,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< MaterialDensityPair44 >
|
class VoxelTypeTraits< MaterialDensityPair44 >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static MaterialDensityPair44::DensityType MinDensity;
|
const static MaterialDensityPair44::DensityType MinDensity;
|
||||||
const static MaterialDensityPair44::DensityType MaxDensity;
|
const static MaterialDensityPair44::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
@ -98,6 +100,8 @@ namespace PolyVox
|
|||||||
class VoxelTypeTraits< MaterialDensityPair88 >
|
class VoxelTypeTraits< MaterialDensityPair88 >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
const static bool HasDensity;
|
||||||
|
const static bool HasMaterial;
|
||||||
const static MaterialDensityPair88::DensityType MinDensity;
|
const static MaterialDensityPair88::DensityType MinDensity;
|
||||||
const static MaterialDensityPair88::DensityType MaxDensity;
|
const static MaterialDensityPair88::DensityType MaxDensity;
|
||||||
};
|
};
|
||||||
|
@ -445,7 +445,11 @@ namespace PolyVox
|
|||||||
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
|
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
|
||||||
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
|
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
|
||||||
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
|
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
|
||||||
const uint32_t uMaterial = (std::max)(v000.getMaterial(), v100.getMaterial());
|
uint32_t uMaterial = 0;
|
||||||
|
if(VoxelTypeTraits<VoxelType>::HasMaterial)
|
||||||
|
{
|
||||||
|
uMaterial = (std::max)(v000.getMaterial(), v100.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||||
@ -471,7 +475,11 @@ namespace PolyVox
|
|||||||
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
|
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
|
||||||
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
|
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
|
||||||
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
|
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
|
||||||
const uint32_t uMaterial = (std::max)(v000.getMaterial(), v010.getMaterial());
|
uint32_t uMaterial = 0;
|
||||||
|
if(VoxelTypeTraits<VoxelType>::HasMaterial)
|
||||||
|
{
|
||||||
|
uMaterial = (std::max)(v000.getMaterial(), v010.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||||
@ -497,7 +505,11 @@ namespace PolyVox
|
|||||||
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
|
//Choose one of the two materials to use for the vertex (we don't interpolate as interpolation of
|
||||||
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
|
//material IDs does not make sense). We take the largest, so that if we are working on a material-only
|
||||||
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
|
//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component.
|
||||||
const uint32_t uMaterial = (std::max)(v000.getMaterial(), v001.getMaterial());
|
uint32_t uMaterial = 0;
|
||||||
|
if(VoxelTypeTraits<VoxelType>::HasMaterial)
|
||||||
|
{
|
||||||
|
uMaterial = (std::max)(v000.getMaterial(), v001.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial));
|
||||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||||
|
@ -27,21 +27,33 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
const bool VoxelTypeTraits< DensityI8 >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< DensityI8 >::HasMaterial = false;
|
||||||
const DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MinDensity = -127;
|
const DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MinDensity = -127;
|
||||||
const DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MaxDensity = 127;
|
const DensityI8::DensityType VoxelTypeTraits< DensityI8 >::MaxDensity = 127;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< DensityU8 >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< DensityU8 >::HasMaterial = false;
|
||||||
const DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MinDensity = 0;
|
const DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MinDensity = 0;
|
||||||
const DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MaxDensity = 255;
|
const DensityU8::DensityType VoxelTypeTraits< DensityU8 >::MaxDensity = 255;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< DensityI16 >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< DensityI16 >::HasMaterial = false;
|
||||||
const DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MinDensity = -32767;
|
const DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MinDensity = -32767;
|
||||||
const DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MaxDensity = 32767;
|
const DensityI16::DensityType VoxelTypeTraits< DensityI16 >::MaxDensity = 32767;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< DensityU16 >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< DensityU16 >::HasMaterial = false;
|
||||||
const DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MinDensity = 0;
|
const DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MinDensity = 0;
|
||||||
const DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MaxDensity = 65535;
|
const DensityU16::DensityType VoxelTypeTraits< DensityU16 >::MaxDensity = 65535;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< DensityFloat >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< DensityFloat >::HasMaterial = false;
|
||||||
const DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MinDensity = FLT_MIN;
|
const DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MinDensity = FLT_MIN;
|
||||||
const DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MaxDensity = FLT_MAX;
|
const DensityFloat::DensityType VoxelTypeTraits< DensityFloat >::MaxDensity = FLT_MAX;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< DensityDouble >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< DensityDouble >::HasMaterial = false;
|
||||||
const DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MinDensity = DBL_MIN;
|
const DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MinDensity = DBL_MIN;
|
||||||
const DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MaxDensity = DBL_MAX;
|
const DensityDouble::DensityType VoxelTypeTraits< DensityDouble >::MaxDensity = DBL_MAX;
|
||||||
}
|
}
|
38
library/PolyVoxCore/source/Material.cpp
Normal file
38
library/PolyVoxCore/source/Material.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
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/Material.h"
|
||||||
|
|
||||||
|
#include <cfloat> //Can't use <limits> as we need compile time constants.
|
||||||
|
|
||||||
|
namespace PolyVox
|
||||||
|
{
|
||||||
|
const bool VoxelTypeTraits< MaterialU8 >::HasDensity = false;
|
||||||
|
const bool VoxelTypeTraits< MaterialU8 >::HasMaterial = true;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< MaterialU16 >::HasDensity = false;
|
||||||
|
const bool VoxelTypeTraits< MaterialU16 >::HasMaterial = true;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< MaterialU32 >::HasDensity = false;
|
||||||
|
const bool VoxelTypeTraits< MaterialU32 >::HasMaterial = true;
|
||||||
|
}
|
@ -25,9 +25,13 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
|
const bool VoxelTypeTraits< MaterialDensityPair44 >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< MaterialDensityPair44 >::HasMaterial = true;
|
||||||
const MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0;
|
const MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MinDensity = 0;
|
||||||
const MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15;
|
const MaterialDensityPair44::DensityType VoxelTypeTraits< MaterialDensityPair44 >::MaxDensity = 15;
|
||||||
|
|
||||||
|
const bool VoxelTypeTraits< MaterialDensityPair88 >::HasDensity = true;
|
||||||
|
const bool VoxelTypeTraits< MaterialDensityPair88 >::HasMaterial = true;
|
||||||
const MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MinDensity = 0;
|
const MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MinDensity = 0;
|
||||||
const MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MaxDensity = 255;
|
const MaterialDensityPair88::DensityType VoxelTypeTraits< MaterialDensityPair88 >::MaxDensity = 255;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user