Exemple #1
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);
                }
            }
        }
    }
Exemple #2
0
    public void generateNewFlapCreases(Plane p, VertexNode v1)
    {
        List <EdgeNode>   activeEdgeNodes = edgeBTL.getLeaveNodes();
        List <VertexNode> activeVertices  = getVertices();
        List <Edge>       flapEdges       = v1.edges;
        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]);
            }
        }

        /// per cada aresta que es talla faig split i genero un vertex
        for (int i = 0; i < activeEdgeNodes.Count; i++)
        {
            if (flapEdges.Contains(activeEdgeNodes[i].edge))
            {
                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);
        }
    }