Turned isQuadNeeded() (which was a stl::function) into a function object.
This commit is contained in:
		@@ -286,8 +286,8 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	//Extract the surface
 | 
						//Extract the surface
 | 
				
			||||||
	SurfaceMesh<PositionMaterialNormal> mesh;
 | 
						SurfaceMesh<PositionMaterialNormal> mesh;
 | 
				
			||||||
	//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh);
 | 
						CubicSurfaceExtractorWithNormals< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
 | 
				
			||||||
	MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
 | 
						//MarchingCubesSurfaceExtractor< LargeVolume<MaterialDensityPair44> > surfaceExtractor(&volData, reg, &mesh);
 | 
				
			||||||
	//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
 | 
						//CubicSurfaceExtractorWithNormals<MaterialDensityPair44> surfaceExtractor(&volData, reg, &mesh);
 | 
				
			||||||
	surfaceExtractor.execute();
 | 
						surfaceExtractor.execute();
 | 
				
			||||||
	std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;
 | 
						std::cout << "#vertices: " << mesh.getNoOfVertices() << std::endl;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,7 @@ SET(CORE_INC_FILES
 | 
				
			|||||||
	include/PolyVoxCore/CubicSurfaceExtractor.inl
 | 
						include/PolyVoxCore/CubicSurfaceExtractor.inl
 | 
				
			||||||
	include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h
 | 
						include/PolyVoxCore/CubicSurfaceExtractorWithNormals.h
 | 
				
			||||||
	include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl
 | 
						include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl
 | 
				
			||||||
 | 
						include/PolyVoxCore/DefaultIsQuadNeeded.h
 | 
				
			||||||
	include/PolyVoxCore/DefaultMarchingCubesController.h
 | 
						include/PolyVoxCore/DefaultMarchingCubesController.h
 | 
				
			||||||
	include/PolyVoxCore/Density.h
 | 
						include/PolyVoxCore/Density.h
 | 
				
			||||||
	include/PolyVoxCore/GradientEstimators.h
 | 
						include/PolyVoxCore/GradientEstimators.h
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,39 +24,24 @@ freely, subject to the following restrictions:
 | 
				
			|||||||
#ifndef __PolyVox_CubicSurfaceExtractorWithNormals_H__
 | 
					#ifndef __PolyVox_CubicSurfaceExtractorWithNormals_H__
 | 
				
			||||||
#define __PolyVox_CubicSurfaceExtractorWithNormals_H__
 | 
					#define __PolyVox_CubicSurfaceExtractorWithNormals_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "PolyVoxImpl/MarchingCubesTables.h"
 | 
					#include "PolyVoxCore/DefaultIsQuadNeeded.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "PolyVoxCore/Array.h"
 | 
					#include "PolyVoxCore/Array.h"
 | 
				
			||||||
#include "PolyVoxCore/SurfaceMesh.h"
 | 
					#include "PolyVoxCore/SurfaceMesh.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace PolyVox
 | 
					namespace PolyVox
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						template<typename VolumeType, typename IsQuadNeeded = DefaultIsQuadNeeded<typename VolumeType::VoxelType> >
 | 
				
			||||||
	//FIXME - Make this a member of CubicSurfaceExtractorWithNormals?
 | 
					 | 
				
			||||||
	template<typename VoxelType>
 | 
					 | 
				
			||||||
	bool defaultIsQuadNeeded(VoxelType back, VoxelType front, float& materialToUse)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		if((back > 0) && (front == 0))
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			materialToUse = static_cast<float>(back);
 | 
					 | 
				
			||||||
			return true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	template<typename VolumeType>
 | 
					 | 
				
			||||||
	class CubicSurfaceExtractorWithNormals
 | 
						class CubicSurfaceExtractorWithNormals
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, polyvox_function<bool(typename VolumeType::VoxelType from, typename VolumeType::VoxelType to, float& materialToUse)> funcIsQuadNeededCallback = defaultIsQuadNeeded<typename VolumeType::VoxelType>);
 | 
							CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, IsQuadNeeded isQuadNeeded = IsQuadNeeded());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void execute();
 | 
							void execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		polyvox_function<bool(typename VolumeType::VoxelType voxel0, typename VolumeType::VoxelType voxel1, float& materialToUse)> m_funcIsQuadNeededCallback;
 | 
							//polyvox_function<bool(typename VolumeType::VoxelType voxel0, typename VolumeType::VoxelType voxel1, float& materialToUse)> m_funcIsQuadNeededCallback;
 | 
				
			||||||
 | 
							IsQuadNeeded m_funcIsQuadNeededCallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//The volume data and a sampler to access it.
 | 
							//The volume data and a sampler to access it.
 | 
				
			||||||
		VolumeType* m_volData;
 | 
							VolumeType* m_volData;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,19 +23,18 @@ freely, subject to the following restrictions:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace PolyVox
 | 
					namespace PolyVox
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	template<typename VolumeType>
 | 
						template<typename VolumeType, typename IsQuadNeeded>
 | 
				
			||||||
	CubicSurfaceExtractorWithNormals<VolumeType>::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, polyvox_function<bool(typename VolumeType::VoxelType from, typename VolumeType::VoxelType to, float& materialToUse)> funcIsQuadNeededCallback)
 | 
						CubicSurfaceExtractorWithNormals<VolumeType, IsQuadNeeded>::CubicSurfaceExtractorWithNormals(VolumeType* volData, Region region, SurfaceMesh<PositionMaterialNormal>* result, IsQuadNeeded isQuadNeeded)
 | 
				
			||||||
		:m_funcIsQuadNeededCallback(funcIsQuadNeededCallback)
 | 
							:m_volData(volData)
 | 
				
			||||||
		,m_volData(volData)
 | 
					 | 
				
			||||||
		,m_sampVolume(volData)
 | 
							,m_sampVolume(volData)
 | 
				
			||||||
		,m_meshCurrent(result)
 | 
							,m_meshCurrent(result)
 | 
				
			||||||
		,m_regSizeInVoxels(region)
 | 
							,m_regSizeInVoxels(region)
 | 
				
			||||||
	{		
 | 
						{		
 | 
				
			||||||
		assert(m_funcIsQuadNeededCallback);
 | 
							m_funcIsQuadNeededCallback = isQuadNeeded;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	template<typename VolumeType>
 | 
						template<typename VolumeType, typename IsQuadNeeded>
 | 
				
			||||||
	void CubicSurfaceExtractorWithNormals<VolumeType>::execute()
 | 
						void CubicSurfaceExtractorWithNormals<VolumeType, IsQuadNeeded>::execute()
 | 
				
			||||||
	{		
 | 
						{		
 | 
				
			||||||
		m_meshCurrent->clear();
 | 
							m_meshCurrent->clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					/*******************************************************************************
 | 
				
			||||||
 | 
					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_DefaultIsQuadNeeded_H__
 | 
				
			||||||
 | 
					#define __PolyVox_DefaultIsQuadNeeded_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace PolyVox
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						template<typename VoxelType>
 | 
				
			||||||
 | 
						class DefaultIsQuadNeeded
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						public:
 | 
				
			||||||
 | 
							bool operator()(VoxelType back, VoxelType front, float& materialToUse)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if((back > 0) && (front == 0))
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									materialToUse = static_cast<float>(back);
 | 
				
			||||||
 | 
									return true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //__PolyVox_DefaultIsQuadNeeded_H__
 | 
				
			||||||
@@ -73,19 +73,6 @@ namespace PolyVox
 | 
				
			|||||||
		MaterialType getMaterial() const throw() { return m_uMaterial; }
 | 
							MaterialType getMaterial() const throw() { return m_uMaterial; }
 | 
				
			||||||
		void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
 | 
							void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static bool isQuadNeeded(Material<Type> back, Material<Type> front, float& materialToUse)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			if((back.getMaterial() > 0) && (front.getMaterial() == 0))
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				materialToUse = static_cast<float>(back.getMaterial());
 | 
					 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		MaterialType m_uMaterial;
 | 
							MaterialType m_uMaterial;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ freely, subject to the following restrictions:
 | 
				
			|||||||
#ifndef __PolyVox_MaterialDensityPair_H__
 | 
					#ifndef __PolyVox_MaterialDensityPair_H__
 | 
				
			||||||
#define __PolyVox_MaterialDensityPair_H__
 | 
					#define __PolyVox_MaterialDensityPair_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "PolyVoxCore/DefaultIsQuadNeeded.h" //we'll specialise this function for this voxel type
 | 
				
			||||||
#include "PolyVoxCore/DefaultMarchingCubesController.h" //We'll specialise the controller contained in here
 | 
					#include "PolyVoxCore/DefaultMarchingCubesController.h" //We'll specialise the controller contained in here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "PolyVoxImpl/TypeDef.h"
 | 
					#include "PolyVoxImpl/TypeDef.h"
 | 
				
			||||||
@@ -95,7 +96,16 @@ namespace PolyVox
 | 
				
			|||||||
		static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
 | 
							static DensityType getMaxDensity() throw() { return (0x01 << NoOfDensityBits) - 1; }
 | 
				
			||||||
		static DensityType getMinDensity() throw() { return 0; }
 | 
							static DensityType getMinDensity() throw() { return 0; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static bool isQuadNeeded(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, float& materialToUse)
 | 
						private:
 | 
				
			||||||
 | 
							MaterialType m_uMaterial : NoOfMaterialBits;
 | 
				
			||||||
 | 
							DensityType m_uDensity : NoOfDensityBits;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						template<typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
 | 
				
			||||||
 | 
						class DefaultIsQuadNeeded< MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> >
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						public:
 | 
				
			||||||
 | 
							bool operator()(MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> back, MaterialDensityPair<Type, NoOfMaterialBits, NoOfDensityBits> front, float& materialToUse)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if((back.getMaterial() > 0) && (front.getMaterial() == 0))
 | 
								if((back.getMaterial() > 0) && (front.getMaterial() == 0))
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
@@ -107,10 +117,6 @@ namespace PolyVox
 | 
				
			|||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	private:
 | 
					 | 
				
			||||||
		MaterialType m_uMaterial : NoOfMaterialBits;
 | 
					 | 
				
			||||||
		DensityType m_uDensity : NoOfDensityBits;
 | 
					 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
 | 
						template <typename Type, uint8_t NoOfMaterialBits, uint8_t NoOfDensityBits>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@ namespace PolyVox
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh)
 | 
						void extractCubicMesh(Volume& volume, const Region& region, Mesh& resultMesh)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		CubicSurfaceExtractorWithNormals< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh, MaterialDensityPair88::isQuadNeeded);
 | 
							CubicSurfaceExtractorWithNormals< SimpleVolume<MaterialDensityPair88> > surfaceExtractor(&volume, region, &resultMesh);
 | 
				
			||||||
		surfaceExtractor.execute();
 | 
							surfaceExtractor.execute();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,7 +94,7 @@ void testForType(SurfaceMesh<PositionMaterialNormal>& result)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	CubicSurfaceExtractorWithNormals< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result, VoxelType::isQuadNeeded);
 | 
						CubicSurfaceExtractorWithNormals< SimpleVolume<VoxelType> > extractor(&volData, volData.getEnclosingRegion(), &result);
 | 
				
			||||||
	extractor.execute();
 | 
						extractor.execute();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user