是否有良好的数据结构来表示可以放大和缩小的 2D 地图/网格?

发布于 2024-10-26 19:46:23 字数 431 浏览 0 评论 0原文

我用 java 构建了一个 2D 网格,其中每个单元格都可以具有特定的属性,例如颜色。在主循环的每次迭代中,该颜色可能会发生变化。

我想要做的事情:
- 放大时,它将显示网格的一小部分以及每个网格的实际颜色。
- 当您缩小并一次看到更多单元格时,单元格将开始变得太小而无法单独看到,所以我希望能够将该区域(单元格的集合)表示为单一颜色(比如说 。

我想到的一件事是使用分层树/金字塔结构,在叶子上有每个单元格 每个父节点包含其每个子节点的摘要信息。因此,要以高缩放级别绘制地图,我只需要在树中向下移动几个级别,而不是单独查看每个单元格。然而,从叶子到父级以及随后到每个更高级别的更改传播似乎在每个循环迭代的大网格中都需要相当长的时间。

有更好的方法吗?这个问题似乎应该已经由图形/游戏世界中的人们处理过,但我什至在谷歌上找不到正确的关键字,所以任何帮助或指导都是值得赞赏的。谢谢。

I've built a 2D grid in java where each cell can have a certain attribute, say color. At each iteration of the main loop, that color can possibly change.

What I want to be able to do:
- when zoomed in, it will show a small subset of the grids and the actual color of each grid.
- as you zoom out and see more cells at once, the cells will start to get too small to be seen individually, so I want to be able to just represent that area(a collection of cells) as a single color (say the most often occurring one in that collection)

One thing I thought of for doing this would be to use a hierarchical tree/pyramid structure, where at the leaves you have each cell. Each parent node contains summary information of each of its children. So to draw the map at a high zoom level, I'd only need to go down a few levels in the tree instead of looking at each cell individually. However, propagation of changes from leaves to parents and subsequently to each higher level seems like it'd take quite awhile in a large grid for every loop iteration.

Is there a better way to do this? This problem seems like it should have been handled before by people in the graphics/gaming world but I'm having trouble even finding the right keywords to Google, so any help or direction is appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北恋 2024-11-02 19:46:23

我认为你走在正确的道路上。您提出的是 2D 场景图的典型实现并确定父节点的边界。

请记住,即使叶节点可能会更改颜色,但由于之前的状态,更改可能不会一直向上传播。您需要确保做的是跟踪脏叶子,这样您就不会在不必要时对所有内容进行更新。

我认为你应该实施你的建议,然后看看性能是否真的是一个问题。你的网格中有多少个单元格?

I think you're on the right track. What you propose is a typical implementation of a 2D scene graph and determining bounds of parent nodes.

Keep in mind that even though leaf nodes might change colors, the change may not be propogated all the way up due to previous state. What you need to be sure to do is track dirty leaves so you don't do the update for everything when its not necessary.

I think you should implement what you propose and then see if performance is really an issue. How many cells are in your grid?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文