Ejemplo n.º 1
0
        protected override MergeArgs GetMin()
        {
            List <HeapNode <TriMesh.Face> > unMergable = new List <HeapNode <TriMesh.Face> >();
            HeapNode <TriMesh.Face>         node       = this.heap.Pull();

            while (node != null && !TriMeshModify.IsMergeable(node.Item))
            {
                unMergable.Add(node);
                node = heap.Pull();
            }

            foreach (var item in unMergable)
            {
                this.heap.Add(item);
            }

            if (node == null)
            {
                return(null);
            }
            else
            {
                Vector3D pos = this.GetPos(node.Item);
                return(new MergeArgs {
                    Target = node.Item, Pos = pos
                });
            }
        }
Ejemplo n.º 2
0
        protected override MergeArgs GetMin()
        {
            List <HeapNode <TriMesh.Vertex> > unMergable = new List <HeapNode <TriMesh.Vertex> >();
            HeapNode <TriMesh.Vertex>         node       = heap.Pull();

            while (node != null)
            {
                foreach (var hf in node.Item.HalfEdges)
                {
                    if (TriMeshModify.IsMergeable(hf.Edge))
                    {
                        foreach (var item in unMergable)
                        {
                            heap.Add(item);
                        }
                        Vector3D pos = hf.ToVertex.Traits.Position;
                        return(new MergeArgs()
                        {
                            Target = hf.Edge, Pos = pos
                        });
                    }
                }
                unMergable.Add(node);
                node = heap.Pull();
            }
            return(null);
        }
Ejemplo n.º 3
0
        public bool Del(HeapNode <T> item)
        {
            int pos = item.Pos;

            if (pos != 0)
            {
                nodes[pos]     = nodes[size];
                nodes[pos].Pos = pos;
                if (nodes[pos].Value > item.Value)
                {
                    FilterDown(pos);
                }
                else
                {
                    FilterUp(pos);
                }
                size--;
                item.Pos = 0;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        private int FilterDown(int pos)
        {
            HeapNode <T> temp = nodes[pos];

            while (!isLeaf(pos))
            {
                int smallChild = 2 * pos;
                if ((smallChild < size) && (nodes[smallChild].Value > nodes[smallChild + 1].Value))
                {
                    smallChild = smallChild + 1;
                }

                if (temp.Value > nodes[smallChild].Value)
                {
                    nodes[pos]     = nodes[smallChild];
                    nodes[pos].Pos = pos;
                    pos            = smallChild;
                }
                else
                {
                    break;
                }
            }
            nodes[pos]     = temp;
            nodes[pos].Pos = pos;
            return(pos);
        }
Ejemplo n.º 5
0
        public HeapNode <T> Add(HeapNode <T> item)
        {
            if (size >= capability)
            {
                return(null);
            }
            size++;
            nodes[size]     = item;
            nodes[size].Pos = size;

            int pos = FilterUp(size);

            return(nodes[pos]);
        }
Ejemplo n.º 6
0
        private int FilterUp(int pos)
        {
            HeapNode <T> temp = nodes[pos];

            while (temp.Value < nodes[pos / 2].Value)
            {
                nodes[pos]     = nodes[pos / 2];
                nodes[pos].Pos = pos;
                pos           /= 2;
            }
            nodes[pos]     = temp;
            nodes[pos].Pos = pos;
            return(pos);
        }
Ejemplo n.º 7
0
 public void Update(HeapNode <T> item, double value)
 {
     if (item.Pos != 0)
     {
         double old = item.Value;
         item.Value = value;
         if (value > old)
         {
             FilterDown(item.Pos);
         }
         else
         {
             FilterUp(item.Pos);
         }
     }
 }
Ejemplo n.º 8
0
        public HeapNode <T> Pull()
        {
            if (size == 0)
            {
                return(null);
            }
            HeapNode <T> node = nodes[1];

            nodes[1]    = nodes[size];
            nodes[size] = null;
            size--;

            if (size > 1)
            {
                FilterDown(1);
            }

            node.Pos = 0;
            return(node);
        }
Ejemplo n.º 9
0
        public HeapNode <T> Add(double value, T item)
        {
            HeapNode <T> node = new HeapNode <T>(value, item);

            return(this.Add(node));
        }