More work to make Mesh be templatized on IndexType.
This requires making the SurfaceExtractor classes be templatised on MeshType (at least for now - maybe there is a better approach when working with free functions). This has been partially done for CubicSurfaceExtractor.
This commit is contained in:
parent
ffdf606ad6
commit
06540d6c97
@ -113,7 +113,7 @@ namespace PolyVox
|
|||||||
///
|
///
|
||||||
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
|
/// Another scenario which sometimes results in confusion is when you wish to extract a region which corresponds to the whole volume, partcularly when solid voxels extend right to the edge of the volume.
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
class CubicSurfaceExtractor
|
class CubicSurfaceExtractor
|
||||||
{
|
{
|
||||||
struct IndexAndMaterial
|
struct IndexAndMaterial
|
||||||
@ -150,9 +150,9 @@ namespace PolyVox
|
|||||||
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
|
// This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template
|
||||||
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
|
// Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC?
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
CubicSurfaceExtractor(VolumeType* volData, Region region, Mesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||||
#else
|
#else
|
||||||
CubicSurfaceExtractor(VolumeType* volData, Region region, Mesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ namespace PolyVox
|
|||||||
Region m_regSizeInVoxels;
|
Region m_regSizeInVoxels;
|
||||||
|
|
||||||
//The surface patch we are currently filling.
|
//The surface patch we are currently filling.
|
||||||
Mesh<CubicVertex<typename VolumeType::VoxelType> >* m_meshCurrent;
|
MeshType* m_meshCurrent;
|
||||||
|
|
||||||
//Used to avoid creating duplicate vertices.
|
//Used to avoid creating duplicate vertices.
|
||||||
Array<3, IndexAndMaterial> m_previousSliceVertices;
|
Array<3, IndexAndMaterial> m_previousSliceVertices;
|
||||||
@ -198,8 +198,9 @@ namespace PolyVox
|
|||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename IsQuadNeeded>
|
||||||
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
Mesh<CubicVertex<typename VolumeType::VoxelType> > extractCubicMesh(VolumeType* volData, Region region, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||||
{
|
{
|
||||||
Mesh<CubicVertex<typename VolumeType::VoxelType> > result;
|
typedef Mesh<CubicVertex<typename VolumeType::VoxelType> > MeshType;
|
||||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded);
|
MeshType result;
|
||||||
|
CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded);
|
||||||
extractor.execute();
|
extractor.execute();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,11 @@ namespace PolyVox
|
|||||||
// happens when we have a 2x2x2 group of voxels, all with different materials and some/all partially transparent.
|
// happens when we have a 2x2x2 group of voxels, all with different materials and some/all partially transparent.
|
||||||
// The vertex position at the center of this group is then going to be used by all eight voxels all with different
|
// The vertex position at the center of this group is then going to be used by all eight voxels all with different
|
||||||
// materials.
|
// materials.
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
|
const uint32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::MaxVerticesPerPosition = 8;
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, Mesh<CubicVertex<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::CubicSurfaceExtractor(VolumeType* volData, Region region, MeshType* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded)
|
||||||
:m_volData(volData)
|
:m_volData(volData)
|
||||||
,m_regSizeInVoxels(region)
|
,m_regSizeInVoxels(region)
|
||||||
,m_meshCurrent(result)
|
,m_meshCurrent(result)
|
||||||
@ -53,8 +53,8 @@ namespace PolyVox
|
|||||||
POLYVOX_THROW_IF(region.getDepthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
|
POLYVOX_THROW_IF(region.getDepthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
void CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::execute()
|
void CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::execute()
|
||||||
{
|
{
|
||||||
Timer timer;
|
Timer timer;
|
||||||
m_meshCurrent->clear();
|
m_meshCurrent->clear();
|
||||||
@ -204,8 +204,8 @@ namespace PolyVox
|
|||||||
<< "x" << m_regSizeInVoxels.getDepthInVoxels() << ")");
|
<< "x" << m_regSizeInVoxels.getDepthInVoxels() << ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
int32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
int32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::addVertex(uint32_t uX, uint32_t uY, uint32_t uZ, typename VolumeType::VoxelType uMaterialIn, Array<3, IndexAndMaterial>& existingVertices)
|
||||||
{
|
{
|
||||||
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
|
for(uint32_t ct = 0; ct < MaxVerticesPerPosition; ct++)
|
||||||
{
|
{
|
||||||
@ -236,8 +236,8 @@ namespace PolyVox
|
|||||||
return -1; //Should never happen.
|
return -1; //Should never happen.
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads)
|
bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads)
|
||||||
{
|
{
|
||||||
bool bDidMerge = false;
|
bool bDidMerge = false;
|
||||||
for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++)
|
for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++)
|
||||||
@ -266,8 +266,8 @@ namespace PolyVox
|
|||||||
return bDidMerge;
|
return bDidMerge;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename VolumeType, typename IsQuadNeeded>
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded>
|
||||||
bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2)
|
bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2)
|
||||||
{
|
{
|
||||||
//All four vertices of a given quad have the same data,
|
//All four vertices of a given quad have the same data,
|
||||||
//so just check that the first pair of vertices match.
|
//so just check that the first pair of vertices match.
|
||||||
|
@ -49,16 +49,16 @@ namespace PolyVox
|
|||||||
Mesh();
|
Mesh();
|
||||||
~Mesh();
|
~Mesh();
|
||||||
|
|
||||||
const std::vector<uint32_t>& getIndices(void) const;
|
const std::vector<IndexType>& getIndices(void) const;
|
||||||
uint32_t getNoOfIndices(void) const;
|
uint32_t getNoOfIndices(void) const;
|
||||||
uint32_t getNoOfVertices(void) const;
|
IndexType getNoOfVertices(void) const;
|
||||||
const std::vector<VertexType>& getVertices(void) const;
|
const std::vector<VertexType>& getVertices(void) const;
|
||||||
const Vector3DInt32& getOffset(void) const;
|
const Vector3DInt32& getOffset(void) const;
|
||||||
|
|
||||||
void setOffset(const Vector3DInt32& offset);
|
void setOffset(const Vector3DInt32& offset);
|
||||||
|
|
||||||
void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2);
|
void addTriangle(IndexType index0, IndexType index1, IndexType index2);
|
||||||
uint32_t addVertex(const VertexType& vertex);
|
IndexType addVertex(const VertexType& vertex);
|
||||||
void clear(void);
|
void clear(void);
|
||||||
bool isEmpty(void) const;
|
bool isEmpty(void) const;
|
||||||
void removeUnusedVertices(void);
|
void removeUnusedVertices(void);
|
||||||
@ -66,17 +66,17 @@ namespace PolyVox
|
|||||||
Vector3DInt32 m_offset;
|
Vector3DInt32 m_offset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<uint32_t> m_vecTriangleIndices;
|
std::vector<IndexType> m_vecTriangleIndices;
|
||||||
std::vector<VertexType> m_vecVertices;
|
std::vector<VertexType> m_vecVertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename MeshType>
|
template <typename MeshType>
|
||||||
Mesh< Vertex< typename MeshType::VertexType::DataType > > decode(const MeshType& mesh)
|
Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > decode(const MeshType& mesh)
|
||||||
{
|
{
|
||||||
Mesh< Vertex< typename MeshType::VertexType::DataType > > result;
|
Mesh< Vertex< typename MeshType::VertexType::DataType >, typename MeshType::IndexType > result;
|
||||||
result.m_vecVertices.resize(mesh.m_vecVertices.size());
|
result.m_vecVertices.resize(mesh.m_vecVertices.size());
|
||||||
|
|
||||||
for(uint32_t ct = 0; ct < mesh.m_vecVertices.size(); ct++)
|
for(MeshType::IndexType ct = 0; ct < mesh.m_vecVertices.size(); ct++)
|
||||||
{
|
{
|
||||||
result.m_vecVertices[ct] = decode(mesh.m_vecVertices[ct]);
|
result.m_vecVertices[ct] = decode(mesh.m_vecVertices[ct]);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType, typename IndexType>
|
template <typename VertexType, typename IndexType>
|
||||||
const std::vector<uint32_t>& Mesh<VertexType, IndexType>::getIndices(void) const
|
const std::vector<IndexType>& Mesh<VertexType, IndexType>::getIndices(void) const
|
||||||
{
|
{
|
||||||
return m_vecTriangleIndices;
|
return m_vecTriangleIndices;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType, typename IndexType>
|
template <typename VertexType, typename IndexType>
|
||||||
uint32_t Mesh<VertexType, IndexType>::getNoOfVertices(void) const
|
IndexType Mesh<VertexType, IndexType>::getNoOfVertices(void) const
|
||||||
{
|
{
|
||||||
return m_vecVertices.size();
|
return m_vecVertices.size();
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType, typename IndexType>
|
template <typename VertexType, typename IndexType>
|
||||||
void Mesh<VertexType, IndexType>::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
|
void Mesh<VertexType, IndexType>::addTriangle(IndexType index0, IndexType index1, IndexType 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.");
|
||||||
@ -83,7 +83,7 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename VertexType, typename IndexType>
|
template <typename VertexType, typename IndexType>
|
||||||
uint32_t Mesh<VertexType, IndexType>::addVertex(const VertexType& vertex)
|
IndexType 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;
|
||||||
@ -116,7 +116,7 @@ namespace PolyVox
|
|||||||
|
|
||||||
int noOfUsedVertices = 0;
|
int noOfUsedVertices = 0;
|
||||||
std::vector<uint32_t> newPos(m_vecVertices.size());
|
std::vector<uint32_t> newPos(m_vecVertices.size());
|
||||||
for(uint32_t vertCt = 0; vertCt < m_vecVertices.size(); vertCt++)
|
for(IndexType vertCt = 0; vertCt < m_vecVertices.size(); vertCt++)
|
||||||
{
|
{
|
||||||
if(isVertexUsed[vertCt])
|
if(isVertexUsed[vertCt])
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,7 @@ namespace PolyVox
|
|||||||
// CubicSurfaceExtractor
|
// CubicSurfaceExtractor
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template<typename VoxelType> class DefaultIsQuadNeeded;
|
template<typename VoxelType> class DefaultIsQuadNeeded;
|
||||||
template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> > class CubicSurfaceExtractor;
|
template<typename VolumeType, typename MeshType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> > class CubicSurfaceExtractor;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// CubicVertex
|
// CubicVertex
|
||||||
|
Loading…
x
Reference in New Issue
Block a user