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:
		| @@ -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.   | ||||
| 	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| 	template<typename VolumeType, typename IsQuadNeeded> | ||||
| 	template<typename VolumeType, typename MeshType, typename IsQuadNeeded> | ||||
| 	class CubicSurfaceExtractor | ||||
| 	{ | ||||
| 		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 | ||||
| 		// 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) | ||||
| 		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 | ||||
| 		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 | ||||
|  | ||||
|  | ||||
| @@ -172,7 +172,7 @@ namespace PolyVox | ||||
| 		Region m_regSizeInVoxels; | ||||
|  | ||||
| 		//The surface patch we are currently filling. | ||||
| 		Mesh<CubicVertex<typename VolumeType::VoxelType> >* m_meshCurrent; | ||||
| 		MeshType* m_meshCurrent; | ||||
|  | ||||
| 		//Used to avoid creating duplicate vertices. | ||||
| 		Array<3, IndexAndMaterial> m_previousSliceVertices; | ||||
| @@ -198,8 +198,9 @@ namespace PolyVox | ||||
| 	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> > result; | ||||
| 		CubicSurfaceExtractor<VolumeType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded); | ||||
| 		typedef Mesh<CubicVertex<typename VolumeType::VoxelType> > MeshType; | ||||
| 		MeshType result; | ||||
| 		CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded> extractor(volData, region, &result, eWrapMode, tBorderValue, bMergeQuads, isQuadNeeded); | ||||
| 		extractor.execute(); | ||||
| 		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. | ||||
| 	// The vertex position at the center of this group is then going to be used by all eight voxels all with different | ||||
| 	// materials. | ||||
| 	template<typename VolumeType, typename IsQuadNeeded> | ||||
| 	const uint32_t CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::MaxVerticesPerPosition = 8; | ||||
| 	template<typename VolumeType, typename MeshType, typename IsQuadNeeded> | ||||
| 	const uint32_t CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::MaxVerticesPerPosition = 8; | ||||
|  | ||||
| 	template<typename VolumeType, 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) | ||||
| 	template<typename VolumeType, typename MeshType, typename 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_regSizeInVoxels(region) | ||||
| 		,m_meshCurrent(result) | ||||
| @@ -53,8 +53,8 @@ namespace PolyVox | ||||
| 		POLYVOX_THROW_IF(region.getDepthInVoxels() > maxReionDimension, std::invalid_argument, "Requested extraction region exceeds maximum dimensions"); | ||||
| 	} | ||||
|  | ||||
| 	template<typename VolumeType, typename IsQuadNeeded> | ||||
| 	void CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::execute() | ||||
| 	template<typename VolumeType, typename MeshType, typename IsQuadNeeded> | ||||
| 	void CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::execute() | ||||
| 	{ | ||||
| 		Timer timer; | ||||
| 		m_meshCurrent->clear(); | ||||
| @@ -204,8 +204,8 @@ namespace PolyVox | ||||
| 			<< "x" << m_regSizeInVoxels.getDepthInVoxels() << ")"); | ||||
| 	} | ||||
|  | ||||
| 	template<typename VolumeType, 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) | ||||
| 	template<typename VolumeType, typename MeshType, typename IsQuadNeeded> | ||||
| 	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++) | ||||
| 		{ | ||||
| @@ -236,8 +236,8 @@ namespace PolyVox | ||||
| 		return -1; //Should never happen. | ||||
| 	} | ||||
|  | ||||
| 	template<typename VolumeType, typename IsQuadNeeded> | ||||
| 	bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads) | ||||
| 	template<typename VolumeType, typename MeshType, typename IsQuadNeeded> | ||||
| 	bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::performQuadMerging(std::list<Quad>& quads) | ||||
| 	{ | ||||
| 		bool bDidMerge = false; | ||||
| 		for(typename std::list<Quad>::iterator outerIter = quads.begin(); outerIter != quads.end(); outerIter++) | ||||
| @@ -266,8 +266,8 @@ namespace PolyVox | ||||
| 		return bDidMerge; | ||||
| 	} | ||||
|  | ||||
| 	template<typename VolumeType, typename IsQuadNeeded> | ||||
| 	bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2) | ||||
| 	template<typename VolumeType, typename MeshType, typename IsQuadNeeded> | ||||
| 	bool CubicSurfaceExtractor<VolumeType, MeshType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2) | ||||
| 	{ | ||||
| 		//All four vertices of a given quad have the same data, | ||||
| 		//so just check that the first pair of vertices match. | ||||
|   | ||||
| @@ -49,16 +49,16 @@ namespace PolyVox | ||||
| 		Mesh(); | ||||
| 		~Mesh();	    | ||||
|  | ||||
| 		const std::vector<uint32_t>& getIndices(void) const; | ||||
| 		const std::vector<IndexType>& getIndices(void) const; | ||||
| 		uint32_t getNoOfIndices(void) const; | ||||
| 		uint32_t getNoOfVertices(void) const; | ||||
| 		IndexType getNoOfVertices(void) const; | ||||
| 		const std::vector<VertexType>& getVertices(void) const; | ||||
| 		const Vector3DInt32& getOffset(void) const; | ||||
|  | ||||
| 		void setOffset(const Vector3DInt32& offset); | ||||
|  | ||||
| 		void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2); | ||||
| 		uint32_t addVertex(const VertexType& vertex); | ||||
| 		void addTriangle(IndexType index0, IndexType index1, IndexType index2); | ||||
| 		IndexType addVertex(const VertexType& vertex); | ||||
| 		void clear(void); | ||||
| 		bool isEmpty(void) const; | ||||
| 		void removeUnusedVertices(void); | ||||
| @@ -66,17 +66,17 @@ namespace PolyVox | ||||
| 		Vector3DInt32 m_offset; | ||||
| 	 | ||||
| 	public:		 | ||||
| 		std::vector<uint32_t> m_vecTriangleIndices; | ||||
| 		std::vector<IndexType> m_vecTriangleIndices; | ||||
| 		std::vector<VertexType> m_vecVertices; | ||||
| 	}; | ||||
|  | ||||
| 	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()); | ||||
|  | ||||
| 		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]); | ||||
| 		} | ||||
|   | ||||
| @@ -34,7 +34,7 @@ namespace PolyVox | ||||
| 	} | ||||
|  | ||||
| 	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; | ||||
| 	} | ||||
| @@ -46,7 +46,7 @@ namespace PolyVox | ||||
| 	} | ||||
|  | ||||
| 	template <typename VertexType, typename IndexType> | ||||
| 	uint32_t Mesh<VertexType, IndexType>::getNoOfVertices(void) const | ||||
| 	IndexType Mesh<VertexType, IndexType>::getNoOfVertices(void) const | ||||
| 	{ | ||||
| 		return m_vecVertices.size(); | ||||
| 	} | ||||
| @@ -70,7 +70,7 @@ namespace PolyVox | ||||
| 	} | ||||
|  | ||||
| 	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. | ||||
| 		POLYVOX_ASSERT(index0 < m_vecVertices.size(), "Index points at an invalid vertex."); | ||||
| @@ -83,7 +83,7 @@ namespace PolyVox | ||||
| 	} | ||||
|  | ||||
| 	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); | ||||
| 		return m_vecVertices.size() - 1; | ||||
| @@ -116,7 +116,7 @@ namespace PolyVox | ||||
|  | ||||
| 		int noOfUsedVertices = 0; | ||||
| 		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]) | ||||
| 			{ | ||||
|   | ||||
| @@ -76,7 +76,7 @@ namespace PolyVox | ||||
| 	// CubicSurfaceExtractor | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user