MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / computeHalfEdges

Method computeHalfEdges

src/collision/HalfEdgeStructure.cpp:35–121  ·  view source on GitHub ↗

Initialize the structure (when all vertices and faces have been added)

Source from the content-addressed store, hash-verified

33
34// Initialize the structure (when all vertices and faces have been added)
35void HalfEdgeStructure::computeHalfEdges() {
36
37 Map<VerticesPair, Edge> edges(mAllocator);
38 Map<VerticesPair, VerticesPair> nextEdges(mAllocator);
39 Map<VerticesPair, uint32> mapEdgeToStartVertex(mAllocator);
40 Map<VerticesPair, uint32> mapEdgeToIndex(mAllocator);
41 Map<uint32, VerticesPair> mapEdgeIndexToKey(mAllocator);
42 Map<uint32, VerticesPair> mapFaceIndexToEdgeKey(mAllocator);
43
44 Array<VerticesPair> currentFaceEdges(mAllocator, mFaces[0].faceVertices.size());
45
46 // For each face
47 const uint32 nbFaces = static_cast<uint32>(mFaces.size());
48 for (uint32 f=0; f < nbFaces; f++) {
49
50 Face& face = mFaces[f];
51
52 VerticesPair firstEdgeKey(0, 0);
53
54 // For each vertex of the face
55 const uint32 nbFaceVertices = static_cast<uint32>(face.faceVertices.size());
56 for (uint32 v=0; v < nbFaceVertices; v++) {
57 uint32 v1Index = face.faceVertices[v];
58 uint32 v2Index = face.faceVertices[v == (face.faceVertices.size() - 1) ? 0 : v + 1];
59
60 const VerticesPair pairV1V2 = VerticesPair(v1Index, v2Index);
61
62 // Create a new half-edge
63 Edge edge;
64 edge.faceIndex = f;
65 edge.vertexIndex = v1Index;
66 if (v == 0) {
67 firstEdgeKey = pairV1V2;
68 }
69 else if (v >= 1) {
70 nextEdges.add(Pair<VerticesPair, VerticesPair>(currentFaceEdges[currentFaceEdges.size() - 1], pairV1V2));
71 }
72 if (v == (face.faceVertices.size() - 1)) {
73 nextEdges.add(Pair<VerticesPair, VerticesPair>(pairV1V2, firstEdgeKey));
74 }
75 edges.add(Pair<VerticesPair, Edge>(pairV1V2, edge));
76
77 const VerticesPair pairV2V1(v2Index, v1Index);
78
79 mapEdgeToStartVertex.add(Pair<VerticesPair, uint32>(pairV1V2, v1Index), true);
80 mapEdgeToStartVertex.add(Pair<VerticesPair, uint32>(pairV2V1, v2Index), true);
81
82 mapFaceIndexToEdgeKey.add(Pair<uint32, VerticesPair>(f, pairV1V2), true);
83
84 auto itEdge = edges.find(pairV2V1);
85 if (itEdge != edges.end()) {
86
87 const uint32 edgeIndex = static_cast<uint32>(mEdges.size());
88
89 itEdge->second.twinEdgeIndex = edgeIndex + 1;
90 edge.twinEdgeIndex = edgeIndex;
91
92 mapEdgeIndexToKey.add(Pair<uint32, VerticesPair>(edgeIndex, pairV2V1));

Callers 5

testCubeMethod · 0.80
testTetrahedronMethod · 0.80

Calls 5

sizeMethod · 0.45
addMethod · 0.45
findMethod · 0.45
endMethod · 0.45
clearMethod · 0.45

Tested by 2

testCubeMethod · 0.64
testTetrahedronMethod · 0.64