public void GenerateOutline() { List <int> outline = new List <int>(); Outside outsider = m_outsiders[0]; Vector3i tri = m_triangles[outsider.Triangle]; int first = tri.GetValueByMember(outsider.Member); int second = tri.GetValueByMember(outsider.Member + 1); int startTriIndex = outsider.Triangle; outline.Add(first); outline.Add(second); Vector3i lastTri = tri; int lastMember = outsider.Member + 1; int lastVertex = lastTri.GetValueByMember(outsider.Member); int lastTriIndex = outsider.Triangle; while (true) { if (GetNextOutsideInfo(lastTri, lastMember, out outsider)) { lastTri = m_triangles[outsider.Triangle]; lastMember = outsider.Member + 1; lastVertex = lastTri.GetValueByMember(outsider.Member); lastTriIndex = outsider.Triangle; } else { lastMember++; if (lastTri.GetValueByMember(lastMember) == lastVertex) { if (lastVertex != first) { break; } } } int nextVertex = lastTri.GetValueByMember(lastMember); if (nextVertex == first) { break; } outline.Add(nextVertex); } GeneratedOutline = outline; }
public void SearchNext() { NextVertex = -1; NextTriangle = -1; float lowestAngle = 360.0f; for (int i = 0; i < m_triangles.Count; i++) { if (i == CurrentTriangle) { continue; } Vector3i triangle = m_triangles[i]; if (!triangle.ContainsValue(CurrentVertex)) { continue; } int checkVertexMember = triangle.GetMemberByValue(CurrentVertex); int checkVertex = triangle.GetValueByMember(checkVertexMember + 1); if (m_line.Contains(checkVertex)) { continue; } Vector2f checkVertexValue = m_vertices[checkVertex].ToVector2(); int checkTriangleIndex = i; if (checkVertexValue == CurrentVertexValue) { // recursivly find next non matching vertex m_line.Add(checkVertex); OutsideVertexSearcher deepSearcher = new OutsideVertexSearcher(this); deepSearcher.CurrentTriangle = i; deepSearcher.CurrentVertex = checkVertex; deepSearcher.SearchNext(); m_line.RemoveAt(m_line.Count - 1); if (deepSearcher.NextVertex == -1) { continue; } checkVertex = deepSearcher.NextVertex; checkVertexValue = m_vertices[deepSearcher.NextVertex].ToVector2(); checkTriangleIndex = deepSearcher.NextTriangle; } float angle = Vector2f.AngleFrom3Points(PreviousVertexValue, CurrentVertexValue, checkVertexValue); if (angle <= lowestAngle) { NextVertex = checkVertex; NextTriangle = checkTriangleIndex; lowestAngle = angle; } } }
private Vector3i GetNextNeighbor(Vector3i tri, int vertex) { int member = tri.GetMemberByValue(vertex); int nextVertex = tri.GetValueByMember(member + 1); foreach (int index in m_indexes) { Vector3i check = m_triangles[index]; if (check.ContainsValue(vertex) && check.ContainsValue(nextVertex)) { if (check != tri) { return(check); } } } return(default);
private bool GetNextOutsideInfo(Vector3i triangle, int member, out Outside result) { int vertex = triangle.GetValueByMember(member); foreach (Outside outsider in m_outsiders) { Vector3i check = m_triangles[outsider.Triangle]; if (check.GetValueByMember(outsider.Member) == vertex) { if (IsConnectedNeighbors(triangle, check, vertex)) { result = outsider; return(true); } } } result = default; return(false); }
private bool GetNextNeighbor(Vector3i tri, int vertex, out Vector3i result) { int member = tri.GetMemberByValue(vertex); int nextVertex = tri.GetValueByMember(member + 1); foreach (int index in m_indexes) { Vector3i check = m_triangles[index]; if (check.ContainsValue(vertex) && check.ContainsValue(nextVertex)) { if (check != tri) { result = check; return(true); } } } result = default; return(false); }
private static Vector2f[] VerticesToOutline(IReadOnlyList <Vector3f> vertexValues, List <Vector3i> vertices) { FindOutsideVertex(vertices, out int outsideVertexIndex, out int member); Vector3i outsideVertex = vertices[outsideVertexIndex]; List <int> line = new List <int>(); int point1 = outsideVertex.GetValueByMember(member); int point2 = outsideVertex.GetValueByMember(member + 1); line.Add(point1); line.Add(point2); int currentPoint = point2; int currentIndex = outsideVertexIndex; Vector2f prevPointValue = vertexValues[point1].ToVector2(); Vector2f curPointValue = vertexValues[point2].ToVector2(); while (true) { int nextPoint = -1; int nextVertexIndex = -1; float lowestAngle = 360.0f; for (int i = 0; i < vertices.Count; i++) { if (i == currentIndex) { continue; } Vector3i vertex = vertices[i]; if (!vertex.ContainsValue(currentPoint)) { continue; } int checkPointMember = vertex.GetMemberByValue(currentPoint); int checkPoint = vertex.GetValueByMember(checkPointMember + 1); if (line.Contains(checkPoint)) { continue; } Vector2f nextPointValue = vertexValues[checkPoint].ToVector2(); float angle = Vector2f.AngleFrom3Points(prevPointValue, curPointValue, nextPointValue); if (angle < lowestAngle) { nextPoint = checkPoint; nextVertexIndex = i; lowestAngle = angle; } } if (nextVertexIndex == -1) { Vector3i currentVertex = vertices[currentIndex]; int nextPointMember = currentVertex.GetMemberByValue(currentPoint); nextPoint = currentVertex.GetValueByMember(nextPointMember + 1); nextVertexIndex = currentIndex; if (line.Contains(nextPoint)) { break; } } prevPointValue = curPointValue; curPointValue = vertexValues[nextPoint].ToVector2(); currentPoint = nextPoint; line.Add(nextPoint); currentIndex = nextVertexIndex; } Vector2f[] outline = new Vector2f[line.Count]; for (int i = 0; i < line.Count; i++) { outline[i] = vertexValues[line[i]].ToVector2(); } HashSet <int> deletePoints = new HashSet <int>(); foreach (int point in line) { deletePoints.Add(point); } while (true) { bool isNew = false; for (int i = 0; i < vertices.Count; i++) { Vector3i vertex = vertices[i]; if (deletePoints.Contains(vertex.X)) { isNew |= deletePoints.Add(vertex.Y); isNew |= deletePoints.Add(vertex.Z); vertices.RemoveAt(i--); } else if (deletePoints.Contains(vertex.Y)) { isNew |= deletePoints.Add(vertex.Z); isNew |= deletePoints.Add(vertex.X); vertices.RemoveAt(i--); } else if (deletePoints.Contains(vertex.Z)) { isNew |= deletePoints.Add(vertex.X); isNew |= deletePoints.Add(vertex.Y); vertices.RemoveAt(i--); } } if (!isNew) { break; } } return(outline); }
private Vector2f[] GenerateOutline() { FindOutsideTriangle(out int outsideTriangleIndex, out int outsideMember); Vector3i outsideTriangle = m_triangles[outsideTriangleIndex]; List <int> line = new List <int>(); int vertex1 = outsideTriangle.GetValueByMember(outsideMember); int vertex2 = outsideTriangle.GetValueByMember(outsideMember + 1); line.Add(vertex1); line.Add(vertex2); OutsideVertexSearcher searcher = new OutsideVertexSearcher(m_vertices, m_triangles, line); searcher.CurrentTriangle = outsideTriangleIndex; searcher.PreviousVertex = vertex1; searcher.CurrentVertex = vertex2; while (true) { searcher.SearchNext(); if (searcher.NextVertex == -1) { Vector3i currentTriangle = m_triangles[searcher.CurrentTriangle]; int nextPointMember = currentTriangle.GetMemberByValue(searcher.CurrentVertex); int nextVertex = currentTriangle.GetValueByMember(nextPointMember + 1); searcher.PreviousVertex = searcher.CurrentVertex; searcher.CurrentVertex = nextVertex; if (line.Contains(nextVertex)) { break; } } else { searcher.CurrentTriangle = searcher.NextTriangle; searcher.PreviousVertex = searcher.CurrentVertex; searcher.CurrentVertex = searcher.NextVertex; } line.Add(searcher.CurrentVertex); } Vector2f[] outline = new Vector2f[line.Count]; for (int i = 0; i < line.Count; i++) { outline[i] = m_vertices[line[i]].ToVector2(); } HashSet <int> deletePoints = new HashSet <int>(); foreach (int point in line) { deletePoints.Add(point); } while (true) { bool isNew = false; for (int i = 0; i < m_triangles.Count; i++) { Vector3i vertex = m_triangles[i]; if (deletePoints.Contains(vertex.X)) { isNew |= deletePoints.Add(vertex.Y); isNew |= deletePoints.Add(vertex.Z); m_triangles.RemoveAt(i--); } else if (deletePoints.Contains(vertex.Y)) { isNew |= deletePoints.Add(vertex.Z); isNew |= deletePoints.Add(vertex.X); m_triangles.RemoveAt(i--); } else if (deletePoints.Contains(vertex.Z)) { isNew |= deletePoints.Add(vertex.X); isNew |= deletePoints.Add(vertex.Y); m_triangles.RemoveAt(i--); } } if (!isNew) { break; } } return(outline); }