简体   繁体   English

在高度图阵列中查找边缘和顶点

[英]Finding Edges and Vertices Within Heightmap Array

Lets say I have generated a heightmap array, which for simplicity's sake will only have three height values within it: 0 , 1 , and 2 . 可以说,我已经产生了高度图阵列,其中为了简单起见,将只具有在其内3个高度值: 01 ,和2 For example, it may look like this: 例如,它可能看起来像这样:

000000111111110000000000000000000000000000000000
001111111111111111000000000001111111111111000000
000011111111111111100000000000000011122111110000
000000000111111100000000000000000111221110000000
000000000000000000000000000001111122222111111100
000000000000000000000000111111111111111111000000
000000000000000000000111111111100000000000001111
000000000001111111111110000000000000000001111111
000000001111222222211100000000000000000000001110
000000000011112221100000000000000011111000000000
000000000000111111100000000000001111111110000000
000000001111111110000000000000000011111000000000
000000000000000000000000000000000000000000000000

What I'm trying to do is find the 'vertices' in this heightmap, and to output them in a logical order (so I can draw a line going to each consecutive point that will eventually trace the outline of the shape). 我想做的是在此高度图中找到“顶点”,并以逻辑顺序输出它们(因此我可以画一条线到达每个连续点,最终将跟踪形状的轮廓)。 For example, for the first 'group' of 1 s in the top right corner: 例如,对于第一“的组” 1 S IN右上角:

000000111111110000000           .1------2       
001111111111111111000        8-'         `--3   
000011111111111111100  -->    `7---.        .4  
000000000111111100000               6-----5'    
000000000000000000000                           

The numbers in the second diagram are the coordinates I need to find (in the correct order), and the dots and dashes are the lines I would trace from each point to get the outline of the shape. 第二张图中的数字是我需要查找的坐标(以正确的顺序),点和破折号是我从每个点开始跟踪以获取形状轮廓的线。

Is there any sort of algorithm I can use to find these vertices? 我可以使用某种算法来找到这些顶点吗? If not, what is the most efficient method of finding them? 如果没有,找到它们的最有效方法是什么?

What I am currently doing is using recursion to find each of the 'islands' or 'groups' of numbers, and then taking all the outer points of this shape as the vertices. 我目前正在做的事情是使用递归来找到数字的每个“岛”或“组”,然后以该形状的所有外点为顶点。 However, my method is quite slow and the vertices are not in the correct order. 但是,我的方法相当慢,并且顶点的顺序不正确。

Thank you for your help and I hope this all makes sense. 感谢您的帮助,我希望这一切都有意义。

Edit: I realize from the comments that using vertices would make me lose some areas of the shape. 编辑:我从评论中意识到,使用顶点会使我失去某些形状的区域。 I think that instead of vertices then what I need to find is all the points on the edge of the shape, but in the correct order. 我认为,除了顶点以外,我需要找到的是形状边缘上的所有点,但顺序正确。 So my example should be: 所以我的例子应该是:

000000111111110000000             12345678       
001111111111111111000         17          9,10   
000011111111111111100  -->     16,15         11  
000000000111111100000               14,13,12     
000000000000000000000                            

Sorry for the confusion. 对困惑感到抱歉。

(Answer to the edited question:) A certain form of graph traversal should do for this, I will only give a very high-level description of it. (针对已编辑的问题的答案:)为此需要某种形式的图形遍历,我将仅对其进行非常高级的描述。 Start at the highest level of the height map, and for any island, start at some interior point. 从高度图的最高层开始,对于任何岛屿,都从某个内部点开始。 Go north until you reach the edge of the island or the edge of the map. 向北走,直到到达岛屿的边缘或地图的边缘。 In a clockwise (or counter-clockwise, whichever it is you need) fashion, explore only those cells that can belong to the edge of the island. 以顺时针(或逆时针,无论您需要的是哪种方式)的方式,仅探索那些可能属于该岛边缘的单元。

For lower levels, start from cells neighboring the higher-level islands and do the same. 对于较低的级别,请从与较高级别的岛相邻的单元开始,然后执行相同的操作。


(Answer to question before clarifying edit:) Sounds to me like you want the convex hull of every "island". (在澄清编辑之前要提问题:)听起来像我想要每个“岛”的凸包 Find contiguous groups (your "islands") with graph traversal (I like BFS best, but tastes differ; consider two cell to belong to the same island whenever they contain the same value and are adjacent), then apply some convex hull algorithm . 通过图遍历找到连续的组(您的“岛”)(我最喜欢BFS ,但是口味不同;只要两个单元包含相同的值并且相邻,则将两个单元都视为属于同一岛),然后应用一些凸包算法

You can try alpha shapes. 您可以尝试使用Alpha形状。 Alpha shapes is defined as a delaunay triangulation without edges exceeding alpha. Alpha形状定义为不超过Alpha的边的Delaunay三角剖分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM