private int GetPointIndex(TriVertex V) { int Result = FindPointIndex(V); Debug.Assert(Result != -1, "Invalid vertex in GetPointIndex"); return(Result); }
public void BuildTriangleLinks() { // Ensure all the indices are correct // Triangles.DumpTriangleList('c:\TriangleList_BeforeNumber.txt'); // Vertices.DumpVertexList('c:\VertexList_BeforeNumber.txt'); Vertices.NumberVertices(); Triangles.NumberTriangles(); // Vertices.DumpVertexList('c:\VertexList_AfterNumber.txt'); // Triangles.DumpTriangleList('c:\TriangleList_AfterNumber.txt'); // Create point triangle lists List <List <Triangle> > Trianglelists = new List <List <Triangle> >(Vertices.Count + 1); // Add a dummy list to make the indices of the lists agree with the indices in the tag property Trianglelists.Add(new List <Triangle>()); for (int i = 0; i < Vertices.Count; i++) { Trianglelists.Add(new List <Triangle>()); } // Vertices.DumpVertexList('c:\VertexList_AfterTriangleListCreate.txt'); // Associate triangles with points for (int i = 0; i < Triangles.Count; i++) { for (int Side = 0; Side < 3; Side++) { Trianglelists[Triangles[i].Vertices[Side].Tag].Add(Triangles[i]); } } // Find the neighbour for each triangle side for (int i = 0; i < Triangles.Count; i++) { for (int Side = 0; Side < 3; Side++) { if (Triangles[i].Neighbours[Side] != null) { continue; } TriVertex FromVertex = Triangles[i].Vertices[Side]; TriVertex ToVertex = Triangles[i].Vertices[XYZ.NextSide(Side)]; Triangle Nbr = FindNeighbour(Trianglelists, Triangles[i], FromVertex, ToVertex); Triangles[i].Neighbours[Side] = Nbr; if (Nbr != null) { int NbrSide = Nbr.GetSideIndex(FromVertex, ToVertex); Nbr.Neighbours[NbrSide] = Triangles[i]; } } } }
public Triangle AddTriangle(TriVertex Vertex1, TriVertex Vertex2, TriVertex Vertex3) { Triangle Result = null; if (!(Vertex1 == Vertex2 || Vertex1 == Vertex3 || Vertex2 == Vertex3)) { Result = CreateTriangle(Vertex1, Vertex2, Vertex3); Add(Result); } return(Result); }
/* Re-include if required, and add unit tests for them at that time. * public bool CrossesNeighbour(int Side) * { * Triangle NbrTri = Neighbours[Side]; * * if (NbrTri == null) * return false; * * TriVertex SideStartPt = Vertices[Side]; * TriVertex SideEndPt = Vertices[XYZ.NextSide(Side)]; * TriVertex OppositePt = Vertices[XYZ.PrevSide(Side)]; * int NbrSide = NbrTri.GetSideIndex(SideStartPt, SideEndPt); * TriVertex NbrOppositePt = NbrTri.Vertices[XYZ.PrevSide(NbrSide)]; * * return XYZ.PointOnRight(SideStartPt.XYZ, SideEndPt.XYZ, OppositePt.XYZ) == XYZ.PointOnRight(SideStartPt.XYZ, SideEndPt.XYZ, NbrOppositePt.XYZ); * } * * public bool GetCrossingNeighbour(out int Side) * { * Side = 0; * * for (int i = 0; i < 3; i++) * { * if (CrossesNeighbour(i)) * { * Side = i; * return true; * } * } * * return false; * } */ public int GetSideIndex(TriVertex VertexA, TriVertex VertexB) { int Result = GetPointIndex(VertexA); if (VertexB != Vertices[XYZ.NextSide(Result)]) { Result = XYZ.PrevSide(Result); Debug.Assert(Vertices[Result] == VertexB, "Invalid vertex pair in GetSideIndex"); } return(Result); }
/* Re-include if required, and add unit tests for them at that time. * /// <summary> * /// FFlags is a general purpose flags field for a triangle. It is not persistent * /// (ie: is not written to the TTM file) * /// </summary> * public ushort Flags { get; set; } * * protected bool GetFlag(int Index) => (Flags & (1 << Index)) != 0; * * protected void SetFlag(int Index, bool Value) * { * Flags = (ushort) (Value ? Flags | (1 << Index) : Flags & ~(1 << Index)); * } */ public Triangle(TriVertex Vertex1, TriVertex Vertex2, TriVertex Vertex3) { Vertices[0] = Vertex1; Vertices[1] = Vertex2; Vertices[2] = Vertex3; Neighbours[0] = null; Neighbours[1] = null; Neighbours[2] = null; /* Re-include if required, and add unit tests for them at that time. * Flags = 0; */ }
private int FindPointIndex(TriVertex V) { int result = -1; if (V == Vertices[0]) { result = 0; } else if (V == Vertices[1]) { result = 1; } else if (V == Vertices[2]) { result = 2; } return(result); }
public DesignTriangleEdge(TriVertex vertex1, TriVertex vertex2) { Stamped = false; Vertex1 = vertex1; Vertex2 = vertex2; }
private Triangle FindNeighbour(List <List <Triangle> > Trianglelists, Triangle triangle, TriVertex fromVertex, TriVertex toVertex) { for (int i = 0; i < Trianglelists[fromVertex.Tag].Count; i++) { Triangle Result = Trianglelists[fromVertex.Tag][i]; if (Result != triangle && Trianglelists[toVertex.Tag].IndexOf(Result) >= 0) { return(Result); } } return(null); }
/// <summary> /// Determine if another TriVertex coordinate is the same as the coordinate of this vertex within a given tolerance /// </summary> /// <param name="Other"></param> /// <param name="Tolerance"></param> /// <returns></returns> public bool IsEqual(TriVertex Other, double Tolerance) { return(Other == this || IsEqual(Other.X, Other.Y, Other.Z, Tolerance)); }
public Triangle CreateTriangle(TriVertex Vertex1, TriVertex Vertex2, TriVertex Vertex3) => CreateTriangleFunc(Vertex1, Vertex2, Vertex3);
public TTMTriangle(TriVertex Vertex1, TriVertex Vertex2, TriVertex Vertex3) : base(Vertex1, Vertex2, Vertex3) { }