public void DrawSupertetrahedron() { Bounds meshBounds = _mesh.bounds; _superTetra = Tetra.ComputeCircumTetraOfSphere(meshBounds.center, meshBounds.extents.magnitude); _superTetra.Show(Color.red, 1000); }
public TriangleFace(Vertex p1, Vertex p2, Vertex p3, Tetra tetra) { P1 = p1; P2 = p2; P3 = p3; RightTetra = tetra; LeftTetra = null; }
public TriangleFace(Tetra tetra, Tetra otherTetra) { tetra.GetCommonVerticesWith(otherTetra, out Vertex p1, out Vertex p2, out Vertex p3); P1 = p1; P2 = p2; P3 = p3; LeftTetra = tetra; RightTetra = otherTetra; }
public bool HasACommonVertexWith(Tetra otherTetra) { HashSet <Vertex> tetraVertices = new HashSet <Vertex>() { P1, P2, P3, P4 }; HashSet <Vertex> otherTetraVertices = new HashSet <Vertex>() { otherTetra.P1, otherTetra.P2, otherTetra.P3, otherTetra.P4 }; tetraVertices.IntersectWith(otherTetraVertices); return(tetraVertices.Count >= 1); }
public void Init() { Mesh mesh = _meshFilter.sharedMesh; _vector3vertices = mesh.vertices; _numberOfVertices = _vector3vertices.Length; FillVeticesArray(); _normals = mesh.normals; _triangles = mesh.triangles; _numberOfTriangles = _triangles.Length; Bounds meshBounds = mesh.bounds; _superTetra = Tetra.ComputeCircumTetraOfSphere(meshBounds.center, meshBounds.extents.magnitude); }
public bool IsNeighborOf(Tetra otherTetra) { HashSet <Vertex> tetraVertices = new HashSet <Vertex>() { P1, P2, P3, P4 }; HashSet <Vertex> otherTetraVertices = new HashSet <Vertex>() { otherTetra.P1, otherTetra.P2, otherTetra.P3, otherTetra.P4 }; tetraVertices.IntersectWith(otherTetraVertices); // Two tetrahedrons are neighbors if and only if they share 3 vertices; return(tetraVertices.Count == 3); }
public void RegisterNeighbor(Tetra tetra) { if (LeftTetra == null) { LeftTetra = tetra; } else if (RightTetra == null) { RightTetra = tetra; } else { throw new System.Exception("Trying to register a neighboring tetrahedron to a triangle that already has two neighbors."); } }
public Tetra GetOtherTetraThan(Tetra tetra) { if (tetra.Equals(RightTetra)) { return(LeftTetra); } else if (tetra.Equals(LeftTetra)) { return(RightTetra); } else { tetra.Show(Color.red, 100); Show(Color.cyan, 100); throw new System.Exception("The given tetrahedron is not one of the neighbors of the triangle face"); } }
private HashSet <TriangleFace> GetPolygonalHoleFromBadTetras(HashSet <Tetra> badTetras) { HashSet <TriangleFace> polyHole = new HashSet <TriangleFace>(); foreach (Tetra badTetra in badTetras) { foreach (TriangleFace face in badTetra.Faces) { Tetra otherTetraOfFace = face.GetOtherTetraThan(badTetra); if (!badTetras.Contains(otherTetraOfFace)) { TriangleFace newFace = new TriangleFace(face.P1, face.P2, face.P3, otherTetraOfFace); polyHole.Add(newFace); } } } return(polyHole); }
public override bool Equals(object obj) { Tetra tetra = obj as Tetra; if (tetra == null) { return(false); } Vertex[] tetraVertices = new Vertex[4]; tetraVertices[0] = tetra.P1; tetraVertices[1] = tetra.P2; tetraVertices[2] = tetra.P3; tetraVertices[3] = tetra.P4; return(tetra != null && tetraVertices.Contains(P1) && tetraVertices.Contains(P2) && tetraVertices.Contains(P3) && tetraVertices.Contains(P4)); }
public void ComputeDelaunayTriangulation() { HashSet <Tetra> triangulation = new HashSet <Tetra> { _superTetra }; foreach (Vertex vertex in _vertices) { HashSet <Tetra> badTetras = GetBadTetrasInCurrentTriangulation(triangulation, vertex); HashSet <TriangleFace> polyHole = GetPolygonalHoleFromBadTetras(badTetras); RemoveBadTetras(triangulation, badTetras); HashSet <Tetra> tetrasToAdd = GetNewTetrasFromPolygonalHole(vertex, polyHole); AddNewTetrasToTriangulation(triangulation, tetrasToAdd); _triangulation = triangulation; } RemoveTetrasFromSuperTetra(triangulation); _triangulation = triangulation; Tetra.Show(triangulation, Color.green, 1000); }
public void GetCommonVerticesWith(Tetra otherTetra, out Vertex p1, out Vertex p2, out Vertex p3) { if (IsNeighborOf(otherTetra)) { HashSet <Vertex> tetraVertices = new HashSet <Vertex>() { P1, P2, P3, P4 }; HashSet <Vertex> otherTetraVertices = new HashSet <Vertex>() { otherTetra.P1, otherTetra.P2, otherTetra.P3, otherTetra.P4 }; tetraVertices.IntersectWith(otherTetraVertices); List <Vertex> commonVertices = new List <Vertex>(tetraVertices); p1 = commonVertices[0]; p2 = commonVertices[1]; p3 = commonVertices[2]; } else { throw new Exception("The two tetrahedrons are not neighbors"); } }
private HashSet <Tetra> GetNewTetrasFromPolygonalHole(Vertex vertex, HashSet <TriangleFace> polyHole) { HashSet <Tetra> tetrasToAdd = new HashSet <Tetra>(); foreach (TriangleFace face in polyHole) { Tetra newTetra = new Tetra(face, vertex); tetrasToAdd.Add(newTetra); } foreach (Tetra tetra in tetrasToAdd) { foreach (Tetra otherTetra in tetrasToAdd) { if (tetra.IsNeighborOf(otherTetra)) { TriangleFace face = new TriangleFace(tetra, otherTetra); tetra.AddNeighbor(face); } } } return(tetrasToAdd); }