r-tree how to calculate minimum bounding rectangles of non leaf nodes - bounding-box

I have many building footprints and want to store them in a r-tree structure.I want to understand that in a r-tree structure leaf nodes are minimum bounding rectangles (MBR) of real objects, in my case building footprints. But I could not understand how MBRs of non leaf nodes can be calculated and I want to know how can it be done (In the picture Green boxes). I suppose there are many possible solution but I just want to know only one of them.

The bounding boxes of inner nodes are computed exactly the same way as for leaf nodes.
You need the minimum and maximum in each axis.

The MBR of a non-leaf node is the union of its children nodes (can be leaf or non-leaf nodes) so that it is the bounding box of offspring data.
Take the two-dimensional example in your picture, suppose the children nodes A(X_amin, X_amax, Y_amin, Y_amax) and B(X_bmin, X_bmax, Y_bmin, Y_bmax), the non-leaf parent node is N(min(X_amin, X_bmin), max(X_amax, X_bmax), min(Y_amin, Y_bmin), max(Y_amax, Y_bmax)).

Related

Is there a known algorithm to find groups of adjacent pixels with similar color?

I'd like to know if this is a known algorithm with a name.
I've never done any image processing, but I'm picturing an image as a 2-d matrix of 3-d vectors (ignore transparency).
The only input parameter is distance. Every pixel is tested against its neighbors. If they are closer than the parameter, they join a group and their values are averaged. As groups grow by gaining new pixels all pixels get the average value of the group.
For your typical selfie the result might resemble quantizing or posterizing, but unlike quantizing or posterizing, there is no fixed count of output colors. If absolutely no pixels are close enough to their neighbors, the result is a 1:1 mapping of every pixel to its own group.
Is there a name for this?

How can I calculate center of mass after floodfill?

I have an image like this one
with 3 distinct regions. Using a breath first 4 neighbor queue, I have implemented a basic flood fill that distinguishes between the 3.
Now I need to find the center of mass of these regions with each pixel weighing one unit of weight.
Whats the best way of going about that?
The simplest way is to keep three arrays, sumx, sumy and count, each with one entry per label (3 in your case), and all initialized to 0. Then run through the image once, and for each labeled pixel add the x coordinate to the corresponding bin in sumx, the y coordinate to the corresponding bin in sumy, and 1 to the corresponding bin in count.
At the end, for each label l you can compute sumx[l]/count[l] and sumy[l]/count[l]. These are the unweighted centers of gravity (centroids).

Minimum cost to connect components of a disconnected graph?

We are initially given a fully connected graph by means of an adjacency matrix. Then, some edges are removed such that the graph becomes disconnected and we now have multiple components of this disconnected graph. What is the minimum cost needed to connect all the components?
Let G = (V, E_1 ∪ E_2) be the original (weighted, fully connected) graph and G' = (V, E_1) the graph obtained by removing the edges in the set E_2.
Consider the graph G'' that is obtained by contracting the connected components of G' (i.e., each connected component becomes a single vertex), where two vertices of G'' are neighbours if and only if the corresponding connected components in G' were connected by an edge in E_2. Essentially, this means that the edges of G'' are the edges in the set E_2 (the edges that were removed from the original graph).
Observe that adding a subset of the edges from E_2 to G' restores (full) connectivity of G' if and only if these edges connect all vertices from G''. The cheapest way to do this is by selecting a min-cost spanning tree on G'' (with respect to the weights of the edges). From your comments, I assume you know what a minimum spanning tree is and how it can be computed.
One-sentence-summary:
A cost-minimal set of edges that is needed to restore connectivity can be found by computing a minimum (cost) spanning tree on the graph that is obtained by contracting each of the connected components into a single vertex and that contains, as its edge set, the edges that were removed from the original graph.

Calculating the neighborhood distance

What method would you use to compute a distance that represents the number of "jumps" one has to do to go from one area to another area in a given 2D map?
Let's take the following map for instance:
(source: free.fr)
The end result of the computation would be a triangle like this:
A B C D E F
A
B 1
C 2 1
D 2 1 1
E . . . .
F 3 2 2 1 .
Which means that going from A to D, it takes 2 jumps.
However, to go from anywhere to E, it's impossible because the "gap" is too big, and so the value is "infinite", represented here as a dot for simplification.
As you can see on the example, the polygons may share points, but most often they are simply close together and so a maximum gap should be allowed to consider two polygons to be adjacent.
This, obviously, is a simplified example, but in the real case I'm faced with about 60000 polygons and am only interested by jump values up to 4.
As input data, I have the polygon vertices as an array of coordinates, from which I already know how to calculate the centroid.
My initial approach would be to "paint" the polygons on a white background canvas, each with their own color and then walk the line between two candidate polygons centroid. Counting the colors I encounter could give me the number of jumps.
However, this is not really reliable as it does not take into account concave arrangements where one has to walk around the "notch" to go from one polygon to the other as can be seen when going from A to F.
I have tried looking for reference material on this subject but could not find any because I have a hard time figuring what the proper terms are for describing this kind of problem.
My target language is Delphi XE2, but any example would be most welcome.
You can create inflated polygon with small offset for every initial polygon, then check for intersection with neighbouring (inflated) polygons. Offseting is useful to compensate small gaps between polygons.
Both inflating and intersection problems might be solved with Clipper library.
Solution of the potential neighbours problem depends on real conditions - for example, simple method - divide plane to square cells, and check for neighbours that have vertices in the same cell and in the nearest cells.
Every pair of intersecting polygons gives an edge in (unweighted, undirected) graph. You want to find all the path with length <=4 - just execute depth-limited BFS from every vertice (polygon) - assuming that graph is sparse
You can try a single link clustering or some voronoi diagrams. You can also brute-force or try Density-based spatial clustering of applications with noise (DBSCAN) or K-means clustering.
I would try that:
1) Do a Delaunay triangulation of all the points of all polygons
2) Remove from Delaunay graph all triangles that have their 3 points in the same polygon
Two polygons are neightbor by point if at least one triangle have at least one points in both polygons (or obviously if polygons have a common point)
Two polygons are neightbor by side if each polygon have at least two adjacents points in the same quad = two adjacent triangles (or obviously two common and adjacent points)
Once the gaps are filled with new polygons (triangles eventually combined) use Djikistra Algorithm ponderated with distance from nearest points (or polygons centroid) to compute the pathes.

How to draw a presentable tree using CFTree?

I have to draw a presentable tree using CFTree. You can see in picture
The should satisfy all principles stated in this link.
The principle are :
Principle 1: The edges of the tree should not cross each other.
Principle 2: All nodes at the same depth should be drawn on the same horizontal line. This helps make clear the structure of the tree.
Principle 3: Trees should be drawn as narrowly as possible.
Principle 4: A parent should be centered over its children.
Principle 5: A subtree should be drawn the same no matter where in the tree it lies.
Principle 6: The child nodes of a parent node should be evenly spaced.
How should I calculate X,Y position of each nodes?
You can solve this problem recursively.
Without diagrams (which would help a lot!) here goes an outline - you need to fill in the details! - of one algorithm for this. The algorithm is being typed directly into the answer - expect errors.
First:
Bounding box a rectangle enclosing the drawing of a (sub)tree.
Anchor as the point that connecting arcs will draw towards (part of the arc may be obscured by the drawing of nodes) to connect to the (sub)tree.
The anchor will be the coordinate origin of the bounding box - so bounding boxes are measurements relative to this point.
A bounding box may have children - bounding boxes for subtrees. The location of each child is relative to the boxes anchor.
Now:
Consider first drawing a single node with no children. Based on your desired size you can determine a bounding box for this single node. You are using circles so the anchor, the (0,0) coordinate origin of the bounding box is at the centre and the bounding box is +/- the radius relative to that. So you have the bounding box's anchor, (0,0), and its size relative to that - say (x minimum, x maximum, y minimum, y maximum) being (-radius, +radius, -radius, +radius). You will probably also wish to store the node's label. So for example for the "L" node in your diagram in total you have a representation (i.e. and object) containing: (0,0), (-radius, +radius, -radius, +radius) & "L".
Now consider drawing a node with a single child. By a recursive call determine the bounding box for the child. Construct a bounding box to enclose the child with your node at the top centre of this box and the child bounding box directly below it. So you have the bounding box's anchor, it's size relative to that, and a single child at an offset from the anchor. So for example for the "H" node above you have: (0,0), (xmin, xmax, ymin, ymax), "H", 1 child at (xoffset, yoffset), child is (a reference to the object) (0,0), (-radius, +radius, -radius, +radius) & "L".
Now consider drawing a node with 2 children, etc.
A single recursive traversal from the root of your tree, at each node combining the information returned from subtrees, produces a structure describing the layout of your tree. Now draw it!
HTH
I realize this is an old thread, but for anyone else who googled CFTREE and found this image and is looking for a similar diagram, I can recommend GraphViz as a solution. I've used it and it's easy and powerful. From ColdFusion or any other language you can call it via the command line, have it create an image, use that image, then delete the image. The reason I mention this software is there a whole science (algothrym) behind how to build a diagram like this. Rather than write it yourself, just use this free software.
To get the data ordered by parent/child, in Oracle you can use the CONNECT BY statement.
Build your string of data then call GraphViz - e.g.,
Then refer to the image
And delete it:

Resources