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:
Related
Given and image and 4 corner points of an area inside the image, I want to figure out if a point p (x,y) lays inside the given area. The area is not necessarily in form of a rectangle, as the area is the result of a perspective projection of some other image.
For example:
Here I want to figure out if the pink point actually lays within the shape inside the image. In this case it does.
I was thinking about drawing an contour with drawContours and then using pointPolygonTest but I was wondering if there is an easier and more tailored way of doing it.
I'm writing a connected component system and one of the descriptors I can easily compute is the surface area along with the component's rectangular bounding box.
What is surface area divided by bounding area called? (or any mixture of these two parameters).
For example, if my object were a rectangle, this parameter would be 1.0.
Extent or rectangularity, apparently:
Extent of an image object is defined as area of the image object
divided by the area of its bounding rectangle.
Source: Question text in https://dsp.stackexchange.com/questions/49026/what-is-the-application-difference-between-extent-and-solidity-in-image-processi
Rectangularity is the ratio of the object to the area of the minimum
bounding rectangle.
Source: Page 45 in http://www.cyto.purdue.edu/cdroms/micro2/content/education/wirth10.pdf
But the definitions I've run across do not always fully specify the rectangle. The ambiguity is related to the concept of "ferret box". Ferret boxes' edges do not have to be parallel to the image axes like good old bounding boxes. So depending on which you choose, your "extent" value might change.
I am trying to find a reliable method to calculate the corner points of a container. From these corner point’s idea is to calculate the center point of the container for the localization of robot, it means that the calculated center point will be the destination of robot in order to pick the container. For this I am looking for any suggestions to calculate the corner points or may be if any possibility to calculate the center point directly. Up to this point PCL library C/C++ is used for the processing of the 3D data.
The image below is the screenshot of the container.
thanks in advance.
afterApplyingPassthrough
I did the following things:
I binarized the image (black pixels = 0, green pixels = 1),
inverted the image (black pixels = 1, green pixels = 0),
eroded the image with 3x3 kernel N-times and dilated it with same kernel M-times.
Left: N=2, M=1;Right: N=6, M=6
After that:
I computed contours of all non-zero areas and
removed the contour that surrounded entire image.
This are the contours that remained:
I do not know how "typical" input image looks like in your case. Since I only have access to one sample image, I would rather not speculate about "general solution" that will be suitable for you. But to solve this particular case, you could analyze every contour in the following way:
compute rotatated rectangle that fits best around your contour (you need something similar to minAreaRect from OpenCV)
compute areas of rectangle and contour interior
if the difference between contour area and the area of the rotated bounding rectangle is small, the contour has approximately rectangular shape
find the contour that is both rectangular and satisfies some other condition (for example: typical area of the container). Assume that this belongs to container and compute its center.
I am not claiming that this is a solution that will work well in real world scenarios. It is also not fast. You should view it as a "sketch" that shows how to extract some useful information.
I assume the wheels maintain the cart a known offset from the floor and you can identify the floor. Filter out all points which are too close to the floor (this will remove wheels and everything but cart which will help limit data and simplify later steps.
If you isolate the cart, you could apply a simple average point (centroid), alternately, if that is not precise, you could try finding the bounding box of the isolated cart (min max in primary directions) and then take the centroid of that bounding box (this should be more accurate, but will still need a slight vertical offset due to the top handles).
If you can not isolate the cart or the other methods are not working well, you could try using PCL sample consensus specifically SACMODEL_LINE. This will be an involved strategy, but will give very solid results, basically run through and find each line and subtract its members from the cloud so as to find the next best line. After you have your 4 primary cart lines, use their parameters to find your centroid. *this would also be robust against random items being in or on the cart as well as carts of various sizes (assuming they always had linear perpendicular walls)
I want to find all pixels in an image (in Cartesian coordinates) which lie within certain polar range, r_min r_max theta_min and theta_max. So in other words I have some annular section defined with the parameters mentioned above and I want to find integer x,y coordinates of the pixels which lie within it. The brute force solution comes to mid offcourse (going through all the pixels of the image and checking if it is within it) but I am wondering if there is some more efficient solution to it.
Thanks
In the brute force solution, you can first determine the tight bounding box of the area, by computing the four vertexes and including the four cardinal extreme points as needed. Then for every pixel, you will have to evaluate two circles (quadratic expressions) and two straight lines (linear expressions). By doing the computation incrementally (X => X+1) the number of operations drops to about nothing.
Inside a circle
f(X,Y) = X²+Y²-2XXc-2YYc+Xc²+Yc²-R² <= 0
Incrementally,
f(X+1,Y) = f(X,Y)+2X+1-2Xc <= 0
If you really want to avoid that overhead, you will resort to scanline conversion techniques. First think of filling a slanted rectangle. Drawing two horizontal lines by the intermediate vertices, you decompose the rectangle in two triangles and a parallelogram. Then for any scanline that crosses one of these shapes, you know beforehand what pair of sides you will intersect. From there, you know what portion of the scanline you need to fill.
You can generalize to any shape, in particular your circle segment. Be prepared to a relatively subtle case analysis, but finding the intersections themselves isn't so hard. It may help to split the domain with a vertical through the center so that any horizontal always meets the outline twice, never four times.
We'll assume the center of the section is at 0,0 for simplicity. If not, it's easy to change by offsetting all the coordinates.
For each possible y coordinate from r_max to -r_max, find the x coordinates of the circle of both radii: -sqrt(r*r-y*y) and sqrt(r*r-y*y). For every point that is inside the r_max circle and outside the r_min circle, it might be part of the section and will need further testing.
Now do the same x coordinate calculations, but this time with the line segments described by the angles. You'll need some conditional logic to determine which side of the line is inside and which is outside, and whether it affects the upper or lower part of the section.
I have a set of points to define a shape. These points are in order and essentially are my "selection".
I want to be able to contract this selection by an arbitrary amount to get a smaller version of my original shape.
In a basic example with a triangle, the points are simply moved along their normal which is defined by the points to the left and the right of the points in question.
Eventually all 3 points will meet and form one point but until that point they will make a smaller and smaller triangle.
For more complex shapes, when moving the individual points inward, they may pass through the outer edge of the shape resulting in weird artifacts. Obviously I'll need to cull these points and remove them from the array.
Any help in exactly how I can do that would be greatly appreciated.
Thanks!
This is just an idea but couldn't you find the center of mass of the object, create a vector from the center to each point, and move each point along this vector?
To find the center of mass would of course involve averaging each x and y coordinate. Getting a vector is as simple a subtracting the point in question with the center point. Normalizing and scaling are common vector operations that can be found with the Google.
EDIT
Another way to interpret what you're asking is you want to erode your collection of points. As in morphology erosion. This is typically applied to binary images but you can slightly modify the concept to work with a collection of points. Essentially, you need to write a function that, given a point, will return true (black) or false (white) depending on if that point is inside or outside the shape defined by your points. You'd have to look up how to do that for shapes that aren't always concave (it's harder but not impossible).
Now, obviously, every single one of your actual points will return false because they're all on the border (by definition). However, you now have a matrix of points around your point of interest that define where is "inside" and where is "outside". Average all of the "inside" points and move your actual point along the vector between itself and towards this average. You could play with different erosion kernels to see what works best.
You could even work with a kernel with floating point weights instead of either/or values which will affect your average calculation proportional to their weights. With this, you could approximate a circular kernel with a low number of points. Try the simpler method first.
Find the selection center (as suggested by colithium)
Map the selection points to the coordinate system with the selection center at (0,0). For example, if the selection center is at (150,150), and a given selection point is at (125,75), the mapped position of the point becomes (-25,-75).
Scale the mapped points (multiply X and Y by something in the range of 0.0..1.0)
Remap the points back to the original coordinate system
Only simple maths required, no need to muck about normalizing vectors.