A tool for evaluating multiple NURBS curve/surface points using the GPU.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2 KiB

2 years ago
#ifndef UNTITLED1_NURBSEVALUATOR_CUH
#define UNTITLED1_NURBSEVALUATOR_CUH
#include <cuda_runtime.h>
#include <thrust/device_vector.h>
#include <vector>
#include <map>
namespace NurbsSurface {
/**
* 曲面计算的核函数,负责计算曲面中的一个点的值
* @param d_pointSize 点的大小(3: [x, y, z] | 4:[x, y, z, w])
*/
__global__ void
calculate_kernel(const float *d_points, const float *d_knots_u, const float *d_knots_v, int d_pointsCnt_u,
int d_pointsCnt_v, int d_pointSize, int d_knotsCnt_u, int d_knotsCnt_v, int d_sampleCnt_u,
int d_sampleCnt_v);
class Evaluator {
private:
std::vector<std::vector<std::vector<float>>> controlPoints;
std::vector<float> knots_u;
std::vector<float> knots_v;
bool recordTime;
public:
/**
* 构造函数
* @param controlPoints 控制点矩阵[pointsCnt_u][pointsCnt_v][3]
* @param knots_u u方向knots
* @param knots_v v方向knots
*/
__host__ explicit Evaluator(std::vector<std::vector<std::vector<float>>> controlPoints,
std::vector<float> knots_u, std::vector<float> knots_v);
/**
* 供外部CPU程序使用的、负责调用gpu并行计算的方法
* @param sampleCnt_u u方向采样数目
* @param sampleCnt_v v方向采样数目
* @return 由 map 组成的vector{<<u, v>, {x, y, z}>}
*/
__host__ std::vector<std::map<std::pair<float, float>, std::vector<float>>>
calculate(int sampleCnt_u, int sampleCnt_v);
void setRecordTime(bool r);
};
}
/**
* 曲线部分
*/
namespace NurbsCurve {
/**
* 曲线计算的核函数
* @param d_pointSize 点的大小(3: [x, y, z] | 4:[x, y, z, w])
*/
__global__ static void
calculate_kernel(const float *d_points, const float *d_knots, int d_pointsCnt, int d_pointSize, int d_knotsCnt,
int d_sampleCnt);
class Evaluator {
private:
std::vector<std::vector<float>> controlPoints;
std::vector<float> knots;
bool recordTime;
public:
/**
* 构造函数
* @param controlPoints 控制点矩阵[pointsCnt][3]
*/
__host__ explicit Evaluator(std::vector<std::vector<float>> controlPoints, std::vector<float> knots);
/**
* 供外部CPU程序使用的、负责调用gpu并行计算的方法
* @param sampleCnt
* @return 由 map 组成的vector{<u, {x, y, z}>}
*/
__host__ std::vector<std::map<float, std::vector<float>>> calculate(int sampleCnt);
void setRecordTime(bool r);
};
}
/**
* 当u值已知时,根据基函数N的递推表达式,采用动态规划的方式求解N值
* @param N_Texture 结果返回在N_Texture中
*/
__device__ void d_basisFunction(float *N_Texture, const float *knots, float u, int degree, int d_knotsCnt);
/**
* device中判断两个浮点数是否相等。与CPU中一样,GPU中的浮点数也存在很小的误差,直接使用==判断往往容易将相等误判为不等
* @return true:相等
*/
__device__ bool d_floatEqual(float a, float b);
#endif