PeriDyno 1.0.0
Loading...
Searching...
No Matches
ParticleSkinning.cu
Go to the documentation of this file.
1#include "ParticleSkinning.h"
2#include "ComputeSurfaceLevelSet.h"
3
4namespace dyno
5{
6 IMPLEMENT_TCLASS(ParticleSkinning, TDataType)
7
8 template<typename TDataType>
9 ParticleSkinning<TDataType> ::ParticleSkinning()
10 :Node()
11 {
12 this->stateLevelSet()->setDataPtr(std::make_shared<LevelSet<TDataType>>());
13 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
14 this->statePoints()->allocate();
15
16 auto iso = std::make_shared<ComputeSurfaceLevelset<TDataType>>();
17 this->stateLevelSet()->connect(iso->inLevelSet());
18 this->stateGridSpacing()->connect(iso->inGridSpacing());
19 this->statePoints()->connect(iso->inPoints());
20 this->animationPipeline()->pushModule(iso);
21
22 }
23
24 template<typename TDataType>
25 void ParticleSkinning<TDataType>::resetStates() {
26 this->updateLevelset();
27 };
28
29 template<typename TDataType>
30 void ParticleSkinning<TDataType>::preUpdateStates() {
31 this->updateLevelset();
32 };
33
34 template<typename Coord>
35 __global__ void constrGridPosition(
36 DArray<Coord> GridPositions,
37 Coord lo,
38 int nx,
39 int ny,
40 int nz,
41 Real h
42 )
43 {
44 int gId = threadIdx.x + (blockIdx.x * blockDim.x);
45 if (gId >= GridPositions.size()) return;
46
47 uint nk = gId / (nx * ny);
48 uint nj = (gId % (nx * ny)) / ny;
49 uint ni = (gId % ny);
50
51 GridPositions[gId][0] = (float)(ni)*h;
52 GridPositions[gId][1] = (float)(nj)*h;
53 GridPositions[gId][2] = (float)(nk)*h;
54
55 //if ((nk == 1) && (nj == 1))
56 //{
57 // //printf("ijk: %f, %f, %f \r\n", GridPositions[gId][0], GridPositions[gId][1], GridPositions[gId][2]);
58 // printf("%f, %f, %f \r\n", h[0], h[1], h[2]);
59 //}
60
61 };
62
63 template<typename TDataType>
64 void ParticleSkinning<TDataType> ::constrGridPositionArray() {
65
66 auto& sdf = this->stateLevelSet()->getDataPtr()->getSDF();
67 auto& leveset = this->stateLevelSet()->getDataPtr()->getSDF().distances();
68
69 int num = leveset.size();
70 std::cout <<"Grid number " << num << std::endl;
71
72 if (this->stateGridPoistion()->size() == 0)
73 {
74 this->stateGridPoistion()->resize(num);
75 }
76
77 cuExecute(num, constrGridPosition,
78 this->stateGridPoistion()->getData(),
79 this->stateLevelSet()->getDataPtr()->getSDF().lowerBound(),
80 this->stateLevelSet()->getDataPtr()->getSDF().nx(),
81 this->stateLevelSet()->getDataPtr()->getSDF().ny(),
82 this->stateLevelSet()->getDataPtr()->getSDF().nz(),
83 this->stateLevelSet()->getDataPtr()->getSDF().getGridSpacing()
84 )
85
86
87 };
88
89 template<typename TDataType>
90 void ParticleSkinning<TDataType>::updateLevelset()
91 {
92
93 auto& sdf = this->stateLevelSet()->getDataPtr()->getSDF();
94
95
96 this->statePoints()->assign(this->getParticleSystem()->statePosition()->getData());
97 auto particles = this->statePoints()->getData();
98
99 std::cout << "Pos number : " << particles.size() << std::endl;
100
101 Reduction<Coord> reduce;
102 Coord hiBound = reduce.maximum(particles.begin(), particles.size());
103 Coord loBound = reduce.minimum(particles.begin(), particles.size());
104
105 Real h = this->stateGridSpacing()->getValue();
106
107
108 hiBound = h * Coord(
109 (Real)((int)(hiBound[0] / h)),
110 (Real)((int)(hiBound[1] / h)),
111 (Real)((int)(hiBound[2] / h)));
112
113 loBound = h * Coord(
114 (Real)((int)(loBound[0] / h)),
115 (Real)((int)(loBound[1] / h)),
116 (Real)((int)(loBound[2] / h)));
117
118 std::cout << hiBound[0] << "," << hiBound[1] << "," << hiBound[2] << "," << std::endl;
119 std::cout << loBound[0] << "," << loBound[1] << "," << loBound[2] << "," << std::endl;
120
121
122
123
124 hiBound += 8.0 * h;
125 loBound -= 8.0 * h;
126 uint nx = (hiBound - loBound)[0] / h;
127 uint ny = (hiBound - loBound)[1] / h;
128 uint nz = (hiBound - loBound)[2] / h;
129
130 sdf.setSpace(loBound, hiBound, h);
131
132 constrGridPositionArray();
133
134 };
135
136
137 DEFINE_CLASS(ParticleSkinning);
138}