Exemple #1
0
        private void ShowCurListResult(BorderCircleList result)
        {
            BorderMap map = new BorderMap(borderMap.Width - 4, borderMap.Height - 4);

            foreach (BorderPoint bord in result)
            {
                Point p = bord.p;
                map[p.X, p.Y] = true;
            }
            map.ShowDataToConsole();
            Console.WriteLine();
        }
Exemple #2
0
        private void CreateBorderCircles(Texture2D tex)
        {
            LinkedList <BorderPoint> leftBorderNodes = new LinkedList <BorderPoint>();

            for (int y = -1; y <= tex.Height; y++)
            {
                for (int x = -1; x <= tex.Width; x++)
                {
                    BorderPoint cur = new BorderPoint(new Point(x, y));
                    if (NodeIsBorder(cur))
                    {
                        borderMap[x, y] = true;
                        leftBorderNodes.AddLast(cur);
                    }
                }
            }

            while (leftBorderNodes.Count != 0)
            {
                BorderPoint first = leftBorderNodes.First.Value;

                BorderCircleList list = BuildCircle(first);
                if (list.isLinked && list.Length >= minBorderListLength)
                {
                    borderCircles.Add(list);
                }

                // Delete Circles' node from LeftBorderNodes
                foreach (BorderPoint border in list)
                {
                    LinkedListNode <BorderPoint> node = leftBorderNodes.First;
                    for (int i = 0; i < leftBorderNodes.Count - 1; i++)
                    {
                        node = node.Next;
                        if (node.Previous.Value.p == border.p)
                        {
                            leftBorderNodes.Remove(node.Previous);
                        }
                    }
                    if (leftBorderNodes.Last != null && leftBorderNodes.Last.Value.p == border.p)
                    {
                        leftBorderNodes.RemoveLast();
                    }
                }
            }
        }
Exemple #3
0
 private void ShowCurListResult ( BorderCircleList result )
 {
     BorderMap map = new BorderMap( borderMap.Width - 4, borderMap.Height - 4 );
     foreach (BorderPoint bord in result)
     {
         Point p = bord.p;
         map[p.X, p.Y] = true;
     }
     map.ShowDataToConsole();
     Console.WriteLine();
 }
Exemple #4
0
        /// <summary>
        /// 按逆时针方向获得边界圈
        /// </summary>
        /// <param name="first"></param>
        /// <returns></returns>
        private BorderCircleList BuildCircle ( BorderPoint first )
        {
            BorderCircleList result = new BorderCircleList();

            BorderNode firstNode = new BorderNode( first );
            result.AddLast( firstNode );

            Point prePoint = new Point();
            Point curPoint = firstNode.value.p;

            try
            {
                //set the prePoint at the first time!
                SetPrePointFirstTime( firstNode.value.p, ref prePoint );


                bool linked = false;
                while (!linked)
                {
                    bool findNext = false;

                    foreach (Point p in SurroundQueue( curPoint, prePoint ))
                    {
                        if (borderMap[p.X, p.Y] && p != prePoint)
                        {
                            findNext = true;

                            if (p == firstNode.value.p)
                            {
                                linked = true;
                                result.LinkLastAndFirst();
                                break;
                            }

                            result.AddLast( new BorderPoint( p ) );
                            prePoint = curPoint;
                            curPoint = p;
                            break;
                        }
                    }
                    if (!findNext)
                    {
#if SHOWERROR
                        //ShowDataToConsole();
                        //ShowCurListResult( result );
#endif
                        throw new BorderBulidException( curPoint, prePoint, borderMap );
                    }
                }

            }
            // 如果此处出现异常,往往是导入的图片不能满足要求。
            // 将在输出中打印出图片上具体出错的位置。
            // 需要重新修改图片以正常使用。
            catch (BorderBulidException e)
            {
#if SHOWERROR
                //ShowDataToConsole();
                //ShowCurListResult( result );
#endif
                throw e;
                //return result;
            }
            return result;
        }
Exemple #5
0
        /// <summary>
        /// 按逆时针方向获得边界圈
        /// </summary>
        /// <param name="first"></param>
        /// <returns></returns>
        private BorderCircleList BuildCircle(BorderPoint first)
        {
            BorderCircleList result = new BorderCircleList();

            BorderNode firstNode = new BorderNode(first);

            result.AddLast(firstNode);

            Point prePoint = new Point();
            Point curPoint = firstNode.value.p;

            try
            {
                //set the prePoint at the first time!
                SetPrePointFirstTime(firstNode.value.p, ref prePoint);


                bool linked = false;
                while (!linked)
                {
                    bool findNext = false;

                    foreach (Point p in SurroundQueue(curPoint, prePoint))
                    {
                        if (borderMap[p.X, p.Y] && p != prePoint)
                        {
                            findNext = true;

                            if (p == firstNode.value.p)
                            {
                                linked = true;
                                result.LinkLastAndFirst();
                                break;
                            }

                            result.AddLast(new BorderPoint(p));
                            prePoint = curPoint;
                            curPoint = p;
                            break;
                        }
                    }
                    if (!findNext)
                    {
#if SHOWERROR
                        //ShowDataToConsole();
                        //ShowCurListResult( result );
#endif
                        throw new BorderBulidException(curPoint, prePoint, borderMap);
                    }
                }
            }
            // 如果此处出现异常,往往是导入的图片不能满足要求。
            // 将在输出中打印出图片上具体出错的位置。
            // 需要重新修改图片以正常使用。
            catch (BorderBulidException e)
            {
#if SHOWERROR
                //ShowDataToConsole();
                //ShowCurListResult( result );
#endif
                throw e;
                //return result;
            }
            return(result);
        }