private FaceIndex IndexCells(Triangles triangles) { var zero = 0; var fals = false; var index = new FaceIndex(WorkBufferPool); triangles.Fill(index.Cells); //First get cells and canonicalize var cells = index.Cells; var nc = cells.UsedSize; var cellsData = cells.Data; for (var i = 0; i < nc; ++i) { var c = cellsData[i]; var x = c.x; var y = c.y; var z = c.z; if (y < z) { if (y < x) { c.x = y; c.y = z; c.z = x; cellsData[i] = c; } } else if (z < x) { c.x = z; c.y = x; c.z = y; cellsData[i] = c; } } WorkBuffer <Int3> .Sort(cells); //Initialize flag array var flags = index.Flags; flags.Fill(ref zero, nc); //Build neighbor index, initialize queues var active = index.Active; var next = index.Next; var neighbor = index.Neighbor; var constraint = index.Constraint; var boundary = index.Boundary; neighbor.Fill(ref zero, nc * 3); constraint.Fill(ref fals, nc * 3); var flagsData = flags.Data; var neighborData = neighbor.Data; var constraintData = constraint.Data; for (var i = 0; i < nc; ++i) { var c = cellsData[i]; for (var j = 0; j < 3; ++j) { var x = 0; var y = 0; switch (j) { case 0: x = c.x; y = c.y; break; case 1: x = c.y; y = c.z; break; case 2: x = c.z; y = c.x; break; } var a = neighborData[3 * i + j] = Locate(cells, y, x, triangles.Opposite(y, x)); var b = constraintData[3 * i + j] = triangles.IsConstraint(x, y); if (a < 0) { if (b) { next.Push(ref i); } else { active.Push(ref i); flagsData[i] = 1; } if (Infinity) { var v = new Int3(y, x, -1); boundary.Push(ref v); } } } } return(index); }
public void Do(Triangles triangles, List <int> result) { using (var index = IndexCells(triangles)) { var cellN = index.Cells.UsedSize; if (result.Capacity < cellN * 3) { result.Capacity = cellN * 3; } result.Clear(); if (Target == 0) { if (Infinity) { FillTriangles(index.Cells, result); FillTriangles(index.Boundary, result); return; } else { FillTriangles(index.Cells, result); return; } } var side = 1; var active = index.Active; var next = index.Next; var flags = index.Flags; var flagsData = flags.Data; var cells = index.Cells; var constraint = index.Constraint; var constraintData = constraint.Data; var neighbor = index.Neighbor; var neighborData = neighbor.Data; while (active.UsedSize > 0 || next.UsedSize > 0) { while (active.UsedSize > 0) { var t = active.Pop(); if (flagsData[t] == -side) { continue; } flagsData[t] = side; for (var j = 0; j < 3; ++j) { var f = neighborData[3 * t + j]; if (f >= 0 && flagsData[f] == 0) { if (constraintData[3 * t + j]) { next.Push(ref f); } else { active.Push(ref f); flagsData[f] = side; } } } } //Swap arrays and loop var tmp = next; next = active; active = tmp; next.Clear(); side = -side; } FilterCells(cells, flags); FillTriangles(cells, result); if (Infinity) { FillTriangles(index.Boundary, result); } } }