Layout manager for .NET, UI agnostic - algorithm

I need a simple Layout Manager that is UI agnostic. By this, I mean it should not specify how I want to represent my shapes/controls on the screen. It should just enable me to say:
I want shape X here.
I want shape Y under shape X.
I want shape Z to surround X, and isolate itself from shape Y.
I guess it would be nice if it can also give me (X, Y) for each shape when I am finished.
I am using .NET.

You could consider Windows Presentation Foundation
The Layout System

Related

Disable rotation on Z axis

I am developing an application to register and display a 3D DICOM image using VTK, ITK, and QT.
I am running into some issues with the registration part.
I am using the ScaleVersor3DTransform, VersorTransformOptimizer, NormalizedCorrelationImageToImageMetric, and LinearInterpolateImageFunction for this.
The problem is that I need to lock or disable the rotation on Z axis. The only axis that can rotate are X and Y.
I tried getting the GetNumberOfParameters() from the transform and setting all its values to 1.0 (although I think the Z-rotation is the third position on the array), but that didn't seen to work.
What are my options?
You can minimize (or disable) a certain parameter by setting a very high scale for the parameter you do not want to optimize (using SetScales on the optimizer). In the case of a ScaleVersor3DTransform, no single parameter is representing the Z-rotation, so I am afraid it won't work out for your specific case.
You could consider to use a Euler3DTransform instead, for which the Z-rotation is a specific parameter of the transformation.

From TopLeft 0,0 to BottomLeft 0,0 in GDI win32

How can I change transform the coordinates in a window from 0,0 topleft to 0,0 bottomleft.
I have tried various solutions with
SetMapMode(hdc,MM_TEXT);,
SetViewportExtEx(hdc,0,-clientrect.bottom,NULL);
SetViewPortOrgEx(hdc,0,-clientrect.bottom,NULL);
SetWindowOrgEx(hdc,0,-clientrect.bottom,NULL);
SetWindowExtEx(hdc,0,-clientrect.bottom,NULL);
I have even tried google for a solution but to no prevail, so I turn to you the more experienced people on the internet.
The idea is I'm creating a custom control for linear interpolation and I could reverse the coordinate system by x,y in top right corner but I want it right. At the moment I get a reversed linear interpolation when I try to draw it as I cannot get the coords to be bottomleft.
I'm using win32 api, and I suspect I can skip the code as the screen coordinate system is almost identical on all systems, by that I mean 0,0 is "always" topleft on the screen if you are keeping it to standard 2d window and frames.
I really don't want a whole codesample to ease the typing pain for you guys, but I want some direction as it seems I cannot grasp the simple concept of flipping the coords in win32 api.
Thanks and a merry christmas
EDIT !
I would like to add my own answer to this question as I used simple math to reverse the view so to say.
If for an example I got the valuepair x,y (150,57) and another pair x,y (100,75) then I used this formulae height + (-1 * y) and voila I get a proper cartesian coordinate field :) ofcourse in this example height is undefined variable but in my application its 200px in height.
According to the documentation for SetViewportOrgEx, you generally want to use it or SetWindowOrgEx, but not both. That said, you probably want the viewport origin to be (0, clientrect.bottom), not -clientrect.bottom.
Setting transforms with GDI always made me crazy. I think you're better off using GDI+. With it, you can create a matrix that describes a translation of (0, clientRect.bottom), and a scaling of (1.0, -1.0). Then you can call SetWorldTransform.
See the example at Using Coordinate Spaces and Transformations. For general information about transforms: Coordinate Spaces and Transformations.
Additional information:
I've not tried this with direct Windows API calls, but if I do the following in C# using the Graphics class (which is a wrapper around GDI+), it works:
Graphics g = GetGraphics(); // gets a canvas to draw on
SetTranslateTransform(0, clientRect.Bottom);
SetScaleTransform(1.0f, -1.0f);
That puts the origin at the bottom left, with x increasing to the right and y increasing as you go up. If you use SetWorldTransform as I suggested, the above will work for you.
If you have to use GDI, then you'll want to use SetViewportOrgEx(0, clientRect.bottom), and then set the scaling. I don't remember how to do scaling with the old GDI functions.
Note also that the documentation for SetViewportExtEx says:
When the following mapping modes are set, calls to the SetWindowExtEx
and SetViewportExtEx functions are ignored.
MM_HIENGLISH
MM_HIMETRIC
MM_LOENGLISH
MM_LOMETRIC
MM_TEXT
MM_TWIPS

medial axis transform implementation

How do I implement the Medial Axis Transform algorithm to transform the first image into the second?
(source: algorith at www.cs.sunysb.edu)
(source: algorith at www.cs.sunysb.edu)
What library in C++/C# have support for Medial Axis Transform?
There are many implementations of the medial axis transform on the Internet (personally I don't use OpenCV library but I'm sure it has a decent implementation). However, you could easily implement it yourself.
In order to perform medial axis transform, we need to define only one term: simple point.
A point (P) is simple point iff removing P doesn't effect the number of connected components of either the foreground or the background. So, you have to decide the connectivity (4 or 8) for the background and for the foreground - in order to work pick different one for both (if you are interested why, look up Jordan property on google).
Medial transform axis could be implemented by sequentally deleting simple points. You get the final skeleton if there are no more simple points. You get the curved skeleton (I don't know the english name for it which is rare - please correct me) if you only have endpoints OR non-simple points. You provided examples of the latter in your question.
Finding simple points could be easily implemented with morphological operators or a look-up table. Hint: a point is simple point iff the number of connected components in the background is 1 and the number of connected components in the foreground is 1 in a 3x3 local window.
There is a medial axis transform available in this C Library:http://www.pinkhq.com/
There are lot other related functionalities.
Check out this Function:http://www.pinkhq.com/medialaxis_8c.html

Set cursor position in Mac OS

I want to write a little vnc similar program that moves the Mac OS cursor to a position (x, y) given through a protocol which gets data from Bonjour service. The problem is that I don't know how to move the cursor!
I'm working with Cocoa.
You can be forgiven for not looking in Quartz Display Services for this one. The function you're after is CGWarpMouseCursorPosition.
Since the documentation doesn't say, you'll have to experiment to determine which co-ordinate system it uses—i.e., where the origin is and which way positive y goes.

How can the crosshair of ginput be restricted to one plot?

I wrote a small MATLAB program with a gui. Inside the gui I have, among other things, a plot in which the user should be able to select two points. For this I use the function ginput, which creates a crosshair for selection. Unfortunatley the crosshair extends the whole window and is not restricted to the plot, which doesn't look nice and is confusing for the user. How can the crosshair be restricted only to the area of the plot?
Try using getpts, which doesn't create the crosshair; with getpts, you can also specify the axes you want the user to select from, as in
[x,y] = getpts(ax);
The only trouble with getpts is there's no way to limit it to exactly two points. But it does have the nice feature that the user can undo point selection by hitting DELETE, and confirm points by hitting ENTER.
looking closely at the ginput documentation, the behavior you describe is intended, and apparently unavoidable
from
doc ginput
Clicking an axes makes that axes the current axes. Even if you set the current axes before calling ginput, whichever axes you click becomes the current axes and ginput returns points relative to that axes. If you select points from multiple axes, the results returned are relative to the coordinate system of the axes they come from.
Try this slightly modified ginput script on File Exchange that takes the wanted crosshair as input. Because it is modified from ginput rev. 5.32.4.4, I recommend you make a new one from the latest version.
try ginputax. It does exactly what you want. This function works as ginput but it is adapted to be used in GUIs.
Here is an example in how to use it.
http://www.mathworks.com/matlabcentral/fileexchange/39799

Resources