Beispiel #1
0
 /// <summary>
 /// Create a tree node.
 /// </summary>
 public PathTreeNode(Node node, Node.WalkableAxis axis, PathTreeNode father)
 {
     m_node   = node;
     m_axis   = axis;
     m_father = father;
     _nodes   = new List <PathTreeNode>();
 }
Beispiel #2
0
    public override bool Equals(object obj)
    {
        PathTreeNode node = (PathTreeNode)obj;

        return((node.m_node == m_node) &&
               (node.m_father == m_father) &&
               (node.m_axis == m_axis));
    }
Beispiel #3
0
    public void Init()
    {
        if (m_head == null)
        {
            Debug.LogError("Init tree fail! 'm_head' is not set!");
            return;
        }

        List <Node> visited = new List <Node>();

        visited.Add(m_head.m_node);
        m_head = RecusionGenerateTree(m_head, visited);
    }
Beispiel #4
0
    /// <summary>
    /// Recusion generate path tree
    /// </summary>
    private PathTreeNode RecusionGenerateTree(PathTreeNode father, List <Node> visited)
    {
        if (father == null)
        {
            return(null);
        }

        var connecPoints = Node.GetConnectTypeOnFace(father.m_axis);

        if (connecPoints == null)
        {
            return(father);
        }

        foreach (var connecPoint in connecPoints)
        {
            List <Node.AdjNodeInfo> nodeInfoList = father.m_node.m_adjNodes[connecPoint];

            if (nodeInfoList.Count == 0)
            {
                continue;
            }

            foreach (var nodeInfo in nodeInfoList)
            {
                if (visited.Contains(nodeInfo.m_adjNode))
                {
                    continue;
                }

                PathTreeNode newTreeNode = new PathTreeNode(nodeInfo.m_adjNode,
                                                            nodeInfo.m_adjWalkAxis,
                                                            father);
                visited.Add(newTreeNode.m_node);
                father.AddChild(newTreeNode);

                newTreeNode = RecusionGenerateTree(newTreeNode, visited);
            }
        }

        return(father);
    }
Beispiel #5
0
    /// <summary>
    /// Add a child to this tree node. If add fail, return false.
    /// </summary>
    public bool AddChild(PathTreeNode node)
    {
        if (_nodes == null)
        {
            _nodes = new List <PathTreeNode>(2);
        }

        if (_nodes.Count == 0)
        {
            _nodes.Add(node);
            return(true);
        }

        if (_nodes.Contains(node))
        {
            return(false);
        }

        _nodes.Add(node);
        return(true);
    }
Beispiel #6
0
    /// <summary>
    /// Get a tree node from the tree.
    /// </summary>
    /// <returns> return null if there is no such tree node </returns>
    public PathTreeNode FindTreeNode(Node nodeToFind, Node.WalkableAxis axisToFind)
    {
        if (m_head == null)
        {
            return(null);
        }

        Queue <PathTreeNode> queue = new Queue <PathTreeNode>();

        queue.Enqueue(m_head);

        while (queue.Count > 0)
        {
            PathTreeNode treeNode = queue.Dequeue();
            if (treeNode == null)
            {
                continue;
            }

            foreach (var childTreeNode in treeNode.GetChilds())
            {
                if (childTreeNode == null)
                {
                    continue;
                }

                if ((childTreeNode.m_node == nodeToFind) &&
                    (childTreeNode.m_axis == axisToFind))
                {
                    return(childTreeNode);
                }
                else
                {
                    queue.Enqueue(childTreeNode);
                }
            }
        }

        return(null);
    }
Beispiel #7
0
    /// <summary>
    /// Get a path, from head to endNode
    /// </summary>
    public List <Transform> FindPathFromStartToEnd(Node endNode, Node.WalkableAxis endAxis)
    {
        PathTreeNode curTreeNode = FindTreeNode(endNode, endAxis);

        if (curTreeNode == null)
        {
            return(null);
        }

        List <Transform> path = new List <Transform>();

        // Add first node
        path.Add(curTreeNode.m_node.GetTransByAxis(curTreeNode.m_axis));

        // Add other nodes
        while (curTreeNode != m_head)
        {
            Node curNode = curTreeNode.m_node;
            Node.WalkableAxis curAxis = curTreeNode.m_axis;

            Node fatherNode = curTreeNode.m_father.m_node;
            Node.WalkableAxis fatherAxis = curTreeNode.m_father.m_axis;

            Transform curConnect = curNode.FindConnectTrans(fatherNode);
            Transform adjConnect = fatherNode.FindConnectTrans(curNode);

            path.Add(curConnect);
            path.Add(adjConnect);
            path.Add(fatherNode.GetTransByAxis(fatherAxis));

            curTreeNode = curTreeNode.m_father;
        }

        path.Reverse();
        return(path);
    }
Beispiel #8
0
        /// <summary>
        /// Encodes the inner.
        /// </summary>
        /// <param name="rawData">The raw data.</param>
        /// <param name="result">The result.</param>
        /// <param name="options">The options.</param>
        protected override void EncodeInner(Stream rawData, Stream result, Dictionary <PdfName, PdfObjectBase> options)
        {
            StreamNBitWriter writer = new StreamNBitWriter(result, 9);

            writer.Write(0x100);
            if (rawData.Length > 0L)
            {
                int num3;
                int num = 0x102;
                PathTree <byte, int> tree = new PathTree <byte, int>();
                for (int i = 0; i < 0x100; i++)
                {
                    tree.Root[(byte)i] = new PathTreeNode <byte, int>(i);
                }
                PathTreeNode <byte, int> node = tree.Root[(byte)rawData.ReadByte()];
                while ((num3 = rawData.ReadByte()) != -1)
                {
                    byte path = (byte)num3;
                    if (node.ContainsPath(path))
                    {
                        node = node[path];
                    }
                    else
                    {
                        writer.Write(node.Data);
                        node[path] = new PathTreeNode <byte, int>(num++);
                        node       = tree.Root[path];
                    }
                    if (num == 0x1000)
                    {
                        writer.Write(0x100);
                        tree = new PathTree <byte, int>();
                        for (int j = 0; j < 0x100; j++)
                        {
                            tree.Root[(byte)j] = new PathTreeNode <byte, int>(j);
                        }
                        num      = 0x102;
                        writer.N = 9;
                    }
                    else if (num > 0x7ff)
                    {
                        writer.N = 12;
                    }
                    else
                    {
                        if (num > 0x3ff)
                        {
                            writer.N = 11;
                            continue;
                        }
                        if (num > 0x1ff)
                        {
                            writer.N = 10;
                        }
                    }
                }
                writer.Write(tree.GetPath(node));
            }
            writer.Write(0x101);
            writer.Flush();
        }
Beispiel #9
0
 public PathTree()
 {
     m_head = null;
 }
Beispiel #10
0
 public PathTree(PathTreeNode head)
 {
     m_head = head;
 }
        private PathTreeNode GetNode(TreeNodeCollection nodes, string pathComponent)
        {
            foreach (PathTreeNode node in nodes)
            {
                if (String.Compare(node.Text, pathComponent, true) == 0)
                    return node;
            }

            PathTreeNode newNode = new PathTreeNode(pathComponent);
            nodes.Add(newNode);

            // non-leaf nodes default to gray and are disabled
            newNode.Enabled = false;
            newNode.SelectedImageIndex = newNode.ImageIndex = FolderIndex;
            return newNode;
        }