Beispiel #1
0
    /// In the construction of the data structure we generate the initial square
    /// centered in 0,0,0 and with side 2.
    /// The structures that hold the data are created and filled
    public DataStructure()
    {
        step        = 0;
        unfoldCount = 0;

        faceTree = new FaceTree();
        edgeBTL  = new EdgeBinaryTreeList();
        vertexLL = new VertexLinkedList();

        Vertex v1 = new Vertex(new Vector3(-1, 1, 0), step);
        Vertex v2 = new Vertex(new Vector3(1, 1, 0), step);
        Vertex v3 = new Vertex(new Vector3(1, -1, 0), step);
        Vertex v4 = new Vertex(new Vector3(-1, -1, 0), step);

        Edge e1 = new Edge(v1, v2, step);
        Edge e2 = new Edge(v2, v3, step);
        Edge e3 = new Edge(v3, v4, step);
        Edge e4 = new Edge(v4, v1, step);

        v1.addEdge(e1);
        v1.addEdge(e4);

        v2.addEdge(e1);
        v2.addEdge(e2);

        v3.addEdge(e2);
        v3.addEdge(e3);

        v4.addEdge(e3);
        v4.addEdge(e4);

        List <Vertex> vList = new List <Vertex>();

        vList.Add(v1);
        vList.Add(v2);
        vList.Add(v3);
        vList.Add(v4);

        List <Edge> eList = new List <Edge>();

        eList.Add(e1);
        eList.Add(e2);
        eList.Add(e3);
        eList.Add(e4);

        Face f = new Face(vList, step);

        vertexLL.addVertex(v1);
        vertexLL.addVertex(v2);
        vertexLL.addVertex(v3);
        vertexLL.addVertex(v4);

        edgeBTL.addEdge(e1);
        edgeBTL.addEdge(e2);
        edgeBTL.addEdge(e3);
        edgeBTL.addEdge(e4);

        faceTree.setRoot(f);
    }
Beispiel #2
0
    // Creates vertices, edges and faces and inserts them in the model's strucutre
    public void generateNewCreases(Plane p)
    {
        List <EdgeNode>   activeEdgeNodes = edgeBTL.getLeaveNodes();
        List <VertexNode> activeVertices  = getVertices();
        List <VertexNode> prevCutVertices = new List <VertexNode>();
        List <VertexNode> cutVertices     = new List <VertexNode>();

        /// si tallo un vertex el tinc en compte d(etermineSide =0)
        for (int i = 0; i < activeVertices.Count; i++)
        {
            if (p.determineSide(activeVertices[i].peek()) == 0)
            {
                cutVertices.Add(activeVertices[i]);
                prevCutVertices.Add(activeVertices[i]);
            }
        }
        //prevCutVertices = cutVertices;
        List <VertexNode> vNode = getVertices();

        /// per cada aresta que es talla faig split i genero un vertex
        for (int i = 0; i < activeEdgeNodes.Count; i++)
        {
            EdgeNode   parent = activeEdgeNodes[i];
            VertexNode o      = parent.edge.origin;
            VertexNode e      = parent.edge.end;


            Vector3 point = parent.edge.isCut(p);

            Vector3 inf = new Vector3(9999, 9999, 9999);

            bool close = isClose(point, prevCutVertices);

            if (point != inf && !close)
            {
                Vertex v = new Vertex(point, step, vertexLL.vll.Count);
                vertexLL.count++;
                VertexNode vn = new VertexNode(v);
                cutVertices.Add(vn);
                vertexLL.addVertex(vn);

                Edge edgel = new Edge(o, vn, step, edgeBTL.count);
                edgeBTL.count++;
                EdgeNode ls = new EdgeNode(parent, edgel);
                vn.addEdge(edgel);
                edgel.origin.edges.Remove(parent.edge);
                edgel.origin.addEdge(edgel);

                Edge edger = new Edge(vn, e, step, edgeBTL.count);
                edgeBTL.count++;
                EdgeNode rs = new EdgeNode(parent, edger);
                vn.addEdge(edger);
                edger.end.edges.Remove(parent.edge);
                edger.end.addEdge(edger);

                for (int j = 0; j < parent.edge.faces.Count; j++)
                {
                    parent.edge.faces[j].extraV.Add(vn);
                }

                parent.setSons(ls, rs);
            }
        }

        /// per cada vertex que comparteix cara 2 a 2 genero una aresta
        for (int i = 0; i < cutVertices.Count; i++)
        {
            for (int j = i + 1; j < cutVertices.Count; j++)
            {
                FaceNode f = shareFace(cutVertices[i], cutVertices[j]);
                if (f != null && !doesEdgeExist(cutVertices[i], cutVertices[j]))
                {
                    Edge e = new Edge(cutVertices[i], cutVertices[j], step, edgeBTL.count);
                    edgeBTL.count++;
                    cutVertices[i].addEdge(e);
                    cutVertices[j].addEdge(e);

                    edgeBTL.addEdge(e);

                    List <VertexNode> l  = f.face.vList;
                    List <VertexNode> l1 = new List <VertexNode>();
                    List <VertexNode> l2 = new List <VertexNode>();
                    int side;

                    l1.Add(cutVertices[i]);
                    l2.Add(cutVertices[i]);
                    l1.Add(cutVertices[j]);
                    l2.Add(cutVertices[j]);

                    for (int k = 0; k < l.Count; k++)
                    {
                        side = p.determineSide(l[k].peek());
                        if (side == 1)
                        {
                            l1.Add(l[k]);
                        }
                        else if (side == -1)
                        {
                            l2.Add(l[k]);
                        }
                    }
                    Face f1 = new Face(l1, step, faceTree.count);
                    faceTree.count++;
                    Face f2 = new Face(l2, step, faceTree.count);
                    faceTree.count++;


                    FaceNode fn1 = new FaceNode(f, f1);
                    FaceNode fn2 = new FaceNode(f, f2);

                    for (int k = 0; k < l1.Count; k++)
                    {
                        for (int m = k + 1; m < l1.Count; m++)
                        {
                            Edge foundEdge = edgeExists(l1[k], l1[m]);
                            if (foundEdge != null)
                            {
                                foundEdge.faces.Add(f1);
                            }
                        }
                    }
                    for (int k = 0; k < l2.Count; k++)
                    {
                        for (int m = k + 1; m < l2.Count; m++)
                        {
                            Edge foundEdge = edgeExists(l2[k], l2[m]);
                            if (foundEdge != null)
                            {
                                foundEdge.faces.Add(f2);
                            }
                        }
                    }
                }
            }
        }
        List <Face> faces = getFaces();

        for (int i = 0; i < faces.Count; i++)
        {
            //faces[i].sortVertices();
        }

        List <Edge> activeE = getEdges();

        for (int i = 0; i < activeE.Count; i++)
        {
            activeE[i].cleanFaces(faces);
        }
    }
Beispiel #3
0
    // Creates vertices, edges and faces and inserts them in the model's strucutre
    public void generateNewCreases(Plane p)
    {
        List <EdgeNode> activeEdgeNodes = edgeBTL.getLeaveNodes();
        List <Vertex>   activeVertices  = getVertices();

        List <Vertex> cutVertices = new List <Vertex>();

        /// si tallo un vertex el tinc en compte d(etermineSide =0)
        for (int i = 0; i < activeVertices.Count; i++)
        {
            if (p.determineSide(activeVertices[i]) == 0)
            {
                cutVertices.Add(activeVertices[i]);
            }
        }

        /// per cada aresta que es talla faig split i genero un vertex
        for (int i = 0; i < activeEdgeNodes.Count; i++)

        {
            EdgeNode parent = activeEdgeNodes[i];
            Vertex   o      = parent.getEdge().origin;
            Vertex   e      = parent.getEdge().end;


            Vector3 point = parent.getEdge().isCut(p);

            Vector3 inf = new Vector3(999999, 999999, 999999);

            if (point != inf)
            {
                Vertex v = new Vertex(point, step);
                cutVertices.Add(v);
                vertexLL.addVertex(v);

                Edge     edgel = new Edge(o, v, step);
                EdgeNode ls    = new EdgeNode(parent, edgel);

                Edge     edger = new Edge(v, e, step);
                EdgeNode rs    = new EdgeNode(parent, edger);

                v.addEdge(edgel);
                v.addEdge(edger);

                parent.setSons(ls, rs);
            }
        }

        /// per cada vertex que comparteix cara 2 a 2 genero una aresta
        for (int i = 0; i < cutVertices.Count; i++)
        {
            for (int j = i + 1; j < cutVertices.Count; j++)
            {
                FaceNode f = shareFace(cutVertices[i], cutVertices[j]);
                if (f != null)
                {
                    Edge e = new Edge(cutVertices[i], cutVertices[j], step);
                    cutVertices[i].addEdge(e);
                    cutVertices[j].addEdge(e);

                    edgeBTL.addEdge(e);

                    /// genero cares
                    /// agafo tots els vertex de la cara original i elsdaquesta aresta nova
                    /// filtro repetits
                    ///si estan a laresta van als dos
                    ///s determineside de tots
                    ///0 als 2
                    ///1 a f1
                    ///-1 f2
                    ///
                    List <Vertex> l = f.getFace().getVertices();

                    if (!l.Contains(cutVertices[i]))
                    {
                        l.Add(cutVertices[i]);
                    }
                    if (!l.Contains(cutVertices[j]))
                    {
                        l.Add(cutVertices[j]);
                    }
                    int           side;
                    List <Vertex> l1 = new List <Vertex>();
                    List <Vertex> l2 = new List <Vertex>();

                    for (int k = 0; k < l.Count; k++)
                    {
                        side = p.determineSide(l[k]);
                        if (side == 1)
                        {
                            l1.Add(l[k]);
                        }
                        else if (side == -1)
                        {
                            l2.Add(l[k]);
                        }
                        else
                        {
                            l1.Add(l[k]);
                            l2.Add(l[k]);
                        }
                    }

                    Face f1 = new Face(l1, step);
                    Face f2 = new Face(l2, step);

                    FaceNode fn1 = new FaceNode(f, f1);
                    FaceNode fn2 = new FaceNode(f, f2);

                    f.addSon(fn1);
                    f.addSon(fn2);
                }
            }
        }
    }
Beispiel #4
0
    // In the construction of the data structure we generate the initial square centered in 0,0,0 and with side 2. The structures that hold the data are created and filled
    public DataStructure(Vector3 v)
    {
        camToModel  = v;
        step        = 0;
        unfoldCount = 0;

        faceTree = new FaceTree();
        edgeBTL  = new EdgeBinaryTreeList();
        vertexLL = new VertexLinkedList();

        Vertex v1 = new Vertex(new Vector3(-1, 1, 0), step, 0);
        Vertex v2 = new Vertex(new Vector3(1, 1, 0), step, 1);
        Vertex v3 = new Vertex(new Vector3(1, -1, 0), step, 2);
        Vertex v4 = new Vertex(new Vector3(-1, -1, 0), step, 3);

        VertexNode vn1 = new VertexNode(v1);
        VertexNode vn2 = new VertexNode(v2);
        VertexNode vn3 = new VertexNode(v3);
        VertexNode vn4 = new VertexNode(v4);

        Edge e1 = new Edge(vn1, vn2, step, 0);
        Edge e2 = new Edge(vn2, vn3, step, 1);
        Edge e3 = new Edge(vn3, vn4, step, 2);
        Edge e4 = new Edge(vn4, vn1, step, 3);


        vn1.addEdge(e1);
        vn1.addEdge(e4);

        vn2.addEdge(e1);
        vn2.addEdge(e2);

        vn3.addEdge(e2);
        vn3.addEdge(e3);

        vn4.addEdge(e3);
        vn4.addEdge(e4);

        List <VertexNode> vList = new List <VertexNode>();

        vList.Add(vn1);
        vList.Add(vn2);
        vList.Add(vn3);
        vList.Add(vn4);

        List <Edge> eList = new List <Edge>();

        eList.Add(e1);
        eList.Add(e2);
        eList.Add(e3);
        eList.Add(e4);

        Face f = new Face(vList, step, 0);

        for (int i = 0; i < 4; i++)
        {
            eList[i].faces.Add(f);
        }

        vertexLL.addVertex(vn1);
        vertexLL.addVertex(vn2);
        vertexLL.addVertex(vn3);
        vertexLL.addVertex(vn4);

        edgeBTL.addEdge(e1);
        edgeBTL.addEdge(e2);
        edgeBTL.addEdge(e3);
        edgeBTL.addEdge(e4);
        edgeBTL.count = 4;

        faceTree.setRoot(f);
        faceTree.count = 1;
    }