Paraview: rotate around a given axis - paraview

The default 3D rotation mode is a kind of rollerball mode. Is it possible to interactively rotate about a given axis (say x, y or z axis), instead? I see you can do it by typing numbers into the view details dialog, but that is painful.

While rotating, simply press the X, Y or Z key to limit the rotation to the corresponding axis (ParaView Blog. August 1, 2015).

Yes. By holding Shift, you will rotate around the back-front axis.
I suggest you use the view toolbar to put the correct axis to the back.
You can change the default behavior of different mouse+keyboard combinations in Edit->Settings->Camera.
The name of the desired behavior is "roll".

Related

How to reverse the direction of Y-Axis of MatLab figure generated by `imagesc()` function

I am trying to display data in a matrix using imagesc() function but it is showing row index in decreasing order (Assuming origin at left-bottom). Any idea what mistake i could be making or how to correct this?
The matrix only has zeros and ones in it.
Set Ydir property of the current axes to normal
By default, imagesc uses reverse for YDir
set(gca,'YDir','normal');
See Documentation for Axes properties
Before:
After:
Note: This completely flips the inside data as well (it supposed to). As you are dealing with matrices, I hope this is what you want.
If you don't want to affect inside data, you need to change order of YTickLabels instead.
There's another option which requires slightly less code:
axis ij
Reverse the coordinate system so that the y values increase from top to bottom.
As in this case (as it is already reversed), you could use
axis xy
To get back to normal, so that y values increases from bottom to top.
As mentioned in the docs of axis.

Rotating a patch to face the camera in Matlab

This short code plots a flat patch (adapted from Matlab's manual):
t = 0:pi/5:2*pi;
figure
x=sin(t); y=cos(t); z=ones(size(x));
patch(x,y,z,'y')
axis equal
This results with a nice patch facing the camera:
However, I want to plot this patch on top of an already plotted 3D object, with the camera set on a fixed arbitrary view. My question is: how to rotate the patch's coordinates so the patch will face the camera and will have the right roll? A correct solution will make the patch look the same from any given arbitrary view (uniform scaling is permitted).
I guess that the camera's position, target and up-vector have to be taken into account, but it's not clear to me how.
It's funny, but today I was doing exactly the same thing :)
My approach is the following
Put your camera somewhere on the positive half of the X axis and set camera target to (0,0,0)
Draw your object the way you need it
Store X, Y, and Z coordinates of your object
Use rotate3d function and the make callbacks for ActionPreCallback and ActionPostCallback events of the rotate3d mode object
You'll need also to provide your routine for 'WindowButtonMotionFcn' event of the active figure
The whole logic works like this.
After you clicked rotate3d icon or call the rotate3d function, right after you click the left button on axes to start rotation, the ActionPreCallback event is fired. There you have to set flag (WeAreRotating in the code below) that rotation started. Then in the 'WindowButtonMotionFcn' callback function you retrieve camera view position using
[az,el] = view(ah);
function and rotate your object. The rotation is tricky, because you have to set its X, Y, and Z coordinates to the original ones you stored before and apply the rotate function to it. Something like this:
function fig_WindowButtonMotionFcn_callback(obj,evd)
if getappdata(gca,'WeAreRotating')
newView = round(get(gca,'View'));
set( ObjectHandle, ...
'XData',XData0, ...
'YData',YData0, ...
'ZData',ZData0 );
rotate( ObjectHandle, [1 0 0],-newView(2), RotationOrigin );
rotate( ObjectHandle, [0 0 1],+newView(1), RotationOrigin );
end
end % if FogProps.SimpleWhenRotated
The ActionPostCallback event is triggered when you release the mouse button and finish rotation. There you have to clear the rotation flag so moving your mouse will not change the object until you start rotation again.
Sorry if my explanation is somewhat unclear.
It is a little tricky to arrange all the flags properly, especially if you have several axes on the figure.
Actually, after your question I decided to clean my code and post it to FEX so everyone can use it so there you'll see how I achieved desired behavior.
UPDATE1
See http://www.mathworks.com/matlabcentral/fileexchange/47275-fog3d for full example

Change 3D view in matlab

I would like to change the view of a 3D plot in matlab such that the y-axis points upward and the z-axis points to left. For example, consider the following plot:
Here the x-axis points forward, the y-axis points to the right and the z-axis points upward.
I would like to have the y-axis points upward and the z-axis points to the left instead. I tried to rotate the plot (using the figure window toolbar rotate button) but I could not get it to work. (It should just be a simple 90 degrees rotation about the x-axis)
Code to generate the plot:
membrane
view(100,50)
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
grid on
Try using view. I don't have MATLAB available so I can't test it, but I think it can do what you want.
Example from the documentation:
Set the view along the y-axis, with the x-axis extending horizontally
and the z-axis extending vertically in the figure.
view([0 0]);
EDIT:
Try using three inputs to the view function. I can't experiment myself, but you should be able to do it if you choose the right values here.
From documentation:
view([x,y,z]) sets the view direction to the Cartesian coordinates x,
y, and z. The magnitude of (x,y,z) is ignored.
EDIT 2:
Check out camroll. I think camroll(90) (possibly in combination with view) will work.
From documentation:
camroll(dtheta) rotates the camera around the camera viewing axis by
the amounts specified in dtheta (in degrees). The viewing axis is the
line passing through the camera position and the camera target.
This was posted a while ago, but in case someone else is looking for ways to set y-axis as the vertical one here is a possible fix.
Manually: In the command window type cameratoolbar('show') which will open an interactive toolbar in your plot from which you could change the view. One of the options is to set a principle axis to x, y, or z.
Or in you script you could use cameratoolbar('SetCoordSys',coordsys) command which sets the principal axis of the camera motion. coordsys can be: x, y, z, or none.
http://uk.mathworks.com/help/matlab/ref/cameratoolbar.html

Matlab function surf axes going from high to low I want low to high?

Last question on this I swear.
Right now the plot of surf has the dates going from newest (i.e today) at the left hand side to oldest on the right hand side. I would like it to be the other wat round but keep everything else the same.
Is there a quick way to do this? Without having to reorganise the input data?
You can simply revert the direction of the axis. If it's the x-axis, you write
set(gca,'XDir','reverse')
gca grabs the handle to the currently active axes, so make sure that the surface is on the active figure, or store the axis handle somewhere and pass it instead as first argument to set.
Just replace the X in XDir if you want to do it for a different axis.
This can be set using axis properties:
Direction of increasing values. A mode controlling the direction of increasing axis values. Axes form a right-hand coordinate system. By default:
x-axis values increase from left to right. To reverse the direction of increasing x values, set this property to reverse.
set(gca,'XDir','reverse')
y-axis values increase from bottom to top (2-D view) or front to back (3-D view). To reverse the direction of increasing y values, set this property to reverse.
set(gca,'YDir','reverse')
z-axis values increase pointing out of the screen (2-D view) or from bottom to top (3-D view). To reverse the direction of increasing z values, set this property to reverse.
set(gca,'ZDir','reverse')

maintains position in any rotation

I have done some drawing on one layer now I want to draw same thing on another layer.So I have stored all the points of drawing that user has drawn on first layer.And then using convertPoint: toLayer: method converting stored point into points of another layer. And its working.But creates problem in orientation. If I have done drawing in portrait. Then it will work only for portrait in landscape position will be change. So please suggest any way to get out of this.
Thanks
Normalise your stored points, such that the x, y positions are relative to a surface of size 0..1, 0..1 (divide the x, y by the width and height of the current surface). Then, whenever you want to change the size of the underlying surface, multiply each point by this new surface's width and height. All points will now appear in the same relative positions regardless of the surface dimensions.
Note the above will scale (going from portrait to landscape, the Y will be compressed and the X expanded). If you don't want to do this, you will need to take physical dimensions of the surface on-screen into account too. That is, normalise your points to some physical dimension instead.
Note: I have no idea what system, language, package, library, etc. you are using as you don't state in your question!