예제 #1
0
 public void cleanInit()
 {
     graph        = new Microsoft.Msagl.Drawing.Graph("Huffman Tree");
     viewer.Graph = graph;
     viewer.Update();
     Dtable.Clear();
     dataGridView1.Update();
     textBox1.Text = "";
     textBox2.Text = "";
     textBox3.Text = "";
     label1.Text   = "Compression Ratio:";
 }
 public void cleanInit()
 {
     graph        = new Microsoft.Msagl.Drawing.Graph("Huffman Tree");
     viewer.Graph = graph;
     viewer.Update();
     Dtable.Clear();
     dataGridView1.Update();
     textBox1.Text  = "";
     textBox2.Text  = "";
     textBox3.Text  = "";
     mainInput      = "";
     encodedText    = "";
     decodedText    = "";
     label1.Text    = "Compression Ratio:";
     nodeZero       = new HuffmanNode();
     EncodeNodeList = new SortedDictionary <int, HuffmanNode>();
     EncodeNodeList.Add(nodeZero.Depth, nodeZero);
     firstReadOfChar = new List <char>();
     dynamicMap      = new Dictionary <char, HuffmanNode>();
 }
예제 #3
0
        void SelectNodeGraph()
        {
            // TODO: select nodes in selected Path
            Node selectedNode = gLocalViewer.SelectedObject as Node;

            if (selectedNode != null)
            {
                if (_prevSelectedNode != null)
                {
                    IGraphItem prevItem = _prevSelectedNode.UserData as GraphItem;
                    if (prevItem != null)
                    {
                        prevItem.IsSelected        = false;
                        _prevSelectedNode.UserData = prevItem;
                    }
                }

                GraphItem item = selectedNode.UserData as GraphItem;

                ColorButton.ColorButton nodeButton = new ColorButton.ColorButton();
                nodeButton.Text   = selectedNode.Id;
                nodeButton.Anchor = AnchorStyles.Top;
                nodeButton.Tag    = item;
                _selectedPath     = null;
                if (item.CurrentPathIndex > 0)
                {
                    DrawingHelper.SelectedPathItemUniqueID = item.QueryItem.Paths[item.CurrentPathIndex - 1].UniqueID;
                }
                DrawingHelper.SelectedNodeUniqueID = item.UniqueID;
                DrawingHelper.isEdgeSelected       = false;
                //ChangeSelectedFile(nodeButton, null);
                if (_pathItemClick != null)
                {
                    _pathItemClick(item.QueryItem.Paths[item.CurrentPathIndex - 1], null);
                }
                gLocalViewer.Refresh();
                gLocalViewer.ResumeLayout();
                gLocalViewer.Update();
                //_prevSelectedNode = selectedNode;
            }
        }
예제 #4
0
        private void CreateDynamicHuffmanTree(string text)
        {
            graph = new Microsoft.Msagl.Drawing.Graph("Huffman Tree");

            foreach (char c in text)
            {
                if (!firstReadOfChar.Contains(c))
                {
                    encodedText += nodeZero.getBit();
                    firstReadOfChar.Add(c);
                    HuffmanNode leafNode = new HuffmanNode(1, c, 0);
                    dynamicMap[c] = leafNode;
                    HuffmanNode newNode = new HuffmanNode(nodeZero, leafNode, nodeZero.Depth);
                    EncodeNodeList.Add(leafNode.Depth, leafNode);
                    EncodeNodeList[newNode.Depth] = newNode;
                    EncodeNodeList.Add(nodeZero.Depth, nodeZero);

                    updateGraph(EncodeNodeList);
                }
                else
                {
                    encodedText += dynamicMap[c].getBit();
                    dynamicMap[c].Frequency++;
                    updateGraph(EncodeNodeList);
                }
            }
            textBox5.Text = encodedText;
            double compressionRatio = 100.0 - Math.Floor((double)encodedText.Length / (double)(EncodeNodeList[256].Frequency * 8) * 100 * 100) / 100;

            this.label6.Text = "Compression Rate: " + compressionRatio.ToString() + "%";
            Dtable.Rows.Clear();
            createDynamicGraph(EncodeNodeList[256]);
            viewer2.Graph = graph;
            dataGridView2.Sort(dataGridView2.Columns[3], ListSortDirection.Ascending);
            dataGridView2.Update();
            viewer2.Update();
        }
예제 #5
0
 public void UpdateGraph(Microsoft.Msagl.Drawing.Graph graph)
 {
     viewer.Graph = graph;
     viewer.Update();
 }