<legend id='rxPIX'><style id='rxPIX'><dir id='rxPIX'><q id='rxPIX'></q></dir></style></legend>
<i id='rxPIX'><tr id='rxPIX'><dt id='rxPIX'><q id='rxPIX'><span id='rxPIX'><b id='rxPIX'><form id='rxPIX'><ins id='rxPIX'></ins><ul id='rxPIX'></ul><sub id='rxPIX'></sub></form><legend id='rxPIX'></legend><bdo id='rxPIX'><pre id='rxPIX'><center id='rxPIX'></center></pre></bdo></b><th id='rxPIX'></th></span></q></dt></tr></i><div id='rxPIX'><tfoot id='rxPIX'></tfoot><dl id='rxPIX'><fieldset id='rxPIX'></fieldset></dl></div>
  • <tfoot id='rxPIX'></tfoot>

    • <bdo id='rxPIX'></bdo><ul id='rxPIX'></ul>

        <small id='rxPIX'></small><noframes id='rxPIX'>

      1. 网格中的 JAVA 孔

        时间:2024-08-24
          <tbody id='9rTFz'></tbody>

        <small id='9rTFz'></small><noframes id='9rTFz'>

          <legend id='9rTFz'><style id='9rTFz'><dir id='9rTFz'><q id='9rTFz'></q></dir></style></legend>
          • <i id='9rTFz'><tr id='9rTFz'><dt id='9rTFz'><q id='9rTFz'><span id='9rTFz'><b id='9rTFz'><form id='9rTFz'><ins id='9rTFz'></ins><ul id='9rTFz'></ul><sub id='9rTFz'></sub></form><legend id='9rTFz'></legend><bdo id='9rTFz'><pre id='9rTFz'><center id='9rTFz'></center></pre></bdo></b><th id='9rTFz'></th></span></q></dt></tr></i><div id='9rTFz'><tfoot id='9rTFz'></tfoot><dl id='9rTFz'><fieldset id='9rTFz'></fieldset></dl></div>
                <tfoot id='9rTFz'></tfoot>

                  <bdo id='9rTFz'></bdo><ul id='9rTFz'></ul>
                  本文介绍了网格中的 JAVA 孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要在 Java 中的 2D 网格中找到洞" - 你能告诉我最好的算法吗?

                  I need to find "holes" in a 2D grid in java - can you point me toward the best sort of algorithm to do this?

                  输入以下几点:

                  5,3
                  5,4
                  8,4
                  5,5
                  6,3
                  7,3
                  7,4
                  6,5
                  

                  我需要找出这个网格中洞"或包围空间的位置.我对如何做到这一点有点迷茫.

                  I need to figure out the positions of the "hole" or surrounded space in this grid. I'm a bit lost as to how to do this.

                  点的情节:

                  假设每个点是 1x1

                  推荐答案

                  这基本上是一个blob提取算法+一点额外的.这样做:

                  This is basically a blob extraction algorithm + a bit extra. Do this:

                  1) 找到放置任何实体的最西、最东、最北和最南.记住它们为 xmin xmax ymin ymax.

                  1) Find the westmost, eastmost, northmost and southmost any solid is placed. Remember them as xmin xmax ymin ymax.

                  2) 分配具有这些维度的二维整数数组(初始化为 0),并将所有实心点作为值 -1 放入其中.

                  2) Allocate an 2d array of integers (initialized to 0) with those dimensions, and place all solid points in it as the value -1.

                  3) 将计数器初始化为 1.扫描二维数组.每次找到一个为 0 的点时,将其设置为 counter 并将 counters 填充到每个不是 -1 的相邻点上,直到用完点为止洪水填充到.(要进行填充,一种方法是保留一组尚未填充所有邻居的所有点,然后迭代这些点,将新点添加到集合中,直到集合用完 -> 没有任何东西可以填充到.) 现在增加计数器并继续.

                  3) Make a counter initialized to 1. Scan the 2d array. Every time you find a point that is 0, set it to counter and floodfill counters onto every adjacent point that is not a -1 until you've run out of points to floodfill onto. (To do a floodfill, one way is to keep a set of all points you haven't floodfilled all the neighbours of yet, and iterate over these, adding new points to the set until the set is exhausted -> nothing left to floodfill onto.) Now increment the counter and continue.

                  4) 扫描整个网格后,扫描周边.每次您在外围看到非 -1 时,将该 blob 标记为没有被包围(通过与您找到的 blob 数量一样长的 bool 数组).

                  4) When you've scanned the whole grid, scan the perimeter. Every time you see a non -1 on the perimeter, mark that blob as not being surrounded (by having an array of bools as long as the number of blobs you found).

                  5) 您未标记的每个编号的 blob 都会被包围.

                  5) Every numbered blob you have not marked is surrounded.

                  在此处了解 blob 提取:http://en.wikipedia.org/wiki/Blob_extraction

                  Read about blob extraction here: http://en.wikipedia.org/wiki/Blob_extraction

                  这篇关于网格中的 JAVA 孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:GXt 2.2.3 中 EditorGrid 的列标题下的行未正确对齐 下一篇:javafx 制作一个按钮网格

                  相关文章

                  <small id='e8jH7'></small><noframes id='e8jH7'>

                    <bdo id='e8jH7'></bdo><ul id='e8jH7'></ul>

                    1. <legend id='e8jH7'><style id='e8jH7'><dir id='e8jH7'><q id='e8jH7'></q></dir></style></legend>
                      <tfoot id='e8jH7'></tfoot>
                      <i id='e8jH7'><tr id='e8jH7'><dt id='e8jH7'><q id='e8jH7'><span id='e8jH7'><b id='e8jH7'><form id='e8jH7'><ins id='e8jH7'></ins><ul id='e8jH7'></ul><sub id='e8jH7'></sub></form><legend id='e8jH7'></legend><bdo id='e8jH7'><pre id='e8jH7'><center id='e8jH7'></center></pre></bdo></b><th id='e8jH7'></th></span></q></dt></tr></i><div id='e8jH7'><tfoot id='e8jH7'></tfoot><dl id='e8jH7'><fieldset id='e8jH7'></fieldset></dl></div>