Added IndexType template parameter to Mesh class.

This commit is contained in:
David Williams 2014-06-03 15:58:07 +02:00
parent 5701e7a6cc
commit ffdf606ad6
3 changed files with 38 additions and 37 deletions

View File

@ -38,12 +38,13 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
template <typename VertexType> template <typename VertexType, typename IndexType = uint32_t>
class Mesh class Mesh
{ {
public: public:
typedef VertexType VertexType; typedef VertexType VertexType;
typedef IndexType IndexType;
Mesh(); Mesh();
~Mesh(); ~Mesh();

View File

@ -23,54 +23,54 @@ freely, subject to the following restrictions:
namespace PolyVox namespace PolyVox
{ {
template <typename VertexType> template <typename VertexType, typename IndexType>
Mesh<VertexType>::Mesh() Mesh<VertexType, IndexType>::Mesh()
{ {
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
Mesh<VertexType>::~Mesh() Mesh<VertexType, IndexType>::~Mesh()
{ {
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
const std::vector<uint32_t>& Mesh<VertexType>::getIndices(void) const const std::vector<uint32_t>& Mesh<VertexType, IndexType>::getIndices(void) const
{ {
return m_vecTriangleIndices; return m_vecTriangleIndices;
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
uint32_t Mesh<VertexType>::getNoOfIndices(void) const uint32_t Mesh<VertexType, IndexType>::getNoOfIndices(void) const
{ {
return m_vecTriangleIndices.size(); return m_vecTriangleIndices.size();
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
uint32_t Mesh<VertexType>::getNoOfVertices(void) const uint32_t Mesh<VertexType, IndexType>::getNoOfVertices(void) const
{ {
return m_vecVertices.size(); return m_vecVertices.size();
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
const std::vector<VertexType>& Mesh<VertexType>::getVertices(void) const const std::vector<VertexType>& Mesh<VertexType, IndexType>::getVertices(void) const
{ {
return m_vecVertices; return m_vecVertices;
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
const Vector3DInt32& Mesh<VertexType>::getOffset(void) const const Vector3DInt32& Mesh<VertexType, IndexType>::getOffset(void) const
{ {
return m_offset; return m_offset;
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
void Mesh<VertexType>::setOffset(const Vector3DInt32& offset) void Mesh<VertexType, IndexType>::setOffset(const Vector3DInt32& offset)
{ {
m_offset = offset; m_offset = offset;
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
void Mesh<VertexType>::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2) void Mesh<VertexType, IndexType>::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
{ {
//Make sure the specified indices correspond to valid vertices. //Make sure the specified indices correspond to valid vertices.
POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex."); POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex.");
@ -82,28 +82,28 @@ namespace PolyVox
m_vecTriangleIndices.push_back(index2); m_vecTriangleIndices.push_back(index2);
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
uint32_t Mesh<VertexType>::addVertex(const VertexType& vertex) uint32_t Mesh<VertexType, IndexType>::addVertex(const VertexType& vertex)
{ {
m_vecVertices.push_back(vertex); m_vecVertices.push_back(vertex);
return m_vecVertices.size() - 1; return m_vecVertices.size() - 1;
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
void Mesh<VertexType>::clear(void) void Mesh<VertexType, IndexType>::clear(void)
{ {
m_vecVertices.clear(); m_vecVertices.clear();
m_vecTriangleIndices.clear(); m_vecTriangleIndices.clear();
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
bool Mesh<VertexType>::isEmpty(void) const bool Mesh<VertexType, IndexType>::isEmpty(void) const
{ {
return (getNoOfVertices() == 0) || (getNoOfIndices() == 0); return (getNoOfVertices() == 0) || (getNoOfIndices() == 0);
} }
template <typename VertexType> template <typename VertexType, typename IndexType>
void Mesh<VertexType>::removeUnusedVertices(void) void Mesh<VertexType, IndexType>::removeUnusedVertices(void)
{ {
std::vector<bool> isVertexUsed(m_vecVertices.size()); std::vector<bool> isVertexUsed(m_vecVertices.size());
std::fill(isVertexUsed.begin(), isVertexUsed.end(), false); std::fill(isVertexUsed.begin(), isVertexUsed.end(), false);

View File

@ -108,6 +108,11 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class LargeVolume; template <typename VoxelType> class LargeVolume;
////////////////////////////////////////////////////////////////////////////////
// MarchingCubesSurfaceExtractor
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename Controller> class MarchingCubesSurfaceExtractor;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// MarchingCubesVertex // MarchingCubesVertex
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -134,6 +139,11 @@ 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;
////////////////////////////////////////////////////////////////////////////////
// Mesh
////////////////////////////////////////////////////////////////////////////////
template <typename VertexType, typename IndexType> class Mesh;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Pager // Pager
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -154,16 +164,6 @@ namespace PolyVox
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template <typename VoxelType> class SimpleVolume; template <typename VoxelType> class SimpleVolume;
////////////////////////////////////////////////////////////////////////////////
// MarchingCubesSurfaceExtractor
////////////////////////////////////////////////////////////////////////////////
template<typename VolumeType, typename Controller> class MarchingCubesSurfaceExtractor;
////////////////////////////////////////////////////////////////////////////////
// Mesh
////////////////////////////////////////////////////////////////////////////////
template <typename VertexType> class Mesh;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Vector // Vector
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////