Making Cubiquity version of PolyVox more closely match develop version.
This commit is contained in:
		| @@ -118,6 +118,7 @@ namespace PolyVox | ||||
| 		CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh<PositionMaterial<typename VolumeType::VoxelType> >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); | ||||
| #endif | ||||
|  | ||||
|  | ||||
| 		void execute();		 | ||||
|  | ||||
| 	private: | ||||
|   | ||||
| @@ -43,16 +43,16 @@ namespace PolyVox | ||||
| 		Timer timer; | ||||
| 		m_meshCurrent->clear(); | ||||
|  | ||||
| 		for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++) | ||||
| 		for(int32_t z = m_regSizeInVoxels.getLowerZ(); z < m_regSizeInVoxels.getUpperZ(); z++) | ||||
| 		{ | ||||
| 			for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++) | ||||
| 			for(int32_t y = m_regSizeInVoxels.getLowerY(); y < m_regSizeInVoxels.getUpperY(); y++) | ||||
| 			{ | ||||
| 				for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++) | ||||
| 				for(int32_t x = m_regSizeInVoxels.getLowerX(); x < m_regSizeInVoxels.getUpperX(); x++) | ||||
| 				{ | ||||
| 					// these are always positive anyway | ||||
| 					float regX = static_cast<float>(x - m_regSizeInVoxels.getLowerCorner().getX()); | ||||
| 					float regY = static_cast<float>(y - m_regSizeInVoxels.getLowerCorner().getY()); | ||||
| 					float regZ = static_cast<float>(z - m_regSizeInVoxels.getLowerCorner().getZ()); | ||||
| 					float regX = static_cast<float>(x - m_regSizeInVoxels.getLowerX()); | ||||
| 					float regY = static_cast<float>(y - m_regSizeInVoxels.getLowerY()); | ||||
| 					float regZ = static_cast<float>(z - m_regSizeInVoxels.getLowerZ()); | ||||
|  | ||||
| 					uint32_t material = 0; | ||||
|  | ||||
|   | ||||
| @@ -32,11 +32,11 @@ namespace PolyVox | ||||
| 	class DefaultIsQuadNeeded | ||||
| 	{ | ||||
| 	public: | ||||
| 		bool operator()(VoxelType back, VoxelType front, float& materialToUse) | ||||
| 		bool operator()(VoxelType back, VoxelType front, uint32_t& materialToUse) | ||||
| 		{ | ||||
| 			if((back > 0) && (front == 0)) | ||||
| 			{ | ||||
| 				materialToUse = static_cast<float>(back); | ||||
| 				materialToUse = static_cast<uint32_t>(back); | ||||
| 				return true; | ||||
| 			} | ||||
| 			else | ||||
|   | ||||
| @@ -15,7 +15,7 @@ | ||||
| // is a recent version) then assume support for these. | ||||
| #if !defined(_MSC_VER) || (_MSC_VER >= 1600) | ||||
| 	#define HAS_CXX11_CONSTEXPR | ||||
| 	//#define HAS_CXX11_STATIC_ASSERT //This seems to cause issues on Android. | ||||
| 	#define HAS_CXX11_STATIC_ASSERT | ||||
| 	#define HAS_CXX11_CSTDINT_H | ||||
| 	#define HAS_CXX11_SHARED_PTR | ||||
| #endif | ||||
|   | ||||
| @@ -52,8 +52,6 @@ namespace PolyVox | ||||
| 	{ | ||||
| 		return (std::min)(high, (std::max)(low, value)); | ||||
| 	} | ||||
|  | ||||
| 	float triangleFilter(float fInput); | ||||
| } | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -461,7 +461,6 @@ namespace PolyVox | ||||
| 					//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. | ||||
| 					const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000); | ||||
| 					const typename Controller::MaterialType uMaterial100 = m_controller.convertToMaterial(v100); | ||||
| 					//const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial100); | ||||
| 					const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial100, fInterp); | ||||
|  | ||||
| 					const PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial); | ||||
| @@ -495,7 +494,6 @@ namespace PolyVox | ||||
| 					//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. | ||||
| 					const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000); | ||||
| 					const typename Controller::MaterialType uMaterial010 = m_controller.convertToMaterial(v010); | ||||
| 					//const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial010); | ||||
| 					const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial010, fInterp); | ||||
|  | ||||
| 					PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial); | ||||
| @@ -528,7 +526,6 @@ namespace PolyVox | ||||
| 					//volume we get the one which is non-zero. Both materials can be non-zero if our volume has a density component. | ||||
| 					const typename Controller::MaterialType uMaterial000 = m_controller.convertToMaterial(v000); | ||||
| 					const typename Controller::MaterialType uMaterial001 = m_controller.convertToMaterial(v001); | ||||
| 					//const typename Controller::MaterialType uMaterial = (std::max)(uMaterial000, uMaterial001); | ||||
| 					const typename Controller::MaterialType uMaterial = m_controller.blendMaterials(uMaterial000, uMaterial001, fInterp); | ||||
|  | ||||
| 					const PositionMaterialNormal<typename Controller::MaterialType> surfaceVertex(v3dPosition, v3dNormal, uMaterial); | ||||
| @@ -640,4 +637,4 @@ namespace PolyVox | ||||
| 			}//For each cell | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -141,21 +141,21 @@ namespace PolyVox | ||||
| 		/// Tests whether the given point is contained in this Region. | ||||
| 		bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const; | ||||
| 		/// Tests whether the given point is contained in this Region. | ||||
| 		bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, int8_t boundary = 0) const; | ||||
| 		bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary = 0) const; | ||||
| 		/// Tests whether the given point is contained in this Region. | ||||
| 		bool containsPoint(const Vector3DInt32& pos, int8_t boundary = 0) const; | ||||
| 		bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const; | ||||
| 		/// Tests whether the given position is contained in the 'x' range of this Region. | ||||
| 		bool containsPointInX(float pos, float boundary = 0.0f) const; | ||||
| 		/// Tests whether the given position is contained in the 'x' range of this Region. | ||||
| 		bool containsPointInX(int32_t pos, int8_t boundary = 0) const; | ||||
| 		bool containsPointInX(int32_t pos, uint8_t boundary = 0) const; | ||||
| 		/// Tests whether the given position is contained in the 'y' range of this Region. | ||||
| 		bool containsPointInY(float pos, float boundary = 0.0f) const; | ||||
| 		/// Tests whether the given position is contained in the 'y' range of this Region. | ||||
| 		bool containsPointInY(int32_t pos, int8_t boundary = 0) const; | ||||
| 		bool containsPointInY(int32_t pos, uint8_t boundary = 0) const; | ||||
| 		/// Tests whether the given position is contained in the 'z' range of this Region. | ||||
| 		bool containsPointInZ(float pos, float boundary = 0.0f) const; | ||||
| 		/// Tests whether the given position is contained in the 'z' range of this Region. | ||||
| 		bool containsPointInZ(int32_t pos, int8_t boundary = 0) const; | ||||
| 		bool containsPointInZ(int32_t pos, uint8_t boundary = 0) const; | ||||
|  | ||||
| 		/// Tests whether the given Region is contained in this Region. | ||||
| 		bool containsRegion(const Region& reg, uint8_t boundary = 0) const; | ||||
|   | ||||
| @@ -95,8 +95,8 @@ namespace PolyVox | ||||
| 		std::vector<LodRecord> m_vecLodRecords; | ||||
| 	};	 | ||||
|  | ||||
| 	/*template <typename VertexType> | ||||
| 	polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(SurfaceMesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials);*/ | ||||
| 	template <typename VertexType> | ||||
| 	polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(SurfaceMesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials); | ||||
| } | ||||
|  | ||||
| #include "PolyVoxCore/SurfaceMesh.inl" | ||||
|   | ||||
| @@ -394,7 +394,7 @@ namespace PolyVox | ||||
| 	} | ||||
|  | ||||
| 	//Currently a free function - think where this needs to go. | ||||
| 	/*template <typename VertexType> | ||||
| 	template <typename VertexType> | ||||
| 	polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(SurfaceMesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials) | ||||
| 	{ | ||||
| 		polyvox_shared_ptr< SurfaceMesh<VertexType> > result(new SurfaceMesh<VertexType>); | ||||
| @@ -460,7 +460,7 @@ namespace PolyVox | ||||
| 		result->m_vecLodRecords.push_back(lodRecord); | ||||
|  | ||||
| 		return result; | ||||
| 	}*/ | ||||
| 	} | ||||
|  | ||||
| 	template <typename VertexType> | ||||
| 	void SurfaceMesh<VertexType>::scaleVertices(float amount) | ||||
|   | ||||
| @@ -28,9 +28,6 @@ freely, subject to the following restrictions: | ||||
|  | ||||
| namespace PolyVox | ||||
| { | ||||
| 	template<typename VolumeType> | ||||
| 	typename VolumeType::VoxelType interpolatedSample(VolumeType* pVolume, float fPosX, float fPosY, float fPosZ, WrapMode eWrapMode, typename VolumeType::VoxelType tBorder); | ||||
|  | ||||
| 	template< typename SrcVolumeType, typename DstVolumeType> | ||||
| 	class VolumeResampler | ||||
| 	{ | ||||
| @@ -42,7 +39,6 @@ namespace PolyVox | ||||
| 	private: | ||||
| 		void resampleSameSize(); | ||||
| 		void resampleArbitrary(); | ||||
| 		void resampleBetter(); | ||||
|  | ||||
| 		//Source data | ||||
| 		SrcVolumeType* m_pVolSrc; | ||||
|   | ||||
| @@ -23,43 +23,10 @@ freely, subject to the following restrictions: | ||||
|  | ||||
| #include "PolyVoxCore/Interpolation.h" | ||||
|  | ||||
| #include "PolyVoxCore/Impl/Utility.h" | ||||
|  | ||||
| #include <cmath> | ||||
|  | ||||
| namespace PolyVox | ||||
| { | ||||
| 	// Takes an interpolated sample of the volume data. | ||||
| 	template<typename VolumeType> | ||||
| 	typename VolumeType::VoxelType interpolatedSample(VolumeType* pVolume, float fPosX, float fPosY, float fPosZ, WrapMode eWrapMode, typename VolumeType::VoxelType tBorder) | ||||
| 	{ | ||||
| 		float fFloorX = floor(fPosX); | ||||
| 		float fFloorY = floor(fPosY); | ||||
| 		float fFloorZ = floor(fPosZ); | ||||
|  | ||||
| 		float fInterpX = fPosX - fFloorX; | ||||
| 		float fInterpY = fPosY - fFloorY; | ||||
| 		float fInterpZ = fPosZ - fFloorZ; | ||||
|  | ||||
| 		// Conditional logic required to round negative floats correctly | ||||
| 		int32_t iX = static_cast<int32_t>(fFloorX > 0.0f ? fFloorX + 0.5f : fFloorX - 0.5f);  | ||||
| 		int32_t iY = static_cast<int32_t>(fFloorY > 0.0f ? fFloorY + 0.5f : fFloorY - 0.5f);  | ||||
| 		int32_t iZ = static_cast<int32_t>(fFloorZ > 0.0f ? fFloorZ + 0.5f : fFloorZ - 0.5f); | ||||
|  | ||||
| 		const typename VolumeType::VoxelType& voxel000 = pVolume->getVoxelWithWrapping(iX, iY, iZ, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel001 = pVolume->getVoxelWithWrapping(iX, iY, iZ + 1, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel010 = pVolume->getVoxelWithWrapping(iX, iY + 1, iZ, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel011 = pVolume->getVoxelWithWrapping(iX, iY + 1, iZ + 1, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel100 = pVolume->getVoxelWithWrapping(iX + 1, iY, iZ, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel101 = pVolume->getVoxelWithWrapping(iX + 1, iY, iZ + 1, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel110 = pVolume->getVoxelWithWrapping(iX + 1, iY + 1, iZ, eWrapMode, tBorder); | ||||
| 		const typename VolumeType::VoxelType& voxel111 = pVolume->getVoxelWithWrapping(iX + 1, iY + 1, iZ + 1, eWrapMode, tBorder); | ||||
|  | ||||
| 		typename VolumeType::VoxelType tInterpolatedValue = PolyVox::trilerp(voxel000,voxel100,voxel010,voxel110,voxel001,voxel101,voxel011,voxel111,fInterpX,fInterpY,fInterpZ); | ||||
|  | ||||
| 		return tInterpolatedValue; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * \param pVolSrc | ||||
| 	 * \param regSrc | ||||
| @@ -86,16 +53,14 @@ namespace PolyVox | ||||
| 		int32_t uDstHeight = m_regDst.getUpperY() - m_regDst.getLowerY() + 1; | ||||
| 		int32_t uDstDepth = m_regDst.getUpperZ() - m_regDst.getLowerZ() + 1; | ||||
|  | ||||
| 		/*if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth)) | ||||
| 		if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth)) | ||||
| 		{ | ||||
| 			resampleSameSize(); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			resampleArbitrary(); | ||||
| 		}*/ | ||||
|  | ||||
| 		resampleBetter(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	template< typename SrcVolumeType, typename DstVolumeType> | ||||
| @@ -162,7 +127,7 @@ namespace PolyVox | ||||
| 					sy = modf(sy, &dummy); | ||||
| 					sz = modf(sz, &dummy); | ||||
|  | ||||
| 					typename SrcVolumeType::VoxelType tInterpolatedValue = trilerp(voxel000,voxel100,voxel010,voxel110,voxel001,voxel101,voxel011,voxel111,sx,sy,sz); | ||||
| 					typename SrcVolumeType::VoxelType tInterpolatedValue = trilerp<float>(voxel000,voxel100,voxel010,voxel110,voxel001,voxel101,voxel011,voxel111,sx,sy,sz); | ||||
|  | ||||
| 					typename DstVolumeType::VoxelType result = static_cast<typename DstVolumeType::VoxelType>(tInterpolatedValue); | ||||
| 					m_pVolDst->setVoxelAt(dx,dy,dz,result); | ||||
| @@ -170,108 +135,4 @@ namespace PolyVox | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	template< typename SrcVolumeType, typename DstVolumeType> | ||||
| 	void VolumeResampler<SrcVolumeType, DstVolumeType>::resampleBetter() | ||||
| 	{ | ||||
| 		float srcWidth  = m_regSrc.getWidthInCells(); | ||||
| 		float srcHeight = m_regSrc.getHeightInCells(); | ||||
| 		float srcDepth  = m_regSrc.getDepthInCells(); | ||||
|  | ||||
| 		float dstWidth  = m_regDst.getWidthInCells(); | ||||
| 		float dstHeight = m_regDst.getHeightInCells(); | ||||
| 		float dstDepth  = m_regDst.getDepthInCells(); | ||||
| 		 | ||||
| 		float fScaleX = srcWidth / dstWidth; | ||||
| 		float fScaleY = srcHeight / dstHeight; | ||||
| 		float fScaleZ = srcDepth / dstDepth; | ||||
|  | ||||
| 		typename SrcVolumeType::Sampler sampler(m_pVolSrc); | ||||
| 		 | ||||
| 		// Should use SrcVolumeType? Or new template parameter? | ||||
| 		Region regDownscaledX(0, 0, 0, m_regDst.getWidthInVoxels()-1, m_regSrc.getHeightInVoxels()-1, m_regSrc.getDepthInVoxels()-1); | ||||
| 		SrcVolumeType volDownscaledX(regDownscaledX); | ||||
|  | ||||
| 		for(int32_t tz = regDownscaledX.getLowerZ(); tz <= regDownscaledX.getUpperZ(); tz++) | ||||
| 		{ | ||||
| 			for(int32_t ty = regDownscaledX.getLowerY(); ty <= regDownscaledX.getUpperY(); ty++) | ||||
| 			{ | ||||
| 				for(int32_t tx = regDownscaledX.getLowerX(); tx <= regDownscaledX.getUpperX(); tx++) | ||||
| 				{ | ||||
| 					float sx = (tx * fScaleX) + m_regSrc.getLowerCorner().getX(); | ||||
| 					float sy = (ty          ) + m_regSrc.getLowerCorner().getY(); | ||||
| 					float sz = (tz          ) + m_regSrc.getLowerCorner().getZ(); | ||||
|  | ||||
| 					typename SrcVolumeType::VoxelType result = m_pVolSrc->getVoxelWithWrapping(sx, sy, sz, WrapModes::Border); | ||||
|  | ||||
| 					//typename SrcVolumeType::VoxelType result = interpolatedSample(m_pVolSrc, sx, sy, sz, WrapModes::Border, SrcVolumeType::VoxelType(0)); | ||||
|  | ||||
| 					volDownscaledX.setVoxelAt(tx, ty, tz, result); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		//Now downscale in y | ||||
| 		Region regDownscaledXAndY(0, 0, 0, m_regDst.getWidthInVoxels()-1, m_regDst.getHeightInVoxels()-1, m_regSrc.getDepthInVoxels()-1); | ||||
| 		SrcVolumeType volDownscaledXAndY(regDownscaledXAndY); | ||||
|  | ||||
| 		for(int32_t tz = regDownscaledXAndY.getLowerZ(); tz <= regDownscaledXAndY.getUpperZ(); tz++) | ||||
| 		{ | ||||
| 			for(int32_t ty = regDownscaledXAndY.getLowerY(); ty <= regDownscaledXAndY.getUpperY(); ty++) | ||||
| 			{ | ||||
| 				for(int32_t tx = regDownscaledXAndY.getLowerX(); tx <= regDownscaledXAndY.getUpperX(); tx++) | ||||
| 				{ | ||||
| 					float sx = (tx          ); | ||||
| 					float sy = (ty * fScaleY); | ||||
| 					float sz = (tz          ); | ||||
|  | ||||
| 					typename SrcVolumeType::VoxelType result = volDownscaledX.getVoxelWithWrapping(sx, sy, sz, WrapModes::Border); | ||||
|  | ||||
| 					volDownscaledXAndY.setVoxelAt(tx, ty, tz, result); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		//Now copy and downscale to dst. | ||||
| 		//Region regDst = m_pVolDst->getEnclosingRegion(); | ||||
|  | ||||
| 		for(int32_t tz = m_regDst.getLowerZ(); tz <= m_regDst.getUpperZ(); tz++) | ||||
| 		{ | ||||
| 			for(int32_t ty = m_regDst.getLowerY(); ty <= m_regDst.getUpperY(); ty++) | ||||
| 			{ | ||||
| 				for(int32_t tx = m_regDst.getLowerX(); tx <= m_regDst.getUpperX(); tx++) | ||||
| 				{ | ||||
| 					float sx = (tx - m_regDst.getLowerX()); | ||||
| 					float sy = (ty - m_regDst.getLowerY()); | ||||
| 					float sLowerZ = ((tz - 1) - m_regDst.getLowerZ()) * fScaleZ; | ||||
| 					float sCentreZ = ((tz   ) - m_regDst.getLowerZ()) * fScaleZ; | ||||
| 					float sUpperZ = ((tz + 1) - m_regDst.getLowerZ()) * fScaleZ; | ||||
|  | ||||
| 					float sumOfWeights = 0.0f; | ||||
| 					//typename SrcVolumeType::VoxelType tSum = SrcVolumeType::VoxelType(0); | ||||
|  | ||||
| 					//We should be able to use a higher range MultiMaterial rather than needing to use a Vector of floats. | ||||
| 					//We shouold also probably support an Accumulation type rather than hard coding. | ||||
| 					Vector<4, float> vecSum(0.0, 0.0, 0.0, 0.0); | ||||
|  | ||||
| 					for(float sz = sLowerZ; sz <= sUpperZ; sz += 1.0) | ||||
| 					{ | ||||
| 						float weight = triangleFilter(sz - sCentreZ); | ||||
| 						sumOfWeights += weight; | ||||
|  | ||||
| 						//This is wrong! There's no need to do interpolation. Just multiply the sameple by the correct kernel value. | ||||
| 						Vector<4, float> sample = interpolatedSample(&volDownscaledXAndY, sx, sy, sz, WrapModes::Border, SrcVolumeType::VoxelType()); | ||||
|  | ||||
| 						vecSum += (sample * weight); | ||||
| 					} | ||||
|  | ||||
| 					vecSum /= sumOfWeights; //Should divide by 'norm' | ||||
|  | ||||
| 					typename SrcVolumeType::VoxelType tResult = vecSum; //Should divide by 'norm' | ||||
|  | ||||
| 					m_pVolDst->setVoxelAt(tx, ty, tz, tResult); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user