Work on refactoring voxel types.
Expanded surface extractor test.
This commit is contained in:
		| @@ -98,6 +98,7 @@ namespace PolyVox | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		typedef uint8_t MaterialType; | ||||
| 		static const bool HasDensity = true; | ||||
| 		static const bool HasMaterial = false; | ||||
| 		static bool hasDensity() { return true; } | ||||
|   | ||||
| @@ -108,6 +108,7 @@ namespace PolyVox | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		typedef uint8_t MaterialType; | ||||
| 		static const bool HasDensity = false; | ||||
| 		static const bool HasMaterial = true; | ||||
| 		static bool hasDensity() { return false; } | ||||
|   | ||||
| @@ -91,6 +91,7 @@ namespace PolyVox | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		typedef uint8_t MaterialType; | ||||
| 		static const bool HasDensity = true; | ||||
| 		static const bool HasMaterial = true; | ||||
| 		static bool hasDensity() { return true; } | ||||
| @@ -104,6 +105,7 @@ namespace PolyVox | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		typedef uint8_t MaterialType; | ||||
| 		static const bool HasDensity = true; | ||||
| 		static const bool HasMaterial = true; | ||||
| 		static bool hasDensity() { return true; } | ||||
| @@ -111,12 +113,23 @@ namespace PolyVox | ||||
| 		static MaterialDensityPair88::DensityType minDensity() { return 0; } | ||||
| 		static MaterialDensityPair88::DensityType maxDensity() { return 255; } | ||||
| 	}; | ||||
| } | ||||
|  | ||||
| #include "PolyVoxCore/SurfaceExtractor.h" | ||||
|  | ||||
| namespace PolyVox | ||||
| { | ||||
| 	template<> | ||||
| 	typename VoxelTypeTraits<MaterialDensityPair44>::DensityType convertToDensity(MaterialDensityPair44 voxel); | ||||
|  | ||||
| 	template<> | ||||
| 	typename VoxelTypeTraits<MaterialDensityPair88>::DensityType convertToDensity(MaterialDensityPair88 voxel); | ||||
|  | ||||
| 	template<> | ||||
| 	typename VoxelTypeTraits<MaterialDensityPair44>::MaterialType convertToMaterial(MaterialDensityPair44 voxel); | ||||
|  | ||||
| 	template<> | ||||
| 	typename VoxelTypeTraits<MaterialDensityPair88>::MaterialType convertToMaterial(MaterialDensityPair88 voxel); | ||||
| } | ||||
|  | ||||
| #endif | ||||
| @@ -0,0 +1,34 @@ | ||||
| /******************************************************************************* | ||||
| 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. 	 | ||||
| *******************************************************************************/ | ||||
|  | ||||
| #ifndef __PolyVox_PrimitiveVoxelTypes_H__ | ||||
| #define __PolyVox_PrimitiveVoxelTypes_H__ | ||||
|  | ||||
| #include "PolyVoxCore/Voxel.h" | ||||
|  | ||||
| namespace PolyVox | ||||
| {	 | ||||
| 	 | ||||
| } | ||||
|  | ||||
| #endif //__PolyVox_PrimitiveVoxelTypes_H__ | ||||
| @@ -32,6 +32,26 @@ freely, subject to the following restrictions: | ||||
|  | ||||
| namespace PolyVox | ||||
| { | ||||
| 	template<> | ||||
| 	class VoxelTypeTraits< uint8_t >	 | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		typedef uint8_t MaterialType; | ||||
| 		static const bool HasDensity = true; | ||||
| 		static const bool HasMaterial = false; | ||||
| 		static bool hasDensity() { return true; } | ||||
| 		static bool hasMaterial() { return false; } | ||||
| 		static uint8_t minDensity() { return 0; } | ||||
| 		static uint8_t maxDensity() { return 255; } | ||||
| 	}; | ||||
|  | ||||
| 	template<typename VoxelType> | ||||
| 	typename VoxelTypeTraits<VoxelType>::MaterialType convertToMaterial(VoxelType voxel) | ||||
| 	{ | ||||
| 		return 1; | ||||
| 	} | ||||
|  | ||||
| 	template< template<typename> class VolumeType, typename VoxelType> | ||||
| 	class SurfaceExtractor | ||||
| 	{ | ||||
|   | ||||
| @@ -391,28 +391,6 @@ namespace PolyVox | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	template<typename VoxelType, bool HasMaterialInType = true> | ||||
| 	struct getMaterialFromVoxel; | ||||
|  | ||||
| 	template<typename VoxelType> | ||||
| 	struct getMaterialFromVoxel<VoxelType, true> | ||||
| 	{ | ||||
| 		static uint32_t run(VoxelType voxel) | ||||
| 		{ | ||||
| 			return voxel.getMaterial(); | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	template<typename VoxelType> | ||||
| 	struct getMaterialFromVoxel<VoxelType, false> | ||||
| 	{ | ||||
| 		static uint32_t run(VoxelType voxel) | ||||
| 		{ | ||||
| 			return 0; | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
|  | ||||
| 	template< template<typename> class VolumeType, typename VoxelType> | ||||
| 	void SurfaceExtractor<VolumeType, VoxelType>::generateVerticesForSlice(const Array2DUint8& pCurrentBitmask, | ||||
| 		Array2DInt32& m_pCurrentVertexIndicesX, | ||||
| @@ -465,8 +443,8 @@ namespace PolyVox | ||||
| 					//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 | ||||
| 					//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. | ||||
| 					uint32_t uMaterial000 = getMaterialFromVoxel<VoxelType, VoxelTypeTraits<VoxelType>::HasMaterial>::run(v000); | ||||
| 					uint32_t uMaterial100 = getMaterialFromVoxel<VoxelType, VoxelTypeTraits<VoxelType>::HasMaterial>::run(v100); | ||||
| 					uint32_t uMaterial000 = convertToMaterial(v000); | ||||
| 					uint32_t uMaterial100 = convertToMaterial(v100); | ||||
| 					uint32_t uMaterial = (std::max)(uMaterial000, uMaterial100); | ||||
|  | ||||
| 					PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial)); | ||||
| @@ -491,8 +469,8 @@ namespace PolyVox | ||||
| 					//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 | ||||
| 					//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. | ||||
| 					uint32_t uMaterial000 = getMaterialFromVoxel<VoxelType, VoxelTypeTraits<VoxelType>::HasMaterial>::run(v000); | ||||
| 					uint32_t uMaterial010 = getMaterialFromVoxel<VoxelType, VoxelTypeTraits<VoxelType>::HasMaterial>::run(v010); | ||||
| 					uint32_t uMaterial000 = convertToMaterial(v000); | ||||
| 					uint32_t uMaterial010 = convertToMaterial(v010); | ||||
| 					uint32_t uMaterial = (std::max)(uMaterial000, uMaterial010); | ||||
|  | ||||
| 					PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial)); | ||||
| @@ -517,8 +495,8 @@ namespace PolyVox | ||||
| 					//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 | ||||
| 					//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. | ||||
| 					uint32_t uMaterial000 = getMaterialFromVoxel<VoxelType, VoxelTypeTraits<VoxelType>::HasMaterial>::run(v000); | ||||
| 					uint32_t uMaterial001 = getMaterialFromVoxel<VoxelType, VoxelTypeTraits<VoxelType>::HasMaterial>::run(v001); | ||||
| 					uint32_t uMaterial000 = convertToMaterial(v000); | ||||
| 					uint32_t uMaterial001 = convertToMaterial(v001); | ||||
| 					uint32_t uMaterial = (std::max)(uMaterial000, uMaterial001); | ||||
|  | ||||
| 					PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast<float>(uMaterial)); | ||||
|   | ||||
| @@ -47,6 +47,7 @@ namespace PolyVox | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		typedef uint8_t MaterialType; | ||||
| 		static const bool HasDensity = false; | ||||
| 		static const bool HasMaterial = false; | ||||
|  | ||||
| @@ -66,19 +67,6 @@ namespace PolyVox | ||||
| 	{ | ||||
| 		return voxel; | ||||
| 	} | ||||
|  | ||||
| 	template<> | ||||
| 	class VoxelTypeTraits< uint8_t >	 | ||||
| 	{ | ||||
| 	public: | ||||
| 		typedef uint8_t DensityType; | ||||
| 		static const bool HasDensity = true; | ||||
| 		static const bool HasMaterial = false; | ||||
| 		static bool hasDensity() { return true; } | ||||
| 		static bool hasMaterial() { return false; } | ||||
| 		static uint8_t minDensity() { return 0; } | ||||
| 		static uint8_t maxDensity() { return 255; } | ||||
| 	}; | ||||
| } | ||||
|  | ||||
| #endif //__PolyVox_Voxel_H__ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user