PeriDyno 1.0.0
Loading...
Searching...
No Matches
AnchorPointToPointSet.cu
Go to the documentation of this file.
1#include "AnchorPointToPointSet.h"
2
3namespace dyno
4{
5 template<typename TDataType>
6 AnchorPointToPointSet<TDataType>::AnchorPointToPointSet()
7 : TopologyMapping()
8 {
9 }
10
11 template<typename Coord, typename Matrix, typename Joint>
12 __global__ void setUpAnchorPoints(
13 DArray<Joint> joints,
14 DArray<Matrix> rotMat,
15 DArray<Coord> pos,
16 DArray<Coord> vertices,
17 int begin_index
18 )
19 {
20 int tId = threadIdx.x + blockIdx.x * blockDim.x;
21 if (tId >= joints.size())
22 return;
23
24 int idx1 = joints[tId].bodyId1;
25 int idx2 = joints[tId].bodyId2;
26
27 Coord r1 = rotMat[idx1] * joints[tId].r1;
28 Coord r2 = rotMat[idx2] * joints[tId].r2;
29
30 Coord v0 = pos[idx1] + r1;
31 Coord v1 = pos[idx2] + r2;
32 vertices[2 * tId + begin_index] = v0;
33 vertices[2 * tId + 1 + begin_index] = v1;
34 }
35
36 template<typename TDataType>
37 bool AnchorPointToPointSet<TDataType>::apply()
38 {
39 auto topo = this->inDiscreteElements()->constDataPtr();
40
41 if (this->outPointSet()->isEmpty()) {
42 this->outPointSet()->allocate();
43 }
44
45 auto& ballAndSocketJoints = topo->ballAndSocketJoints();
46 auto& sliderJoints = topo->sliderJoints();
47 auto& hingeJoints = topo->hingeJoints();
48 auto& fixedJoints = topo->fixedJoints();
49
50 uint anchorPointSize = 0;
51 uint ballAndSocketJoints_size = ballAndSocketJoints.size();
52 uint sliderJoints_size = sliderJoints.size();
53 uint hingeJoints_size = hingeJoints.size();
54 uint fixedJoint_size = fixedJoints.size();
55 anchorPointSize += ballAndSocketJoints_size + sliderJoints_size + hingeJoints_size + fixedJoint_size;
56
57 if (anchorPointSize == 0)
58 return false;
59
60 auto outset = this->outPointSet()->getDataPtr();
61
62 auto& vertices = outset->getPoints();
63 vertices.resize(anchorPointSize * 2);
64
65 if (ballAndSocketJoints_size > 0)
66 {
67 cuExecute(ballAndSocketJoints_size,
68 setUpAnchorPoints,
69 ballAndSocketJoints,
70 this->inRotationMatrix()->getData(),
71 this->inCenter()->getData(),
72 vertices,
73 0);
74 }
75
76 if (sliderJoints_size > 0)
77 {
78 int begin_index = 2 * ballAndSocketJoints_size;
79 cuExecute(sliderJoints_size,
80 setUpAnchorPoints,
81 sliderJoints,
82 this->inRotationMatrix()->getData(),
83 this->inCenter()->getData(),
84 vertices,
85 begin_index);
86 }
87
88 if (hingeJoints_size > 0)
89 {
90 int begin_index = 2 * (ballAndSocketJoints_size + sliderJoints_size);
91 cuExecute(hingeJoints_size,
92 setUpAnchorPoints,
93 hingeJoints,
94 this->inRotationMatrix()->getData(),
95 this->inCenter()->getData(),
96 vertices,
97 begin_index);
98 }
99
100 if (fixedJoint_size > 0)
101 {
102 int begin_index = 2 * (ballAndSocketJoints_size + sliderJoints_size + hingeJoints_size);
103 cuExecute(fixedJoint_size,
104 setUpAnchorPoints,
105 fixedJoints,
106 this->inRotationMatrix()->getData(),
107 this->inCenter()->getData(),
108 vertices,
109 begin_index);
110 }
111
112 return true;
113 }
114
115 DEFINE_CLASS(AnchorPointToPointSet);
116}