public HalfEdge GetEdge(Vertex a, Vertex b, Face f, HalfEdge abNext) { List<HalfEdge> appropriateEdges; if (edges.ContainsKey(b)) { appropriateEdges = edges[b]; } else { appropriateEdges = new List<HalfEdge>(); edges[b] = appropriateEdges; } var query = appropriateEdges.Where(x => x.Twin.End == a); switch (query.Count()) { case 0: { HalfEdge edge = new HalfEdge(this, null, true); HalfEdge twin = edge.Twin; edge.End = b; twin.End = a; edge.Face = f; edge.Next = abNext; return edge; } case 1: { var edge = query.First(); if (abNext != null && edge.Next != abNext && edge.Next != null) throw new ArgumentException("Edge already attached to edge " + edge.Next); if (f != null && edge.Face != f && edge.Face != null) throw new ArgumentException("Edge already attached to face " + edge.Face); edge.Face = f ?? edge.Face; edge.Next = abNext ?? edge.Next; return edge; } default: throw new MeshMalformedException("More than one edge already exists between " + a + " and " + b); } }
public EndSplitMidpointHalfEdge(HalfEdge e, Vertex m) { //throw new NotImplementedException(); }
public DeleteHalfEdge(HalfEdge e) { Skip = false; Vertex sV = e.Twin.End; if (sV != null) { Start = sV.Position; StartName = sV.Name; } else { Start = default(Vector3); StartName = null; Skip = true; } Vertex eV = e.End; if (eV != null) { End = eV.Position; EndName = eV.Name; } else { End = default(Vector3); EndName = null; Skip = true; } }
public AddHalfEdge(HalfEdge h) { Start = h.Twin.End.Position; End = h.End.Position; }
public void SplitMidpointEnd(HalfEdge e, Vertex mid) { changes.Push(new EndSplitMidpointHalfEdge(e, mid)); }
public void SplitMidpointBegin(HalfEdge e, Vertex mid) { changes.Push(new BeginSplitMidpointHalfEdge(e, mid)); }
/// <summary> /// Merges this halfedge with the Next /// </summary> public void Merge() { if (Next == null) throw new InvalidOperationException("Next must not be null"); if (Face == null) throw new InvalidOperationException("Face must not be null"); if (Face != Next.Face) throw new InvalidOperationException("Cannot merge two edges bordering different faces"); if (Twin.Face != null && Twin.Face != Next.Twin.Face) throw new InvalidOperationException("Cannot merge two edges with twins bordering different faces"); HalfEdge oldNext = Next; Next = oldNext.Next; End = oldNext.End; if (Next.Twin.Next == oldNext.Twin) { Next.Twin.Next = Twin; Next.Twin.End = End; } if (Twin.Face != null) Twin.Face.Edges.Where(a => a.Next == oldNext.Twin).First().Next = Twin; oldNext.Face = null; oldNext.Twin.Face = null; oldNext.Next = null; oldNext.Twin.Next = null; if (Face.Edge == oldNext) Face.Edge = this; if (Twin.Face != null && Twin.Face.Edge == oldNext.Twin) Twin.Face.Edge = Twin; Mesh.Delete(oldNext); }
protected internal HalfEdge(Mesh m) { Mesh = m; Twin = new HalfEdge(m, this); Primary = true; }
public HalfEdge GetEdge(Vertex a, Vertex b, Face f, HalfEdge abNext, bool allowCreation = true) { return(GetEdge(a, b, f, abNext, null, null, allowCreation)); }
public HalfEdge GetEdge(Vertex a, Vertex b, Face abf, HalfEdge abNext, Face baf, HalfEdge baNext, bool allowCreation = true) { HashSet <HalfEdge> edgesEndingAtB = edges.GetOrAdd(b, k => new HashSet <HalfEdge>()); var query = edgesEndingAtB.Where(x => x.Twin.End == a); switch (query.Count()) { case 0: { if (allowCreation) { HalfEdge edge = new HalfEdge(this); HalfEdge twin = edge.Twin; edge.End = b; twin.End = a; edge.Face = abf; twin.Face = baf; edge.Next = abNext; twin.Next = baNext; InformAddEdge(edge); return(edge); } else { return(null); } } case 1: { var edge = query.First(); if (abNext != null && edge.Next != abNext && edge.Next != null) { throw new ArgumentException("Edge already attached to edge " + edge.Next); } if (baNext != null && edge.Twin.Next != baNext && edge.Twin.Next != null) { throw new ArgumentException("Twin edge already attached to edge " + edge.Twin.Next); } if (abf != null && edge.Face != abf && edge.Face != null) { throw new ArgumentException("Edge already attached to face " + edge.Face); } if (baf != null && edge.Twin.Face != baf && edge.Twin.Face != null) { throw new ArgumentException("Twin edge already attached to face " + edge.Twin.Face); } edge.Face = abf ?? edge.Face; edge.Next = abNext ?? edge.Next; edge.Twin.Face = baf ?? edge.Twin.Face; edge.Twin.Next = baNext ?? edge.Twin.Next; return(edge); } default: throw new MeshMalformedException("More than one edge already exists between " + a + " and " + b); } }
private HalfEdge(Mesh m, HalfEdge twin) { Mesh = m; Twin = twin; Primary = false; }
internal HalfEdge(Mesh m, HalfEdge twin, bool primary) { Mesh = m; Twin = primary ? new HalfEdge(m, this, false) : twin; Primary = primary; }
public void Added(HalfEdge e) { changes.Push(new AddHalfEdge(e)); }
public void Deleted(HalfEdge e) { changes.Push(new DeleteHalfEdge(e)); }
public HalfEdge GetEdge(Vertex a, Vertex b, Face abf, HalfEdge abNext, Face baf, HalfEdge baNext) { throw new NotImplementedException(); }