Removed use of template template parameters from Raycast and AmbientOcclusionCalculator.
This commit is contained in:
parent
29d816d416
commit
9db04f38bc
@ -41,26 +41,21 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
class AmbientOcclusionCalculator
|
class AmbientOcclusionCalculator
|
||||||
{
|
{
|
||||||
public:
|
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* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function<bool(const typename VolumeType::VoxelType& voxel)> funcIsTransparent);
|
||||||
~AmbientOcclusionCalculator();
|
~AmbientOcclusionCalculator();
|
||||||
|
|
||||||
void execute(void);
|
void execute(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool raycastCallback(const typename VolumeType::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;
|
Region m_region;
|
||||||
typename VolumeType<VoxelType>::Sampler m_sampVolume;
|
typename VolumeType::Sampler m_sampVolume;
|
||||||
VolumeType<VoxelType>* m_volInput;
|
VolumeType* m_volInput;
|
||||||
Array<3, uint8_t>* m_arrayResult;
|
Array<3, uint8_t>* m_arrayResult;
|
||||||
float m_fRayLength;
|
float m_fRayLength;
|
||||||
|
|
||||||
@ -70,7 +65,7 @@ namespace PolyVox
|
|||||||
uint16_t mRandomVectorIndex;
|
uint16_t mRandomVectorIndex;
|
||||||
uint16_t mIndexIncreament;
|
uint16_t mIndexIncreament;
|
||||||
|
|
||||||
polyvox_function<bool(const VoxelType& voxel)> m_funcIsTransparent;
|
polyvox_function<bool(const typename VolumeType::VoxelType& voxel)> m_funcIsTransparent;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ freely, subject to the following restrictions:
|
|||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
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>::AmbientOcclusionCalculator(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, polyvox_function<bool(const typename VolumeType::VoxelType& voxel)> funcIsTransparent)
|
||||||
:m_region(region)
|
:m_region(region)
|
||||||
,m_sampVolume(volInput)
|
,m_sampVolume(volInput)
|
||||||
,m_volInput(volInput)
|
,m_volInput(volInput)
|
||||||
@ -50,13 +50,13 @@ namespace PolyVox
|
|||||||
mIndexIncreament = 1;
|
mIndexIncreament = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
AmbientOcclusionCalculator<VolumeType, VoxelType>::~AmbientOcclusionCalculator()
|
AmbientOcclusionCalculator<VolumeType>::~AmbientOcclusionCalculator()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
void AmbientOcclusionCalculator<VolumeType, VoxelType>::execute(void)
|
void AmbientOcclusionCalculator<VolumeType>::execute(void)
|
||||||
{
|
{
|
||||||
const int iRatioX = m_volInput->getWidth() / m_arrayResult->getDimension(0);
|
const int iRatioX = m_volInput->getWidth() / m_arrayResult->getDimension(0);
|
||||||
const int iRatioY = m_volInput->getHeight() / m_arrayResult->getDimension(1);
|
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);
|
const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f);
|
||||||
|
|
||||||
RaycastResult raycastResult;
|
RaycastResult raycastResult;
|
||||||
Raycast<VolumeType, VoxelType> raycast(m_volInput, Vector3DFloat(0.0f,0.0f,0.0f), Vector3DFloat(1.0f,1.0f,1.0f), raycastResult, polyvox_bind(&PolyVox::AmbientOcclusionCalculator<VolumeType,VoxelType>::raycastCallback, this, std::placeholders::_1));
|
Raycast<VolumeType> raycast(m_volInput, Vector3DFloat(0.0f,0.0f,0.0f), Vector3DFloat(1.0f,1.0f,1.0f), raycastResult, polyvox_bind(&PolyVox::AmbientOcclusionCalculator<VolumeType>::raycastCallback, this, std::placeholders::_1));
|
||||||
|
|
||||||
//This loop iterates over the bottom-lower-left voxel in each of the cells in the output array
|
//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)
|
for(uint16_t z = m_region.getLowerCorner().getZ(); z <= m_region.getUpperCorner().getZ(); z += iRatioZ)
|
||||||
@ -133,14 +133,10 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
#if defined(_MSC_VER)
|
bool AmbientOcclusionCalculator<VolumeType>::raycastCallback(const typename VolumeType::Sampler& sampler)
|
||||||
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();
|
VolumeType::VoxelType voxel = sampler.getVoxel();
|
||||||
return m_funcIsTransparent(voxel);
|
return m_funcIsTransparent(voxel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,12 +91,12 @@ namespace PolyVox
|
|||||||
/// surace extractors. It's behaviour with the Marching Cubes surface extractor has not
|
/// surace extractors. It's behaviour with the Marching Cubes surface extractor has not
|
||||||
/// been tested yet.
|
/// been tested yet.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
class Raycast
|
class Raycast
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///Constructor
|
///Constructor
|
||||||
Raycast(VolumeType<VoxelType>* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function<bool(const typename VolumeType<VoxelType>::Sampler& sampler)> funcIsPassable);
|
Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function<bool(const typename VolumeType::Sampler& sampler)> funcIsPassable);
|
||||||
|
|
||||||
///Sets the start position for the ray.
|
///Sets the start position for the ray.
|
||||||
void setStart(const Vector3DFloat& v3dStart);
|
void setStart(const Vector3DFloat& v3dStart);
|
||||||
@ -109,12 +109,12 @@ namespace PolyVox
|
|||||||
private:
|
private:
|
||||||
RaycastResult& m_result;
|
RaycastResult& m_result;
|
||||||
|
|
||||||
polyvox_function<bool(const typename VolumeType<VoxelType>::Sampler& position)> m_funcIsPassable;
|
polyvox_function<bool(const typename VolumeType::Sampler& position)> m_funcIsPassable;
|
||||||
|
|
||||||
void doRaycast(float x1, float y1, float z1, float x2, float y2, float z2);
|
void doRaycast(float x1, float y1, float z1, float x2, float y2, float z2);
|
||||||
|
|
||||||
VolumeType<VoxelType>* m_volData;
|
VolumeType* m_volData;
|
||||||
typename VolumeType<VoxelType>::Sampler m_sampVolume;
|
typename VolumeType::Sampler m_sampVolume;
|
||||||
|
|
||||||
Vector3DFloat m_v3dStart;
|
Vector3DFloat m_v3dStart;
|
||||||
Vector3DFloat m_v3dDirectionAndLength;
|
Vector3DFloat m_v3dDirectionAndLength;
|
||||||
|
@ -31,8 +31,8 @@ namespace PolyVox
|
|||||||
/// represents the length of the ray.
|
/// represents the length of the ray.
|
||||||
/// \param result An instance of RaycastResult in which the result will be stored.
|
/// \param result An instance of RaycastResult in which the result will be stored.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
Raycast<VolumeType, VoxelType>::Raycast(VolumeType<VoxelType>* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function<bool(const typename VolumeType<VoxelType>::Sampler& sampler)> funcIsPassable)
|
Raycast<VolumeType>::Raycast(VolumeType* volData, const Vector3DFloat& v3dStart, const Vector3DFloat& v3dDirectionAndLength, RaycastResult& result, polyvox_function<bool(const typename VolumeType::Sampler& sampler)> funcIsPassable)
|
||||||
:m_result(result)
|
:m_result(result)
|
||||||
,m_volData(volData)
|
,m_volData(volData)
|
||||||
,m_sampVolume(volData)
|
,m_sampVolume(volData)
|
||||||
@ -45,8 +45,8 @@ namespace PolyVox
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// \param v3dStart The starting position of the ray.
|
/// \param v3dStart The starting position of the ray.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
void Raycast<VolumeType, VoxelType>::setStart(const Vector3DFloat& v3dStart)
|
void Raycast<VolumeType>::setStart(const Vector3DFloat& v3dStart)
|
||||||
{
|
{
|
||||||
m_v3dStart = v3dStart;
|
m_v3dStart = v3dStart;
|
||||||
}
|
}
|
||||||
@ -55,8 +55,8 @@ namespace PolyVox
|
|||||||
/// \param v3dDirectionAndLength The direction of the ray. The length of this vector also
|
/// \param v3dDirectionAndLength The direction of the ray. The length of this vector also
|
||||||
/// represents the length of the ray.
|
/// represents the length of the ray.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
void Raycast<VolumeType, VoxelType>::setDirection(const Vector3DFloat& v3dDirectionAndLength)
|
void Raycast<VolumeType>::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.
|
//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;
|
m_v3dDirectionAndLength = v3dDirectionAndLength;
|
||||||
@ -65,8 +65,8 @@ namespace PolyVox
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// The result is stored in the RaycastResult instance which was passed to the constructor.
|
/// The result is stored in the RaycastResult instance which was passed to the constructor.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
void Raycast<VolumeType, VoxelType>::execute(void)
|
void Raycast<VolumeType>::execute(void)
|
||||||
{
|
{
|
||||||
//The doRaycast function is assuming that it is iterating over the areas defined between
|
//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
|
//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)".
|
// It should simply read "if (ty <= tz)".
|
||||||
//
|
//
|
||||||
// This error was reported by Joey Hammer (PixelActive).
|
// This error was reported by Joey Hammer (PixelActive).
|
||||||
template< template<typename> class VolumeType, typename VoxelType>
|
template<typename VolumeType>
|
||||||
void Raycast<VolumeType, VoxelType>::doRaycast(float x1, float y1, float z1, float x2, float y2, float z2)
|
void Raycast<VolumeType>::doRaycast(float x1, float y1, float z1, float x2, float y2, float z2)
|
||||||
{
|
{
|
||||||
int i = (int)floorf(x1);
|
int i = (int)floorf(x1);
|
||||||
int j = (int)floorf(y1);
|
int j = (int)floorf(y1);
|
||||||
|
@ -62,7 +62,7 @@ void TestAmbientOcclusionGenerator::testExecute()
|
|||||||
Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength));
|
Array<3, uint8_t> ambientOcclusionResult(ArraySizes(g_uArraySideLength)(g_uArraySideLength)(g_uArraySideLength));
|
||||||
|
|
||||||
//Create the ambient occlusion calculator
|
//Create the ambient occlusion calculator
|
||||||
AmbientOcclusionCalculator<SimpleVolume, uint8_t> calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent);
|
AmbientOcclusionCalculator< SimpleVolume<uint8_t> > calculator(&volData, &ambientOcclusionResult, volData.getEnclosingRegion(), 32.0f, 255, isVoxelTransparent);
|
||||||
|
|
||||||
//Execute the calculator
|
//Execute the calculator
|
||||||
calculator.execute();
|
calculator.execute();
|
||||||
|
@ -68,7 +68,7 @@ void TestRaycast::testExecute()
|
|||||||
for(int ct = 0; ct < 1000000; ct++)
|
for(int ct = 0; ct < 1000000; ct++)
|
||||||
{
|
{
|
||||||
RaycastResult result;
|
RaycastResult result;
|
||||||
Raycast<SimpleVolume, int8_t> raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay);
|
Raycast< SimpleVolume<int8_t> > raycast(&volData, start, randomUnitVectors[ct % 1024] * 1000.0f, result, isPassableByRay);
|
||||||
raycast.execute();
|
raycast.execute();
|
||||||
if(result.foundIntersection)
|
if(result.foundIntersection)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user