|
|
|
|
//
|
|
|
|
|
// Created by 14727 on 2022/11/19.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "device/Nurbs/nurbs_common.cuh"
|
|
|
|
|
#include "device/device_utils.cuh"
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
__device__ void d_basisFunction(float *N_Texture, const float *knots, float u, int degree, int d_knotsCnt) {
|
|
|
|
|
int m = d_knotsCnt - 1;
|
|
|
|
|
for (int p = 0; p <= degree; p++) {
|
|
|
|
|
for (int i = 0; i + p <= m - 1; i++) {
|
|
|
|
|
if (p == 0) {
|
|
|
|
|
if ((u > knots[i] || d_floatEqual(u, knots[i])) && (u < knots[i + 1])
|
|
|
|
|
||
|
|
|
|
|
d_floatEqual(u, knots[i + 1]) && d_floatEqual(u, knots[m])) {
|
|
|
|
|
N_Texture[p * m + i] = 1.0;
|
|
|
|
|
} else {
|
|
|
|
|
N_Texture[p * m + i] = 0.0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
float Nip_1 = N_Texture[(p - 1) * m + i];
|
|
|
|
|
float Ni1p_1 = N_Texture[(p - 1) * m + i + 1];
|
|
|
|
|
float left = d_floatEqual(knots[i + p], knots[i]) ? 0 : (u - knots[i]) * Nip_1 /
|
|
|
|
|
(knots[i + p] - knots[i]);
|
|
|
|
|
float right = d_floatEqual(knots[i + p + 1], knots[i + 1]) ? 0 : (knots[i + p + 1] - u) * Ni1p_1 /
|
|
|
|
|
(knots[i + p + 1] - knots[i + 1]);
|
|
|
|
|
N_Texture[p * m + i] = left + right;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__global__ void g_basisTexture(float *nTexture, float *nTexture1, const float *d_knots, int d_pointsCnt, int d_knotsCnt,
|
|
|
|
|
int d_sampleCnt) {
|
|
|
|
|
// 一维grid和一维block
|
|
|
|
|
int idx = blockIdx.x * blockDim.x + threadIdx.x; // 采样点编号
|
|
|
|
|
float d_paramCeil = d_knots[d_knotsCnt - 1];
|
|
|
|
|
float u = idx * d_paramCeil / (d_sampleCnt - 1);
|
|
|
|
|
if (u > 1.0 * d_paramCeil) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int d_degree = d_knotsCnt - 1 - d_pointsCnt;
|
|
|
|
|
auto *N_dp = (float *) malloc((d_degree + 1) * (d_knotsCnt - 1) * sizeof(float));
|
|
|
|
|
d_basisFunction(N_dp, d_knots, u, d_degree, d_knotsCnt);
|
|
|
|
|
for (int i = 0; i < d_pointsCnt; i++) {
|
|
|
|
|
nTexture[idx * d_pointsCnt + i] = N_dp[d_degree * (d_knotsCnt - 1) + i];
|
|
|
|
|
nTexture1[idx * (d_pointsCnt + 1) + i] = N_dp[(d_degree - 1) * (d_knotsCnt - 1) + i];
|
|
|
|
|
}
|
|
|
|
|
nTexture1[idx * (d_pointsCnt + 1) + d_pointsCnt] = N_dp[(d_degree - 1) * (d_knotsCnt - 1) +
|
|
|
|
|
d_pointsCnt]; // nTexture1多记录一列数据
|
|
|
|
|
d_safeFree(N_dp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__global__ void
|
|
|
|
|
g_derTexture(float *derTexture, const float *nTexture1, const float *d_knots, int d_pointsCnt, int d_knotsCnt,
|
|
|
|
|
int d_sampleCnt) {
|
|
|
|
|
// 一维grid和一维block
|
|
|
|
|
int idx = blockIdx.x * blockDim.x + threadIdx.x; // 采样点编号
|
|
|
|
|
if (idx >= d_sampleCnt) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int degree = d_knotsCnt - 1 - d_pointsCnt;
|
|
|
|
|
|
|
|
|
|
// printf("degree: %d\n", degree);
|
|
|
|
|
for (int i = 0; i < d_pointsCnt; i++) {
|
|
|
|
|
float left = d_floatEqual(d_knots[i + degree], d_knots[i]) ? 0 :
|
|
|
|
|
nTexture1[idx * (d_pointsCnt + 1) + i] * (degree - 1) / (d_knots[i + degree] - d_knots[i]);
|
|
|
|
|
float right = d_floatEqual(d_knots[i + degree + 1], d_knots[i + 1]) ? 0 :
|
|
|
|
|
nTexture1[idx * (d_pointsCnt + 1) + i + 1] * (degree - 1) /
|
|
|
|
|
(d_knots[i + degree + 1] - d_knots[i + 1]);
|
|
|
|
|
derTexture[idx * d_pointsCnt + i] = left - right;
|
|
|
|
|
// printf("<%d, %d> -- %g \n", idx, i, left - right);
|
|
|
|
|
// printf("nTex1: %g \n", nTexture1[idx * (d_pointsCnt + 1) + i]);
|
|
|
|
|
}
|
|
|
|
|
}
|