refactor: migrate voxel data storage to DataAllocator for CUDA
This commit is contained in:
@@ -23,14 +23,12 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef VOXIMAGEFILTERCUSTOM_HPP
|
||||
#define VOXIMAGEFILTERCUSTOM_HPP
|
||||
|
||||
#include <Math/Dense.h>
|
||||
#include "Math/VoxImage.h"
|
||||
#include "VoxImageFilter.h"
|
||||
#include <Math/Dense.h>
|
||||
|
||||
#define likely(expr) __builtin_expect(!!(expr), 1)
|
||||
|
||||
@@ -41,50 +39,50 @@
|
||||
namespace uLib {
|
||||
|
||||
template <typename VoxelT>
|
||||
class VoxFilterAlgorithmCustom :
|
||||
public VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT> > {
|
||||
class VoxFilterAlgorithmCustom
|
||||
: public VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT>> {
|
||||
|
||||
typedef float (*FunctionPt)(const std::vector<Scalarf> &);
|
||||
|
||||
typedef float (* FunctionPt)(const std::vector<Scalarf> &);
|
||||
public:
|
||||
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT> > BaseClass;
|
||||
VoxFilterAlgorithmCustom(const Vector3i &size) :
|
||||
BaseClass(size), m_CustomEvaluate(NULL)
|
||||
{}
|
||||
typedef VoxImageFilter<VoxelT, VoxFilterAlgorithmCustom<VoxelT>> BaseClass;
|
||||
VoxFilterAlgorithmCustom(const Vector3i &size)
|
||||
: BaseClass(size), m_CustomEvaluate(NULL) {}
|
||||
|
||||
float Evaluate(const VoxImage<VoxelT> &buffer, int index)
|
||||
{
|
||||
if(likely(m_CustomEvaluate)) {
|
||||
const std::vector<VoxelT> &vbuf = buffer.ConstData();
|
||||
const std::vector<VoxelT> &vker = this->m_KernelData.ConstData();
|
||||
int vox_size = vbuf.size();
|
||||
int ker_size = vker.size();
|
||||
int pos;
|
||||
float Evaluate(const VoxImage<VoxelT> &buffer, int index) {
|
||||
if (likely(m_CustomEvaluate)) {
|
||||
const DataAllocator<VoxelT> &vbuf = buffer.ConstData();
|
||||
const DataAllocator<VoxelT> &vker = this->m_KernelData.ConstData();
|
||||
int vox_size = vbuf.size();
|
||||
int ker_size = vker.size();
|
||||
int pos;
|
||||
|
||||
float ker_sum = 0;
|
||||
std::vector<Scalarf> mfh(ker_size);
|
||||
for (int ik = 0; ik < ker_size; ik++) {
|
||||
pos = index + vker[ik].Count - vker[this->m_KernelData.GetCenterData()].Count;
|
||||
pos = (pos + vox_size) % vox_size;
|
||||
mfh[ik] = vbuf[pos].Value * vker[ik].Value;
|
||||
ker_sum += vker[ik].Value;
|
||||
}
|
||||
|
||||
return this->m_CustomEvaluate(mfh);
|
||||
}
|
||||
else
|
||||
std::cerr << "Custom evaluate function is NULL \n" <<
|
||||
"No operation performed by filter.\n";
|
||||
float ker_sum = 0;
|
||||
std::vector<Scalarf> mfh(ker_size);
|
||||
for (int ik = 0; ik < ker_size; ik++) {
|
||||
pos = index + vker[ik].Count -
|
||||
vker[this->m_KernelData.GetCenterData()].Count;
|
||||
pos = (pos + vox_size) % vox_size;
|
||||
mfh[ik] = vbuf[pos].Value * vker[ik].Value;
|
||||
ker_sum += vker[ik].Value;
|
||||
}
|
||||
|
||||
return this->m_CustomEvaluate(mfh);
|
||||
} else {
|
||||
std::cerr << "Custom evaluate function is NULL \n"
|
||||
<< "No operation performed by filter.\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void SetCustomEvaluate(FunctionPt funPt) { this->m_CustomEvaluate = funPt; }
|
||||
inline void SetCustomEvaluate(FunctionPt funPt) {
|
||||
this->m_CustomEvaluate = funPt;
|
||||
}
|
||||
|
||||
private:
|
||||
FunctionPt m_CustomEvaluate;
|
||||
FunctionPt m_CustomEvaluate;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
} // namespace uLib
|
||||
|
||||
#endif // VOXIMAGEFILTERCUSTOM_HPP
|
||||
|
||||
Reference in New Issue
Block a user