• 大小: 22KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-07-20
  • 语言: C#
  • 标签: 连通域  

资源简介

VS2005下编写的,在Two-Pass算法上做了一些修改,运行后可看到算法流程...............

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace CheckConnection
{
    class Program
    {
        static int width = 10;
        static int height = 10;

        static void Main(string[] args)
        {
            int[] data = OutData();
            CalConnections(data);
        }

        static void CalConnections(int[] data)
        {
            //一种标记的点的个数
            Dictionary> dic_label_p = new Dictionary>();
            //标记
            int label = 1;
            for (int y = 0; y < data.GetLength(0); y++)
            {
                for (int x = 0; x < data.GetLength(1); x++)
                {
                    //如果该数据不为0
                    if (data[y x] != 0)
                    {
                        List ContainsLabel = new List();
                        #region 第一行
                        if (y == 0)//第一行只看左边
                        {
                            //第一行第一列,如果不为0,那么填入标记
                            if (x == 0)
                            {
                                data[y x] = label;
                                label++;
                            }
                            //第一行,非第一列
                            else
                            {
                                //如果该列的左侧数据不为0,那么该数据标记填充为左侧的标记
                                if (data[y x - 1] != 0)
                                {
                                    data[y x] = data[y x - 1];
                                }
                                //否则,填充自增标记
                                else
                                {
                                    data[y x] = label;
                                    label++;
                                }
                            }
                        }
                        #endregion
                        #region 非第一行
                        else
                        {
                            if (x == 0)//最左边  --->不可能出现衔接情况
                            {
                                /*分析上和右上*/
                                //如果上方数据不为0,则该数据填充上方数据的标记
                                if (data[y - 1 x] != 0)
                                {
                                    data[y x] = data[y - 1 x];
                                }
                                //上方数据为0,右上方数据不为0,则该数据填充右上方数据的标记
                                else if (data[y - 1 x + 1] != 0)
                                {
                                    data[y x] = data[y - 1 x + 1];
                                }
                                //都为0,则填充自增标记
                                else
                                {
                                    data[y x] = label;
                                    label++;
                                }
               

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      20480  2016-03-31 10:16  CheckConnection\CheckConnection\bin\Debug\CheckConnection.exe

     文件      19968  2016-03-31 10:16  CheckConnection\CheckConnection\bin\Debug\CheckConnection.pdb

     文件       5632  2005-11-11 22:25  CheckConnection\CheckConnection\bin\Debug\CheckConnection.vshost.exe

     文件       1964  2016-03-31 09:27  CheckConnection\CheckConnection\CheckConnection.csproj

     文件        631  2016-03-31 13:10  CheckConnection\CheckConnection\obj\CheckConnection.csproj.FileListAbsolute.txt

     文件      20480  2016-03-31 10:16  CheckConnection\CheckConnection\obj\Debug\CheckConnection.exe

     文件      19968  2016-03-31 10:16  CheckConnection\CheckConnection\obj\Debug\CheckConnection.pdb

     文件      12100  2016-03-31 13:11  CheckConnection\CheckConnection\Program.cs

     文件       1195  2016-03-31 09:27  CheckConnection\CheckConnection\Properties\AssemblyInfo.cs

     文件        934  2016-03-31 09:27  CheckConnection\CheckConnection.sln

    ..A..H.     11264  2016-03-31 13:11  CheckConnection\CheckConnection.suo

     目录          0  2016-03-31 09:46  CheckConnection\CheckConnection\obj\Debug\Refactor

     目录          0  2016-03-31 09:27  CheckConnection\CheckConnection\obj\Debug\TempPE

     目录          0  2016-03-31 09:29  CheckConnection\CheckConnection\bin\Debug

     目录          0  2016-03-31 10:16  CheckConnection\CheckConnection\obj\Debug

     目录          0  2016-03-31 09:27  CheckConnection\CheckConnection\bin

     目录          0  2016-03-31 09:28  CheckConnection\CheckConnection\obj

     目录          0  2016-03-31 09:27  CheckConnection\CheckConnection\Properties

     目录          0  2016-03-31 13:11  CheckConnection\CheckConnection

     目录          0  2016-03-31 09:27  CheckConnection

----------- ---------  ---------- -----  ----

               114616                    20


评论

共有 条评论

相关资源