Exemplo n.º 1
0
 void CutStart()
 {
     for (int i = 0; i < this.edgeQueue.Count; i++)
     {
         VertexPair edge1 = this.edgeQueue.Dequeue();
         for (int j = 0; j < this.edgeQueue.Count; j++)
         {
             VertexPair       edge2 = this.edgeQueue.Dequeue();
             TriMesh.HalfEdge hf1   = null;
             TriMesh.HalfEdge hf2   = null;
             if (edge1.Src == edge2.Src)
             {
                 hf1 = edge1.Dst.FindHalfedgeTo(edge1.Src);
                 hf2 = edge2.Src.FindHalfedgeTo(edge2.Dst);
             }
             else if (edge1.Src == edge2.Dst)
             {
                 hf1 = edge1.Dst.FindHalfedgeTo(edge1.Src);
                 hf2 = edge2.Dst.FindHalfedgeTo(edge2.Src);
             }
             else if (edge1.Dst == edge2.Src)
             {
                 hf1 = edge1.Src.FindHalfedgeTo(edge1.Dst);
                 hf2 = edge2.Src.FindHalfedgeTo(edge2.Dst);
             }
             else if (edge1.Dst == edge2.Dst)
             {
                 hf1 = edge1.Src.FindHalfedgeTo(edge1.Dst);
                 hf2 = edge2.Dst.FindHalfedgeTo(edge2.Src);
             }
             if (hf1 != null && hf2 != null)
             {
                 this.CutInner(hf1, hf2);
                 return;
             }
             else
             {
                 this.edgeQueue.Enqueue(edge2);
             }
         }
         this.edgeQueue.Enqueue(edge1);
     }
 }
Exemplo n.º 2
0
        public VertexMap Cut(double move)
        {
            this.vertexMap = new VertexMap(this.mesh);
            this.edgeQueue = new Queue <VertexPair>();
            this.move      = move;

            foreach (var edge in this.mesh.Edges)
            {
                if (edge.Traits.SelectedFlag != 0)
                {
                    this.edgeQueue.Enqueue(new VertexPair(edge.Vertex0, edge.Vertex1));
                }
            }

            bool boundary = false;

            foreach (var edge in this.edgeQueue)
            {
                if (edge.Src.OnBoundary || edge.Dst.OnBoundary)
                {
                    boundary = true;
                    break;
                }
            }

            if (!boundary)
            {
                this.CutStart();
            }

            int count = 1;

            while (this.edgeQueue.Count != 0 && count < this.edgeQueue.Count)
            {
                VertexPair   pair = this.edgeQueue.Dequeue();
                TriMesh.Edge edge = pair.Src.FindEdgeTo(pair.Dst);
                if (edge != null)
                {
                    if (this.Cut(edge))
                    {
                        count = 0;
                    }
                    else
                    {
                        this.edgeQueue.Enqueue(pair);
                        count++;
                    }
                }
                else
                {
                    TriMesh.Vertex[] map1 = this.vertexMap.GetOther(pair.Src, false);
                    TriMesh.Vertex[] map2 = this.vertexMap.GetOther(pair.Dst, false);

                    for (int m = 0; m < map1.Length; m++)
                    {
                        this.edgeQueue.Enqueue(new VertexPair(map1[m], pair.Dst));
                    }

                    for (int n = 0; n < map2.Length; n++)
                    {
                        this.edgeQueue.Enqueue(new VertexPair(pair.Src, map2[n]));
                    }

                    for (int m = 0; m < map1.Length; m++)
                    {
                        for (int n = 0; n < map2.Length; n++)
                        {
                            this.edgeQueue.Enqueue(new VertexPair(map1[m], map2[n]));
                        }
                    }
                    count = 0;
                }
            }
            TriMeshUtil.FixIndex(mesh);

            return(this.vertexMap);
        }