PeriDyno 1.0.0
Loading...
Searching...
No Matches
ContactsToEdgeSet.cu
Go to the documentation of this file.
1#include "ContactsToEdgeSet.h"
2
3namespace dyno
4{
5 IMPLEMENT_TCLASS(ContactsToEdgeSet, TDataType);
6
7 template<typename TDataType>
8 ContactsToEdgeSet<TDataType>::ContactsToEdgeSet()
9 : TopologyMapping()
10 {
11 }
12
13 template<typename Coord, typename Edge>
14 __global__ void SetupContactInfo(
15 DArray<Coord> vertices,
16 DArray<Edge> indices,
17 DArray<TContactPair<Real>> contacts,
18 Real scale)
19 {
20 int tId = threadIdx.x + (blockIdx.x * blockDim.x);
21 if (tId >= contacts.size()) return;
22
23 auto contact = contacts[tId];
24 Coord v0 = contact.pos1;
25 Coord v1 = contact.pos1 + contact.normal1 * scale;
26
27 vertices[2 * tId] = v0;
28 vertices[2 * tId + 1] = v1;
29 indices[tId] = Edge(2 * tId, 2 * tId + 1);
30 }
31
32 template<typename TDataType>
33 bool ContactsToEdgeSet<TDataType>::apply()
34 {
35 if (this->outEdgeSet()->isEmpty())
36 {
37 this->outEdgeSet()->allocate();
38 }
39
40 auto& inContacts = this->inContacts()->getData();
41 auto outSet = this->outEdgeSet()->getDataPtr();
42
43 auto& vertices = outSet->getPoints();
44 auto& indices = outSet->getEdges();
45
46 uint contactNum = inContacts.size();
47 vertices.resize(2 * contactNum);
48 indices.resize(contactNum);
49
50 cuExecute(contactNum,
51 SetupContactInfo,
52 vertices,
53 indices,
54 inContacts,
55 this->varScale()->getData());
56
57 return true;
58 }
59
60 DEFINE_CLASS(ContactsToEdgeSet);
61}