/******************************************************************************** * ReactPhysics3D physics library, http://www.reactphysics3d.com * * Copyright (c) 2010-2016 Daniel Chappuis * ********************************************************************************* * * * This software is provided 'as-is', without any express or implied warranty. * * In no event will the authors be held liable for any damages arising from the * * use of this software. * * * * Permission is granted to anyone to use this software for any purpose, * * including commercial applications, and to alter it and redistribute it * * freely, subject to the following restrictions: * * * * 1. The origin of this software must not be misrepresented; you must not claim * * that you wrote the original software. If you use this software in a * * product, an acknowledgment in the product documentation would be * * appreciated but is not required. * * * * 2. Altered source versions must be plainly marked as such, and must not be * * misrepresented as being the original software. * * * * 3. This notice may not be removed or altered from any source distribution. * * * ********************************************************************************/ // Libraries #include "HalfEdgeStructure.h" #include "containers/Map.h" #include "containers/Pair.h" #include "containers/containers_common.h" using namespace reactphysics3d; // Initialize the structure (when all vertices and faces have been added) void HalfEdgeStructure::init() { Map edges(mAllocator); Map nextEdges(mAllocator); Map mapEdgeToStartVertex(mAllocator); Map mapEdgeToIndex(mAllocator); Map mapEdgeIndexToKey(mAllocator); Map mapFaceIndexToEdgeKey(mAllocator); List currentFaceEdges(mAllocator, mFaces[0].faceVertices.size()); // For each face for (uint f=0; f= 1) { nextEdges.add(Pair(currentFaceEdges[currentFaceEdges.size() - 1], pairV1V2)); } if (v == (face.faceVertices.size() - 1)) { nextEdges.add(Pair(pairV1V2, firstEdgeKey)); } edges.add(Pair(pairV1V2, edge)); const VerticesPair pairV2V1(v2Index, v1Index); mapEdgeToStartVertex.add(Pair(pairV1V2, v1Index), true); mapEdgeToStartVertex.add(Pair(pairV2V1, v2Index), true); mapFaceIndexToEdgeKey.add(Pair(f, pairV1V2), true); auto itEdge = edges.find(pairV2V1); if (itEdge != edges.end()) { const uint edgeIndex = mEdges.size(); itEdge->second.twinEdgeIndex = edgeIndex + 1; edge.twinEdgeIndex = edgeIndex; mapEdgeIndexToKey.add(Pair(edgeIndex, pairV2V1)); mapEdgeIndexToKey.add(Pair(edgeIndex + 1, pairV1V2)); mVertices[v1Index].edgeIndex = edgeIndex + 1; mVertices[v2Index].edgeIndex = edgeIndex; mapEdgeToIndex.add(Pair(pairV1V2, edgeIndex + 1)); mapEdgeToIndex.add(Pair(pairV2V1, edgeIndex)); mEdges.add(itEdge->second); mEdges.add(edge); } currentFaceEdges.add(pairV1V2); } currentFaceEdges.clear(); } // Set next edges for (uint i=0; i < mEdges.size(); i++) { mEdges[i].nextEdgeIndex = mapEdgeToIndex[nextEdges[mapEdgeIndexToKey[i]]]; } // Set face edge for (uint f=0; f < mFaces.size(); f++) { mFaces[f].edgeIndex = mapEdgeToIndex[mapFaceIndexToEdgeKey[f]]; } }