Exemplo n.º 1
0
 /// <summary>
 /// isDamagedEdge
 /// judge if an edge is damaged
 /// </summary>
 /// <param name="edge">the edge to be judged</param>
 public bool isDamagedEdge(Edge3D edge)
 {
     foreach (var damage in damages)
     {
         if (damage.edge.Equals(edge))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
    /// <summary>
    /// tryAddEdge
    /// find the edge in current edges.
    /// if exists, return its index
    /// if not, insert it and return its new index
    /// </summary>
    /// <param name="edge">the edge to insert or find</param>
    public int tryAddEdge(Edge3D edge)
    {
        var index = edges.FindIndex(edg => edg == edge);

        if (index == -1)
        {
            edges.Add(edge);
            return(edges.Count - 1);
        }
        else
        {
            return(index);
        }
    }
Exemplo n.º 3
0
    public int tryAddEdge(int from, int to)
    {
        var edge = new Edge2D(from, to);

        if (edges.Contains(edge))
        {
            return(edges.FindIndex(edg => edg == edge));
        }
        else
        {
            edges.Add(edge);
            return(edges.Count - 1);
        }
    }
Exemplo n.º 4
0
    public static List <List <int> > floodSplit3D(ref VolumeticMesh3D mesh)
    {
        var unassignedNodes = new List <int>();

        for (int i = 0; i < mesh.nodes.Count; ++i)
        {
            unassignedNodes.Add(i);
        }
        var fragmentCount = 0;
        var nodes         = new List <List <int> >();

        while (unassignedNodes.Count != 0)
        {
            var newFragmentId = fragmentCount;
            fragmentCount++;

            List <int> queue = new List <int>();
            queue.Add(unassignedNodes[0]);
            unassignedNodes.RemoveAt(0);

            int targetNode = queue[0];
            while (queue.Count != 0)
            {
                targetNode = queue[0];
                if (nodes.Count <= newFragmentId)
                {
                    nodes.Add(new List <int>());
                }
                nodes[newFragmentId].Add(targetNode);
                foreach (var ne in mesh.getNeighborNodes(targetNode))
                {
                    if (!queue.Contains(ne) && unassignedNodes.Contains(ne))
                    {
                        Edge edge = new Edge(ne, targetNode);
                        if (!mesh.isDamagedEdge(edge))
                        {
                            queue.Add(ne);
                            unassignedNodes.Remove(ne);
                        }
                    }
                }
                queue.RemoveAt(0);
            }
        }

        return(nodes);
    }
Exemplo n.º 5
0
    public static List <List <int> > floodSplit2D(ref VolumeticMesh2D mesh)
    {
        var unassignedNodes = new List <int>();

        for (int i = 0; i < mesh.nodes.Count; ++i)
        {
            unassignedNodes.Add(i);
        }
        var fragmentCount = 0;
        var nodes         = new List <List <int> >();


        int ccc0 = 0;

        while (unassignedNodes.Count != 0)
        {
            if (ccc0++ > 100)
            {
                Debug.Log("Too many loops");
                break;
            }

            Debug.Log(unassignedNodes.Count);

            var newFragmentId = fragmentCount;
            fragmentCount++;

            List <int> queue = new List <int>();
            queue.Add(unassignedNodes[0]);
            unassignedNodes.RemoveAt(0);

            int targetNode = queue[0];

            int ccc1 = 0;
            while (queue.Count != 0)
            {
                if (ccc1++ > 100)
                {
                    Debug.Log("Too many loops");
                    break;
                }

                if (nodes.Count <= newFragmentId)
                {
                    nodes.Add(new List <int>());
                }
                nodes[newFragmentId].Add(targetNode);

                int ccc2 = 0;
                foreach (var ne in mesh.getNeighbors(targetNode))
                {
                    if (ccc2++ > 100)
                    {
                        Debug.Log("Too many loops");
                        break;
                    }

                    if (!queue.Contains(ne) && unassignedNodes.Contains(ne))
                    {
                        Edge edge = new Edge(ne, targetNode);
                        if (!mesh.isDamagedEdge(edge))
                        {
                            queue.Add(ne);
                            unassignedNodes.Remove(ne);
                        }
                    }
                }
                queue.RemoveAt(0);
            }
        }

        return(nodes);
    }
Exemplo n.º 6
0
    /// <summary>
    /// tryAddNode
    /// find the node in current nodes.
    /// if exists, return its index
    /// if not, insert it and return its new index
    /// </summary>
    /// <param name="from">one tail of the edge. choose which tail is irrelevant.</param>
    /// <param name="to">one tail of the edge. choose which tail is irrelevant.</param>
    public int tryAddEdge(int from, int to)
    {
        var edge = new Edge3D(from, to);

        return(tryAddEdge(edge));
    }
Exemplo n.º 7
0
 public Damage3D(Edge3D Edge, double CutPosition)
 {
     this.edge        = Edge;
     this.cutPosition = CutPosition;
 }
Exemplo n.º 8
0
    public VolumeticMesh2D generateMesh()
    {
        var mesh = new VolumeticMesh2D();

        Mesh rawMesh = GetComponent <MeshFilter>().mesh;

        var vertices = rawMesh.vertices;

        foreach (var vertex in vertices)
        {
            mesh.nodes.Add(new Vector2(vertex.x, vertex.y));
        }

        var calculator = new GK.DelaunayCalculator();
        var result     = calculator.CalculateTriangulation(mesh.nodes);
        var triangles  = result.Triangles;

        for (int i = 0; i < triangles.Count; i += 3)
        {
            var edgeA = new Edge2D(triangles[i], triangles[i + 2]);
            var edgeB = new Edge2D(triangles[i + 2], triangles[i + 1]);
            var edgeC = new Edge2D(triangles[i + 1], triangles[i]);

            int edgeIndexA, edgeIndexB, edgeIndexC;

            if (!mesh.edges.Contains(edgeA))
            {
                mesh.edges.Add(edgeA);
                edgeIndexA = mesh.edges.Count - 1;
            }
            else
            {
                edgeIndexA = mesh.edges.FindIndex(edge => edge == edgeA);
            }

            if (!mesh.edges.Contains(edgeB))
            {
                mesh.edges.Add(edgeB);
                edgeIndexB = mesh.edges.Count - 1;
            }
            else
            {
                edgeIndexB = mesh.edges.FindIndex(edge => edge == edgeB);
            }

            if (!mesh.edges.Contains(edgeC))
            {
                mesh.edges.Add(edgeC);
                edgeIndexC = mesh.edges.Count - 1;
            }
            else
            {
                edgeIndexC = mesh.edges.FindIndex(edge => edge == edgeC);
            }

            mesh.nodeJointIndexes.Add(new TriangleNodes2D(triangles[i], triangles[i + 2], triangles[i + 1]));
            mesh.edgeJointIndexes.Add(new TriangleEdges2D(edgeIndexA, edgeIndexB, edgeIndexC));
        }

        return(mesh);
    }