简体   繁体   English

QuadTree如何适用于非正方形区域?

[英]How does a QuadTree work for non-square areas?

I understand how quad trees work on square images (by splitting the image until the section is a single colour, which is stored in the leaf node). 我理解四边形树如何在方形图像上工作(通过分割图像直到该部分是单个颜色,存储在叶节点中)。

What happens if the image has one dimension longer that the other, you may end up with a 2x1 pixel area as the smallest sub unit, making it difficult to use quadtree division methods to store a single colour. 如果图像的一维长度超过另一维,会发生什么情况,最终可能会将2x1像素区域作为最小的子单元,这使得难以使用四叉树分割方法来存储单一颜色。 How would you solve this issue? 你会如何解决这个问题?

You could pad the image until it is an equal and power of two size. 你可以填充图像,直到它是一个相等和两个大小的力量。 While it may add some extra memory requirements, the increase shouldn't be that large. 虽然它可能会增加一些额外的内存需求,但增长量不应该那么大。

The 2x1 example would be padded to a standard 2x2 and store the real size or use a special value for padded nodes so you can restore the original size. 2x1示例将填充到标准2x2并存储实际大小或为填充节点使用特殊值,以便您可以恢复原始大小。

I know this is an old question, but I hope I helped anyway. 我知道这是一个老问题,但我希望无论如何我都会帮忙。

A square is a special rectangle, Quad trees work on rectangles, too. 正方形是一个特殊的矩形,四边形树也可以在矩形上工作。 You just need a split method which gives 4 rectangles for a given one. 你只需要一个分割方法,给出一个给定的4个矩形。

In case the top most root quad cell is an rectangle, just divide the width and height by 2. 如果最顶部的根四边形单元格是矩形,则只需将宽度和高度除以2即可。

In case of pixels, it makes only sense if the root cell widthand height are both a power of 2. 在像素的情况下,只有根单元格widthand和高度都是2的幂才有意义。

So if root cell = 2048 * 1024 The split just divides both width and height by 2. 因此,如果根单元格= 2048 * 1024,则拆分只会将宽度和高度除以2。

Why don't you allow empty leafes in your tree? 你为什么不在树上留下空叶? Edit: Maybe i don't understand the question^^. 编辑:也许我不明白这个问题^^。 Your problem is that you end up with a non square images like 2x1 and want to represent them as a quadtreenode? 你的问题是你最终得到像2x1这样的非方形图像,并希望将它们表示为四边形图?

When you have a 2x2 square like 如果您有2x2的正方形

1 2 1 2
3 4 3 4

you would create a Quadnode with something like "new QuadNode(1,2,3,4)" 你会用“new QuadNode(1,2,3,4)”创建一个Quadnode

I would suggest to handel a 2x1 square like 我建议汉德尔像2x1一样

1 2 1 2

with something like "new QuadNode(1,2,null,null)" When you have bigger missing pieces you can use the same system. 使用类似“new QuadNode(1,2,null,null)”的东西当你有更大的缺失部分时,你可以使用相同的系统。 When you have a 4x2 picture like 当你有像这样的4x2图片时

1 2 3 4 1 2 3 4
5 6 7 8 5 6 7 8

you would get a "new QuadNode(new QuadNode(1,2,3,4),null,new QuadNode(5,6,7,8),null)" 你会得到一个“新的QuadNode(新的QuadNode(1,2,3,4),null,新的QuadNode(5,6,7,8),null)”

This should also work with pieces with equal color instead of pixels. 这也适用于颜色相同而不是像素的碎片。

Did i understand your problem and made myself clear? 我了解你的问题并让自己明白了吗?

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

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