Create Quadtree

I am trying to use quadtree (4-dimensional tree) to store information in this BMP.
I'm struggling to figure out how to build a tree, given any BMP.

In principle, the structure is such that each sheet is a pixel. Each Node has 4 pointers, each of which points to one of the four remaining quadrants of the image. Thus, each Node divides the current image into 4 parts. By the time you are on the sheet, you are in one specific pixel.

I'm not sure how to go about creating a tree to display a specific image. Assuming the image has dimensions equal to two, what should I do. I understand that a recursive function could probably do it most elegantly, but I'm struggling to figure out how to track where in the image I will be.

This is in C ++, and currently my quadtree.h file contains the root Node *, where Node is defined as a structure with a pixel element and 4 pointers to other nodes. Each internal Node (non leaf node) should contain the average of all 4 RGB values ​​to which it leads.

I'm trying to make an algorithm, but I think I might need to include a structure or two in the .h file. Is there a better / cleaner way to solve this problem?

+3
source share
2 answers

Well, depending on how you store your data in Bitmap, you can do things differently. Do you read it from a file and drop it directly into your tree? If so, the .BMP files (if I remember correctly) will tell you about their width and height right at the top, so you can use this to determine exactly how many levels you have, which can help you build something.

, , , " " , . , , , , . , , , , , , .

, , , , node x, y. , , .

? ? ?

+2

Source: https://habr.com/ru/post/1738400/


All Articles