1#include "AnchorPointToPointSet.h"
5 template<typename TDataType>
6 AnchorPointToPointSet<TDataType>::AnchorPointToPointSet()
11 template<typename Coord, typename Matrix, typename Joint>
12 __global__ void setUpAnchorPoints(
14 DArray<Matrix> rotMat,
16 DArray<Coord> vertices,
20 int tId = threadIdx.x + blockIdx.x * blockDim.x;
21 if (tId >= joints.size())
24 int idx1 = joints[tId].bodyId1;
25 int idx2 = joints[tId].bodyId2;
27 Coord r1 = rotMat[idx1] * joints[tId].r1;
28 Coord r2 = rotMat[idx2] * joints[tId].r2;
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;
36 template<typename TDataType>
37 bool AnchorPointToPointSet<TDataType>::apply()
39 auto topo = this->inDiscreteElements()->constDataPtr();
41 if (this->outPointSet()->isEmpty()) {
42 this->outPointSet()->allocate();
45 auto& ballAndSocketJoints = topo->ballAndSocketJoints();
46 auto& sliderJoints = topo->sliderJoints();
47 auto& hingeJoints = topo->hingeJoints();
48 auto& fixedJoints = topo->fixedJoints();
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;
57 if (anchorPointSize == 0)
60 auto outset = this->outPointSet()->getDataPtr();
62 auto& vertices = outset->getPoints();
63 vertices.resize(anchorPointSize * 2);
65 if (ballAndSocketJoints_size > 0)
67 cuExecute(ballAndSocketJoints_size,
70 this->inRotationMatrix()->getData(),
71 this->inCenter()->getData(),
76 if (sliderJoints_size > 0)
78 int begin_index = 2 * ballAndSocketJoints_size;
79 cuExecute(sliderJoints_size,
82 this->inRotationMatrix()->getData(),
83 this->inCenter()->getData(),
88 if (hingeJoints_size > 0)
90 int begin_index = 2 * (ballAndSocketJoints_size + sliderJoints_size);
91 cuExecute(hingeJoints_size,
94 this->inRotationMatrix()->getData(),
95 this->inCenter()->getData(),
100 if (fixedJoint_size > 0)
102 int begin_index = 2 * (ballAndSocketJoints_size + sliderJoints_size + hingeJoints_size);
103 cuExecute(fixedJoint_size,
106 this->inRotationMatrix()->getData(),
107 this->inCenter()->getData(),
115 DEFINE_CLASS(AnchorPointToPointSet);