Example #1
0
        private KdTree.ObstacleTreeNode Assign2Kdtree(KdtreeObstacleTreeNode treenode, Dictionary <int, KdtreeObstacle> dic, Dictionary <int, KdtreeObstacleTreeNode> treedic, Dictionary <int, Obstacle> obsdic)
        {
            if (treenode == null || treenode.id == -1)
            {
                return(null);
            }

            KdTree.ObstacleTreeNode kdnode = new KdTree.ObstacleTreeNode();
            kdnode.obstacle_ = CreateObstacle(dic[treenode.obstacleID], dic, obsdic);

            KdTree.ObstacleTreeNode left  = Assign2Kdtree(treenode.leftID != -1 ? treedic[treenode.leftID]:null, dic, treedic, obsdic);
            KdTree.ObstacleTreeNode right = Assign2Kdtree(treenode.rightID != -1 ?treedic[treenode.rightID]:null, dic, treedic, obsdic);

            /*ScriptCommand setleft_cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.SET_LEFT_LEAF);
             * ScriptCommand setright_cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.SET_RIGHT_LEAF);
             * setleft_cmd.CallParams.WriteObject(kdnode);
             * setleft_cmd.CallParams.WriteObject(left);
             * setleft_cmd.ExcuteAndRelease();
             *
             * setright_cmd.CallParams.WriteObject(kdnode);
             * setright_cmd.CallParams.WriteObject(right);
             * setright_cmd.ExcuteAndRelease();*/

            return(kdnode);
        }
Example #2
0
        public KdTree CopythisToKdtree(IList <Obstacle> target)
        {
            KdTree tree = new KdTree();

            Dictionary <int, KdtreeObstacle> dic = new Dictionary <int, KdtreeObstacle>();

            for (int i = 0; i < obstacles.Count; ++i)
            {
                dic[obstacles[i].id_] = obstacles[i];
            }

            Dictionary <int, KdtreeObstacleTreeNode> treedic = new Dictionary <int, KdtreeObstacleTreeNode>();

            for (int i = 0; i < treenodes.Count; ++i)
            {
                treedic[treenodes[i].id] = treenodes[i];
            }

            Dictionary <int, Obstacle> obsdic = new Dictionary <int, Obstacle>();

            KdTree.ObstacleTreeNode treenode = Assign2Kdtree(treedic[0], dic, treedic, obsdic);

            /*ScriptCommand setnode_cmd = ScriptCommand.Create((int)FrameWorkCmdDefine.SET_KDTREE_TREENODE);
             * setnode_cmd.CallParams.WriteObject(tree);
             * setnode_cmd.CallParams.WriteObject(treenode);
             * setnode_cmd.ExcuteAndRelease();*/

            //assign obstacles
            target.Clear();
            var en = obsdic.GetEnumerator();

            while (en.MoveNext())
            {
                target.Add(en.Current.Value);
            }

            return(tree);
        }
Example #3
0
        private KdtreeObstacleTreeNode AssignTreeNode(KdTree.ObstacleTreeNode kdnode, Dictionary <int, KdtreeObstacle> obslist)
        {
            if (kdnode == null || kdnode.obstacle_ == null)
            {
                return(null);
            }
            KdtreeObstacleTreeNode treenode = new KdtreeObstacleTreeNode();

            treenode.id = this.treenodes.Count;
            treenodes.Add(treenode);

            treenode.obstacle_  = obslist[kdnode.obstacle_.id_];
            treenode.obstacleID = treenode.obstacle_.id_;

            treenode.left_  = AssignTreeNode(kdnode.left_, obslist);
            treenode.right_ = AssignTreeNode(kdnode.right_, obslist);

            if (treenode.left_ != null)
            {
                treenode.leftID = treenode.left_.id;
            }
            else
            {
                treenode.leftID = -1;
            }

            if (treenode.right_ != null)
            {
                treenode.rightID = treenode.right_.id;
            }
            else
            {
                treenode.rightID = -1;
            }
            return(treenode);
        }