public UniqueEdgeList(UniqueEdgeList other)
 {
     foreach (Edge edge in other.edgeList)
     {
         this.Add(edge);
     }
 }
示例#2
0
    public bool StepThree(ref UniqueEdgeList edges)
    {
        foreach (Edge edge_outer in edges.edgeList)
        {
            foreach (Edge edge_inner in edges.edgeList)
            {
                if (!Edge.SameEdge(edge_inner, edge_outer))
                {
                    float[] shared_vertex = Edge.HasSharedVertex(edge_inner, edge_outer);
                    bool    is_parallel   = Edge.AreParallelOrAntiParallel(edge_inner, edge_outer);

                    if (shared_vertex != null && is_parallel)
                    {
                        // Case 1.
                        float[] start_vertex = new float[] { edge_inner.x1, edge_inner.y1, edge_inner.z1 };

                        // Case 2.
                        if (edge_inner.x1 == shared_vertex[0] &&
                            edge_inner.y1 == shared_vertex[1] &&
                            edge_inner.z1 == shared_vertex[2])
                        {
                            start_vertex = new float[] { edge_inner.x2, edge_inner.y2, edge_inner.z2 };
                        }

                        // Case 3.
                        float[] end_vertex = new float[] { edge_outer.x1, edge_outer.y1, edge_outer.z1 };

                        // Case 4.
                        if (edge_outer.x1 == shared_vertex[0] &&
                            edge_outer.y1 == shared_vertex[1] &&
                            edge_outer.z1 == shared_vertex[2])
                        {
                            end_vertex = new float[] { edge_outer.x2, edge_outer.y2, edge_outer.z2 };
                        }

                        edges.edgeList.Remove(edge_outer);
                        edges.edgeList.Remove(edge_inner);
                        edges.Add(
                            new Edge(
                                start_vertex[0], start_vertex[1], start_vertex[2], // Edge Start
                                end_vertex[0], end_vertex[1], end_vertex[2]        // Edge end
                                ));

                        return(StepThree(ref edges));
                    }
                }
            }
        }
        return(true);
    }
示例#3
0
    // Step 3. Simply outline. (Remove edges that are connecting and colinear)
    // Input: List of edges.
    // Output: List of edges with no colinear and connecting edges.
    void StepThree()
    {
        StepThree(ref outline_edges);

        outline_edges_refined = outline_edges;
        outline_edges_refined.Print();

        foreach (Edge edge in outline_edges_refined.edgeList)
        {
            edgeColors.Add(new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)));
        }

        return;
    }
示例#4
0
    void DrawEdges(UniqueEdgeList edges, Color color)
    {
        if (edges != null && edges.edgeList.Count == 0)
        {
            return;
        }

        int i = 0;

        foreach (Edge edge in edges.edgeList)
        {
            Debug.DrawLine(
                new Vector3(edge.x1, edge.y1, edge.z1),
                new Vector3(edge.x2, edge.y2, edge.z2),
                edgeColors[i++]);
        }
        return;
    }
    /// <summary>
    /// This is a - b, not b - a
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <returns></returns>
    public static UniqueEdgeList SetDifference(UniqueEdgeList a, UniqueEdgeList b)
    {
        UniqueEdgeList result = new UniqueEdgeList();

        foreach (Edge edge_a in a.edgeList)
        {
            bool found = false;
            foreach (Edge edge_b in b.edgeList)
            {
                if (Edge.SameEdge(edge_a, edge_b))
                {
                    found = true;
                }
            }
            if (!found)
            {
                result.Add(edge_a);
            }
        }
        return(result);
    }
示例#6
0
    /// <summary>
    /// Sorting the edges that are contiguous into boundary groups/buckets.
    /// </summary>
    public void StepThreePartTwo()
    {
        // Add first bucket.
        UniqueEdgeList first_bucket = new UniqueEdgeList();

        first_bucket.Add(outline_edges_refined.edgeList[0]);
        grouped_edges.Add(first_bucket);

        foreach (Edge edge in outline_edges_refined.edgeList)
        {
            bool found = false;
            foreach (UniqueEdgeList group in grouped_edges)
            {
                foreach (Edge edge_from_bucket in group.edgeList)
                {
                    if (Edge.HasSharedVertex(edge, edge_from_bucket) != null)
                    {
                        group.Add(edge);
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }
            if (!found)
            {
                UniqueEdgeList new_bucket = new UniqueEdgeList();
                new_bucket.Add(edge);
                grouped_edges.Add(new_bucket);
            }
        }

        return;
    }
示例#7
0
    // Step 2. Remove shared edges.
    // Input: List of triangles.
    // Output: List of edges that were not shared by other edges in the triangles.
    void StepTwo()
    {
        // Check every triangle against all other triangles.
        for (int m = 0; m < input_triangles.GetLength(0); ++m)
        {
            for (int n = 0; n < input_triangles.GetLength(0); ++n)
            {
                // Not the same triangle.
                if (m != n)
                {
                    for (int i = 0; i < 3; ++i)
                    {
                        int j = i + 1;
                        if (i == 2)
                        {
                            j = 0;
                        }

                        Edge tri1_edge = new Edge(
                            input_triangles[m, i, 0], input_triangles[m, i, 1], input_triangles[m, i, 2],
                            input_triangles[m, j, 0], input_triangles[m, j, 1], input_triangles[m, j, 2]);

                        all_edges.Add(tri1_edge);

                        // a --> b == (b - a)
                        Edge tri2_edge01 = new Edge(
                            input_triangles[n, 0, 0], input_triangles[n, 0, 1], input_triangles[n, 0, 2],
                            input_triangles[n, 1, 0], input_triangles[n, 1, 1], input_triangles[n, 1, 2]);

                        Edge tri2_edge12 = new Edge(
                            input_triangles[n, 1, 0], input_triangles[n, 1, 1], input_triangles[n, 1, 2],
                            input_triangles[n, 2, 0], input_triangles[n, 2, 1], input_triangles[n, 2, 2]);

                        Edge tri2_edge20 = new Edge(
                            input_triangles[n, 2, 0], input_triangles[n, 2, 1], input_triangles[n, 2, 2],
                            input_triangles[n, 0, 0], input_triangles[n, 0, 1], input_triangles[n, 0, 2]);

                        if (Edge.AreOverlappingEdges(tri1_edge, tri2_edge01))
                        {
                            shared_edges.Add(tri1_edge);
                        }
                        if (Edge.AreOverlappingEdges(tri1_edge, tri2_edge12))
                        {
                            shared_edges.Add(tri1_edge);
                        }
                        if (Edge.AreOverlappingEdges(tri1_edge, tri2_edge20))
                        {
                            shared_edges.Add(tri1_edge);
                        }
                    }
                }
            }
        }
        outline_edges = UniqueEdgeList.SetDifference(all_edges, shared_edges);

        //shared_edges.Print();
        //Debug.Log("OUTLINE EDGES");
        //outline_edges.Print();
        //all_edges.Print();
        return;
    }