当前位置: 首页>>代码示例>>C#>>正文


C# TreeNode.AddParent方法代码示例

本文整理汇总了C#中TreeNode.AddParent方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.AddParent方法的具体用法?C# TreeNode.AddParent怎么用?C# TreeNode.AddParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeNode的用法示例。


在下文中一共展示了TreeNode.AddParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: JoinTree

        //===================================================================//
        //                          Constructors                             //
        //===================================================================//
        /// <summary>
        /// Create a new JoinTree.
        /// </summary>
        /// <param name="maxValue">the maximum value of a node in the tree</param>
        /// <param name="minValue">the minimum value of a node in the tree</param>
        /// <param name="points">the grid points from which to construct the tree</param>
        public JoinTree(float maxValue, float minValue, List<GridPoint> points)
            : base(maxValue, minValue)
        {
            // create a list to store all the blobs in
            List<BlobOfNodes> blobList = new List<BlobOfNodes>();

            // Turn each point into a tree node.
            foreach (GridPoint point in points)
            {
                // Turn the next point into a node.
                TreeNode newNode = new TreeNode(point);

                // Make a list of all the blobs to which the node is adjacent.
                List<BlobOfNodes> adjacentBlobs = new List<BlobOfNodes>();
                // Check each blob in the list.
                foreach (BlobOfNodes blob in blobList) {
                    // If it is adjacent...
                    if (blob.IsAdjacentTo(newNode)) {
                        // ...add it to the list of adjacent blobs.
                        adjacentBlobs.Add(blob); } }

                // If the node is not adjacent to any blobs,
                // create a new blob for it.
                if (adjacentBlobs.Count == 0) {
                    BlobOfNodes newBlob = new BlobOfNodes(newNode);
                    blobList.Add(newBlob);
                    this.parentless.Add(newNode); }

                // If the node is adjacent to exactly one blob,
                // add it to that blob.
                else if (adjacentBlobs.Count == 1) {
                    adjacentBlobs[0].GetMostRecentlyAddedNode().AddChild(newNode);
                    newNode.AddParent(adjacentBlobs[0].GetMostRecentlyAddedNode());
                    adjacentBlobs[0].Add(newNode); }

                // If the node is adjacent to more than one blob,
                // merge the blobs.
                else {
                    foreach (BlobOfNodes blob in adjacentBlobs) {
                        blob.GetMostRecentlyAddedNode().AddChild(newNode);
                        newNode.AddParent(blob.GetMostRecentlyAddedNode());
                        blobList.Remove(blob); }
                    this.merging.Add(newNode);
                    blobList.Add(new BlobOfNodes(newNode, adjacentBlobs)); }
            } // end of adding all the gridpoints

            // At this point, there will be exactly one blob. Its most recently
            // added node is the bottom of the join tree.
            this.childless.Add(blobList[0].GetMostRecentlyAddedNode());
        }
开发者ID:julia-ford,项目名称:Contour-Tree-App,代码行数:59,代码来源:JoinTree.cs

示例2: Clone

        //===================================================================//
        //                             Actions                               //
        //===================================================================//
        /// <summary>
        /// Clones all of the nodes in the tree and duplicates their connections.
        /// </summary>
        /// <param name="parentless">the list in which to store the parentless nodes of the new tree</param>
        /// <param name="merging">the list in which to store the merging nodes of the new tree</param>
        /// <param name="childless">the list in which to store the childless nodes of the new tree</param>
        public void Clone(List<TreeNode> parentless, List<TreeNode> merging, List<TreeNode> childless)
        {
            TreeNode newTreeRoot = new TreeNode(this.GetParentless()[0]);
            parentless.Add(newTreeRoot);

            List<TreeNode> currentLevel = new List<TreeNode>();
            currentLevel.Add(this.GetParentless()[0]);
            List<TreeNode> currentCloneLevel = new List<TreeNode>();
            currentCloneLevel.Add(newTreeRoot);

            while (currentLevel.Count > 0)
            {
                List<TreeNode> nextLevel = new List<TreeNode>();
                List<TreeNode> nextCloneLevel = new List<TreeNode>();

                for (int id = 0; id < currentLevel.Count; id++)
                {
                    foreach (TreeNode child in currentLevel[id].GetChildren())
                    {
                        TreeNode newNode = new TreeNode(child);
                        newNode.AddParent(currentCloneLevel[id]);
                        currentCloneLevel[id].AddChild(newNode);

                        nextLevel.Add(child);
                        nextCloneLevel.Add(newNode);

                        if (this.merging.Contains(child)) {
                            merging.Add(newNode); }
                        if (this.childless.Contains(child)) {
                            childless.Add(newNode); }
                    }
                }
                currentLevel = nextLevel;
                currentCloneLevel = nextCloneLevel;
            }
        }
开发者ID:julia-ford,项目名称:Contour-Tree-App,代码行数:45,代码来源:SplitTree.cs


注:本文中的TreeNode.AddParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。