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.4 KiB

//
// Created by 14727 on 2022/12/9.
//
#ifndef NURBSEVALUATOR_NURBS_SURFACE_CUH
#define NURBSEVALUATOR_NURBS_SURFACE_CUH
#include <vector>
#include "cuda_runtime.h"
#include "bvh.cuh"
namespace NurbsSurface {
const int POINT_SIZE = 4;
/**
* 曲线计算的核函数
* @param d_pointSize 点的大小(3: [x, y, z] | 4:[x, y, z, w])
*/
__global__ static void
g_evaluate(float* res, const float *d_nTexture_u, const float *d_nTexture_v, const float *d_points, int d_pointsCnt_u,
int d_pointsCnt_v, int d_pointSize, float d_lastKnot_u, float d_lastKnot_v, int d_sampleCnt_u,
int d_sampleCnt_v);
__global__ static void
g_derivative(float *derivatives, const float *derTexture_u, const float *derTexture_v, const float *nTexture_u,
const float *nTexture_v,
const float *d_points, int d_pointsCnt_u, int d_pointsCnt_v, int d_pointSize, float d_lastKnot_u,
float d_lastKnot_v, int d_sampleCnt_u, int d_sampleCnt_v);
__global__ static void
g_curvature(const float *derivatives, int sampleCnt_u, int sampleCnt_v, float lastKnot_u, float lastKnot_v, float *ms, float*k);
class Surface {
private:
std::vector<std::vector<std::vector<float>>> controlPoints;
float *d_points;
std::vector<float> knots_u;
std::vector<float> knots_v;
float *d_knots_u;
float *d_knots_v;
bool recordTime;
float *d_nTexture_u; // u方向指向度为p时的device中的nurbs基函数矩阵
float *d_nTexture_v; // v方向指向度为p时的device中的nurbs基函数矩阵
float *d_nTexture1_u; // u方向指向度为p-1时的device中的nurbs基函数矩阵
float *d_nTexture1_v; // v方向指向度为p-1时的device中的nurbs基函数矩阵
float *d_evaluationRes; // evaluation结果
float *d_derivatives; // 一阶导计算结果
float *d_k; // 最大曲率
BVH bvh;
public:
/**
* 构造函数
* @param controlPoints 控制点矩阵[pointsCnt_u][pointsCnt_v][3]
* @param knots_u u方向knots
* @param knots_v v方向knots
*/
__host__ explicit Surface(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::vector<std::vector<float>>>
evaluate(int sampleCnt_u_, int sampleCnt_v_);
/**
* 供外部CPU程序使用的、负责调用gpu并行计算切向量的方法
*/
__host__ void derivative(int sampleCnt_u, int sampleCnt_v);
/**
* 供外部CPU程序使用的、负责调用gpu并行计算二阶导的方法
*/
__host__ void curvature(int sampleCnt_u, int sampleCnt_v);
/**
* 供外部CPU程序使用的、负责调用gpu并行计算BVH的方法
*/
__host__ void buildBHV(int sampleCnt_u, int sampleCnt_v);
void setRecordTime(bool r);
~Surface();
};
}
#endif //NURBSEVALUATOR_NURBS_SURFACE_CUH