Skip to content
Snippets Groups Projects
Commit 7dd6e8d6 authored by Andrew Wilson's avatar Andrew Wilson :elephant:
Browse files

PERF: TriangleToTetMap now in O(n+m) instead of O(n*m)

parent 767a5805
No related branches found
No related tags found
No related merge requests found
......@@ -58,17 +58,14 @@ TriangleToTetMap::computeTriToTetMap(std::unordered_map<int, int>& triToTetMap)
auto tetMesh = std::dynamic_pointer_cast<TetrahedralMesh>(getParentGeometry());
auto surfMesh = std::dynamic_pointer_cast<SurfaceMesh>(getChildGeometry());
//std::shared_ptr<VecDataArray<double, 3>> tetVerticesPtr = tetMesh->getVertexPositions();
//const VecDataArray<double, 3>& tetVertices = *tetVerticesPtr;
std::shared_ptr<VecDataArray<int, 4>> tetIndicesPtr = tetMesh->getTetrahedraIndices();
const VecDataArray<int, 4>& tetIndices = *tetIndicesPtr;
//std::shared_ptr<VecDataArray<double, 3>> surfVerticesPtr = surfMesh->getVertexPositions();
//const VecDataArray<double, 3>& surfVertices = *surfVerticesPtr;
std::shared_ptr<VecDataArray<int, 3>> surfIndicesPtr = surfMesh->getTriangleIndices();
const VecDataArray<int, 3>& surfIndices = *surfIndicesPtr;
// Brute force
// Hash all the triangles from the surface
std::unordered_map<TriCell, int> triToFaceId;
for (int i = 0; i < surfIndices.size(); i++)
{
const Vec3i& tri = surfIndices[i];
......@@ -82,22 +79,30 @@ TriangleToTetMap::computeTriToTetMap(std::unordered_map<int, int>& triToTetMap)
// Hash the triangle with the tet mesh ids
TriCell cell_a(id0, id1, id2);
// Find the corresponding tet
for (int j = 0; j < tetIndices.size(); j++)
{
const Vec4i& tet = tetIndices[j];
triToFaceId[cell_a] = i;
}
// For every face of the tet
for (int k = 0; k < 4; k++)
// Hash all the triangles from the tetrahedron faces. Take note of
// collisions
// Find the corresponding tet
for (int i = 0; i < tetIndices.size(); i++)
{
const Vec4i& tet = tetIndices[i];
// For every face of the tet
for (int k = 0; k < 4; k++)
{
TriCell cell_b(
tet[facePattern[k][0]],
tet[facePattern[k][1]],
tet[facePattern[k][2]]);
// If this tet face exists in the map of hashed triangles
auto iter = triToFaceId.find(cell_b);
if (iter != triToFaceId.end())
{
TriCell cell_b(
tet[facePattern[k][0]],
tet[facePattern[k][1]],
tet[facePattern[k][2]]);
if (cell_a == cell_b)
{
triToTetMap[i] = j;
}
const int triId = iter->second;
triToTetMap[triId] = i; // Map tri to tet id
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment