1#include "ParticleSkinning.h"
2#include "ComputeSurfaceLevelSet.h"
6 IMPLEMENT_TCLASS(ParticleSkinning, TDataType)
8 template<typename TDataType>
9 ParticleSkinning<TDataType> ::ParticleSkinning()
12 this->stateLevelSet()->setDataPtr(std::make_shared<LevelSet<TDataType>>());
13 this->stateTriangleSet()->setDataPtr(std::make_shared<TriangleSet<TDataType>>());
14 this->statePoints()->allocate();
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);
24 template<typename TDataType>
25 void ParticleSkinning<TDataType>::resetStates() {
26 this->updateLevelset();
29 template<typename TDataType>
30 void ParticleSkinning<TDataType>::preUpdateStates() {
31 this->updateLevelset();
34 template<typename Coord>
35 __global__ void constrGridPosition(
36 DArray<Coord> GridPositions,
44 int gId = threadIdx.x + (blockIdx.x * blockDim.x);
45 if (gId >= GridPositions.size()) return;
47 uint nk = gId / (nx * ny);
48 uint nj = (gId % (nx * ny)) / ny;
51 GridPositions[gId][0] = (float)(ni)*h;
52 GridPositions[gId][1] = (float)(nj)*h;
53 GridPositions[gId][2] = (float)(nk)*h;
55 //if ((nk == 1) && (nj == 1))
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]);
63 template<typename TDataType>
64 void ParticleSkinning<TDataType> ::constrGridPositionArray() {
66 auto& sdf = this->stateLevelSet()->getDataPtr()->getSDF();
67 auto& leveset = this->stateLevelSet()->getDataPtr()->getSDF().distances();
69 int num = leveset.size();
70 std::cout <<"Grid number " << num << std::endl;
72 if (this->stateGridPoistion()->size() == 0)
74 this->stateGridPoistion()->resize(num);
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()
89 template<typename TDataType>
90 void ParticleSkinning<TDataType>::updateLevelset()
93 auto& sdf = this->stateLevelSet()->getDataPtr()->getSDF();
96 this->statePoints()->assign(this->getParticleSystem()->statePosition()->getData());
97 auto particles = this->statePoints()->getData();
99 std::cout << "Pos number : " << particles.size() << std::endl;
101 Reduction<Coord> reduce;
102 Coord hiBound = reduce.maximum(particles.begin(), particles.size());
103 Coord loBound = reduce.minimum(particles.begin(), particles.size());
105 Real h = this->stateGridSpacing()->getValue();
109 (Real)((int)(hiBound[0] / h)),
110 (Real)((int)(hiBound[1] / h)),
111 (Real)((int)(hiBound[2] / h)));
114 (Real)((int)(loBound[0] / h)),
115 (Real)((int)(loBound[1] / h)),
116 (Real)((int)(loBound[2] / h)));
118 std::cout << hiBound[0] << "," << hiBound[1] << "," << hiBound[2] << "," << std::endl;
119 std::cout << loBound[0] << "," << loBound[1] << "," << loBound[2] << "," << std::endl;
126 uint nx = (hiBound - loBound)[0] / h;
127 uint ny = (hiBound - loBound)[1] / h;
128 uint nz = (hiBound - loBound)[2] / h;
130 sdf.setSpace(loBound, hiBound, h);
132 constrGridPositionArray();
137 DEFINE_CLASS(ParticleSkinning);