PeriDyno 1.0.0
Loading...
Searching...
No Matches
CalculateNormalSDF.cu
Go to the documentation of this file.
1#include "CalculateNormalSDF.h"
2
3namespace dyno
4{
5 IMPLEMENT_TCLASS(CalculateNormalSDF, TDataType)
6
7
8 template<typename Real, typename Coord, typename Tetrahedron>
9 __global__ void K_UpdateNormalSDF(
10 DArray<Coord> posArr,
11 DArray<Tetrahedron> tets,
12 DArray<Real> distance,
13 DArray<Coord> normalTet)
14 {
15 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
16 if (pId >= tets.size()) return;
17
18 Coord posCenter = (posArr[tets[pId][0]] + posArr[tets[pId][1]] + posArr[tets[pId][2]] + posArr[tets[pId][3]]) / 4.0f;
19 Coord dir(0);
20 for (int i = 0; i < 4; i++)
21 {
22 dir += distance[tets[pId][i]] * (posArr[tets[pId][i]] - posCenter) / (posArr[tets[pId][i]] - posCenter).norm();
23 }
24 if (dir.norm() > EPSILON)
25 dir /= dir.norm();
26 else
27 dir = Coord(0, 1, 0);
28 normalTet[pId] = dir;
29 }
30
31 template<typename TDataType>
32 void CalculateNormalSDF<TDataType>::compute()
33 {
34 cuExecute(this->inTets()->size(),
35 K_UpdateNormalSDF,
36 this->inPosition()->getData(),
37 this->inTets()->getData(),
38 this->inDisranceSDF()->getData(),
39 this->inNormalSDF()->getData()
40 );
41 }
42
43 /*template<typename TDataType>
44 void CalculateNormalSDF<TDataType>::resetStates()
45 {
46
47 }*/
48
49 DEFINE_CLASS(CalculateNormalSDF);
50}