From 9db04f38bcad8836777ba5fa98d0bed0c166054c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 May 2012 13:31:42 +0200 Subject: [PATCH] Removed use of template template parameters from Raycast and AmbientOcclusionCalculator. --- .../PolyVoxCore/AmbientOcclusionCalculator.h | 17 +++++-------- .../AmbientOcclusionCalculator.inl | 24 ++++++++----------- .../PolyVoxCore/include/PolyVoxCore/Raycast.h | 10 ++++---- .../include/PolyVoxCore/Raycast.inl | 20 ++++++++-------- tests/TestAmbientOcclusionGenerator.cpp | 2 +- tests/TestRaycast.cpp | 2 +- 6 files changed, 33 insertions(+), 42 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h index cafcf6bc..0cfdef5b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.h @@ -41,26 +41,21 @@ freely, subject to the following restrictions: namespace PolyVox { - template< template class VolumeType, typename VoxelType> + template class AmbientOcclusionCalculator { public: - AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function funcIsTransparent); + AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function funcIsTransparent); ~AmbientOcclusionCalculator(); void execute(void); private: - -#if defined(_MSC_VER) //FIXME: To be investigated. Linux version is more general and should be correct. - bool raycastCallback(const typename SimpleVolume::Sampler& sampler); -#else - bool raycastCallback(const typename VolumeType::Sampler& sampler); -#endif + bool raycastCallback(const typename VolumeType::Sampler& sampler); Region m_region; - typename VolumeType::Sampler m_sampVolume; - VolumeType* m_volInput; + typename VolumeType::Sampler m_sampVolume; + VolumeType* m_volInput; Array<3, uint8_t>* m_arrayResult; float m_fRayLength; @@ -70,7 +65,7 @@ namespace PolyVox uint16_t mRandomVectorIndex; uint16_t mIndexIncreament; - polyvox_function m_funcIsTransparent; + polyvox_function m_funcIsTransparent; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index a38ce720..1a3e9587 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -23,8 +23,8 @@ freely, subject to the following restrictions: namespace PolyVox { - template< template class VolumeType, typename VoxelType> - AmbientOcclusionCalculator::AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function funcIsTransparent) + template + AmbientOcclusionCalculator::AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function funcIsTransparent) :m_region(region) ,m_sampVolume(volInput) ,m_volInput(volInput) @@ -50,13 +50,13 @@ namespace PolyVox mIndexIncreament = 1; } - template< template class VolumeType, typename VoxelType> - AmbientOcclusionCalculator::~AmbientOcclusionCalculator() + template + AmbientOcclusionCalculator::~AmbientOcclusionCalculator() { } - template< template class VolumeType, typename VoxelType> - void AmbientOcclusionCalculator::execute(void) + template + void AmbientOcclusionCalculator::execute(void) { const int iRatioX = m_volInput->getWidth() / m_arrayResult->getDimension(0); const int iRatioY = m_volInput->getHeight() / m_arrayResult->getDimension(1); @@ -75,7 +75,7 @@ namespace PolyVox const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f); RaycastResult raycastResult; - Raycast raycast(m_volInput, Vector3DFloat(0.0f,0.0f,0.0f), Vector3DFloat(1.0f,1.0f,1.0f), raycastResult, polyvox_bind(&PolyVox::AmbientOcclusionCalculator::raycastCallback, this, std::placeholders::_1)); + Raycast raycast(m_volInput, Vector3DFloat(0.0f,0.0f,0.0f), Vector3DFloat(1.0f,1.0f,1.0f), raycastResult, polyvox_bind(&PolyVox::AmbientOcclusionCalculator::raycastCallback, this, std::placeholders::_1)); //This loop iterates over the bottom-lower-left voxel in each of the cells in the output array for(uint16_t z = m_region.getLowerCorner().getZ(); z <= m_region.getUpperCorner().getZ(); z += iRatioZ) @@ -133,14 +133,10 @@ namespace PolyVox } } - template< template class VolumeType, typename VoxelType> -#if defined(_MSC_VER) - bool AmbientOcclusionCalculator::raycastCallback(const typename SimpleVolume::Sampler& sampler) -#else - bool AmbientOcclusionCalculator::raycastCallback(const typename VolumeType::Sampler& sampler) -#endif + template + bool AmbientOcclusionCalculator::raycastCallback(const typename VolumeType::Sampler& sampler) { - VoxelType voxel = sampler.getVoxel(); + VolumeType::VoxelType voxel = sampler.getVoxel(); return m_funcIsTransparent(voxel); } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h index cb559ec2..24a568c3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.h @@ -91,12 +91,12 @@ namespace PolyVox /// surace extractors. It's behaviour with the Marching Cubes surface extractor has not /// been tested yet. //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> + template class Raycast { public: ///Constructor - Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function::Sampler& sampler)> funcIsPassable); + Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function funcIsPassable); ///Sets the start position for the ray. void setStart(const Vector3DFloat& v3dStart); @@ -109,12 +109,12 @@ namespace PolyVox private: RaycastResult& m_result; - polyvox_function::Sampler& position)> m_funcIsPassable; + polyvox_function m_funcIsPassable; void doRaycast(float x1, float y1, float z1, float x2, float y2, float z2); - VolumeType* m_volData; - typename VolumeType::Sampler m_sampVolume; + VolumeType* m_volData; + typename VolumeType::Sampler m_sampVolume; Vector3DFloat m_v3dStart; Vector3DFloat m_v3dDirectionAndLength; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl index a2e12668..490fb064 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Raycast.inl @@ -31,8 +31,8 @@ namespace PolyVox /// represents the length of the ray. /// \param result An instance of RaycastResult in which the result will be stored. //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> - Raycast::Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function::Sampler& sampler)> funcIsPassable) + template + Raycast::Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function funcIsPassable) :m_result(result) ,m_volData(volData) ,m_sampVolume(volData) @@ -45,8 +45,8 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// \param v3dStart The starting position of the ray. //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> - void Raycast::setStart(const Vector3DFloat& v3dStart) + template + void Raycast::setStart(const Vector3DFloat& v3dStart) { m_v3dStart = v3dStart; } @@ -55,8 +55,8 @@ namespace PolyVox /// \param v3dDirectionAndLength The direction of the ray. The length of this vector also /// represents the length of the ray. //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> - void Raycast::setDirection(const Vector3DFloat& v3dDirectionAndLength) + template + void Raycast::setDirection(const Vector3DFloat& v3dDirectionAndLength) { //FIXME: We should add a warning when the ray direction is of length one, as this seems to be a common mistake. m_v3dDirectionAndLength = v3dDirectionAndLength; @@ -65,8 +65,8 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// /// The result is stored in the RaycastResult instance which was passed to the constructor. //////////////////////////////////////////////////////////////////////////////// - template< template class VolumeType, typename VoxelType> - void Raycast::execute(void) + template + void Raycast::execute(void) { //The doRaycast function is assuming that it is iterating over the areas defined between //voxels. We actually want to define the areas as being centered on voxels (as this is @@ -109,8 +109,8 @@ namespace PolyVox // It should simply read "if (ty <= tz)". // // This error was reported by Joey Hammer (PixelActive). - template< template class VolumeType, typename VoxelType> - void Raycast::doRaycast(float x1, float y1, float z1, float x2, float y2, float z2) + template + void Raycast::doRaycast(float x1, float y1, float z1, float x2, float y2, float z2) { int i = (int)floorf(x1); int j = (int)floorf(y1); diff --git a/tests/TestAmbientOcclusionGenerator.cpp b/tests/TestAmbientOcclusionGenerator.cpp index 34f9df00..7491f7c5 100644 --- a/tests/TestAmbientOcclusionGenerator.cpp +++ b/tests/TestAmbientOcclusionGenerator.cpp @@ -62,7 +62,7 @@ void TestAmbientOcclusionGenerator::testExecute() Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength)); //Create the ambient occlusion calculator - AmbientOcclusionCalculator calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent); + AmbientOcclusionCalculator< SimpleVolume > calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent); //Execute the calculator calculator.execute(); diff --git a/tests/TestRaycast.cpp b/tests/TestRaycast.cpp index 72c5586e..645a4542 100644 --- a/tests/TestRaycast.cpp +++ b/tests/TestRaycast.cpp @@ -68,7 +68,7 @@ void TestRaycast::testExecute() for(int ct = 0; ct < 1000000; ct++) { RaycastResult result; - Raycast raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay); + Raycast< SimpleVolume > raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay); raycast.execute(); if(result.foundIntersection) {