Work on voxel refactoring...

This commit is contained in:
unknown 2012-03-27 14:21:43 +02:00
parent 1f748cbd72
commit 6d656ad173
3 changed files with 20 additions and 10 deletions

View File

@ -43,15 +43,18 @@ namespace PolyVox
class AmbientOcclusionCalculator
{
public:
AmbientOcclusionCalculator(VolumeType<VoxelType>* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement/*, polyvox_function<bool(const VoxelType& voxel)> funcIsTransparent*/);
AmbientOcclusionCalculator(VolumeType<VoxelType>* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function<bool(const VoxelType& voxel)> funcIsTransparent);
~AmbientOcclusionCalculator();
void execute(void);
private:
//bool raycastCallback(const typename VolumeType<VoxelType>::Sampler& sampler);
#if defined(_MSC_VER) //FIXME: To be investigated. Linux version is more general and should be correct.
bool raycastCallback(const typename SimpleVolume<VoxelType>::Sampler& sampler);
#else
bool raycastCallback(const typename VolumeType<VoxelType>::Sampler& sampler);
#endif
Region m_region;
typename VolumeType<VoxelType>::Sampler m_sampVolume;

View File

@ -24,7 +24,7 @@ freely, subject to the following restrictions:
namespace PolyVox
{
template< template<typename> class VolumeType, typename VoxelType>
AmbientOcclusionCalculator<VolumeType, VoxelType>::AmbientOcclusionCalculator(VolumeType<VoxelType>* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement/*, polyvox_function<bool(const VoxelType& voxel)> funcIsTransparent*/)
AmbientOcclusionCalculator<VolumeType, VoxelType>::AmbientOcclusionCalculator(VolumeType<VoxelType>* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function<bool(const VoxelType& voxel)> funcIsTransparent)
:m_region(region)
,m_sampVolume(volInput)
,m_volInput(volInput)
@ -33,7 +33,7 @@ namespace PolyVox
,m_uNoOfSamplesPerOutputElement(uNoOfSamplesPerOutputElement)
,mRandomUnitVectorIndex(0) //Although these could be uninitialised, we
,mRandomVectorIndex(0) //initialise for consistant results in the tests.
//,m_funcIsTransparent(funcIsTransparent)
,m_funcIsTransparent(funcIsTransparent)
{
//Make sure that the size of the volume is an exact multiple of the size of the array.
assert(m_volInput->getWidth() % arrayResult->getDimension(0) == 0);
@ -134,11 +134,13 @@ namespace PolyVox
}
template< template<typename> class VolumeType, typename VoxelType>
//bool AmbientOcclusionCalculator<VolumeType, VoxelType>::raycastCallback(const typename VolumeType<VoxelType>::Sampler& sampler)
#if defined(_MSC_VER)
bool AmbientOcclusionCalculator<VolumeType, VoxelType>::raycastCallback(const typename SimpleVolume<VoxelType>::Sampler& sampler)
#else
bool AmbientOcclusionCalculator<VolumeType, VoxelType>::raycastCallback(const typename VolumeType<VoxelType>::Sampler& sampler)
#endif
{
//VoxelType voxel = sampler.getVoxel();
//return m_funcIsTransparent(voxel);
return sampler.getVoxel().getMaterial() == 0;
VoxelType voxel = sampler.getVoxel();
return m_funcIsTransparent(voxel);
}
}

View File

@ -31,6 +31,11 @@ freely, subject to the following restrictions:
using namespace PolyVox;
bool isVoxelTransparent(Material8 voxel)
{
return voxel.getMaterial() == 0;
}
void TestAmbientOcclusionGenerator::testExecute()
{
const int32_t g_uVolumeSideLength = 64;
@ -59,7 +64,7 @@ void TestAmbientOcclusionGenerator::testExecute()
Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength));
//Create the ambient occlusion calculator
AmbientOcclusionCalculator<SimpleVolume, Material8> calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255);
AmbientOcclusionCalculator<SimpleVolume, Material8> calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent);
//Execute the calculator
calculator.execute();