remove part of iso_surface in mayavi - mayavi

I am trying to find some hints in documentation of mayavi without any success.
In the visualization of complex data I would like to remove a part of computed iso_surface.
E.g., I have a code like
field = mlab.pipeline.gaussian_splatter(data)
iso = mlab.pipeline.iso_surface(field, contours=[0.07])
I may remove part of this iso_surface by explicitly explaining that my data is limited along x, y or z by doing something like
field.filter.model_bounds = array([-1., 1., -1., 1., -1., 1.])
But I can not find the way to explain this for an arbitrary directed plane. For instance, I would like to limit my data for a (1,1,1) direction.
Is there a way to do this?

You can use data_set_clipper
to clip the data. The clipper is either interactive or non interactive. I will demonstrate it for a non interactive version:
fld = mlab.pipeline.scalar_field(data)
clip = mlab.pipeline.data_set_clipper(fld)
clip.widget.widget_mode='ImplicitPlane'
clip.widget.widget.enabled=0
clip.widget.widget.normal=(1,1,1)
clip.widget.widget.origin=(20,20,20) #(0,0,0) is not the centre but the corner
iso = mlab.pipeline.iso_surface(clip, contours=[0.07])
If you want to clip more often you have to put your clipped data into another data_set_clippe:
clip2=mlab.pipeline.data_set_clipper(clip)
However, I am not fully satisfied with my approach as it uses a lot of resources. If someone has a better solution I would be glad to see it.

if you're having trouble displaying the surface you want, try playing around with the argument of contours, if you can make them tight enough around the surface you want to have displayed you should get what you want..
if you could post some more of a {non,}working example I might be able to help out

Related

Smoothly painting a path of straight line segments in Qt5

I have a series of straight line segments of varying thickness connected end-to-end to create meandering path. Does anyone know a way to paint this as a smooth meandering line, sort of like vectorizing it? I am using QPainter. I haven't had any success finding an appropriate function in QPainterPath.
The data looks something like this:
[(QPointF, width), (QPointF, width), (QPointF, width), ... ]
Thanks!
EDIT: Added example image
I wanted to leave it open to creative responses, but I am just looking to move from linear interpolation (QPainter::drawLine()) to spline interpolation.
If I understand your question correctly...
Don't draw a line, draw a filled polygon that encloses your line data with the right thickness. Drawback: That requires calculations on your data beforehand.

Camera matrix from essential matrix

I am trying to extract camera matrix from essential matrix. I found some answers about this.
determine camera rotation and translation matrix from essential matrix
Rotation and Translation from Essential Matrix incorrect
In these answers, they suggest me to use newE where [U,S,V] = svd(E) and newE = U*diag(1,1,0)*Vt. I don't understand why I need to use newE. As I know, singular values are unique. So changing singular values to diag(1,1,0) seems to make E to completely different values.
I read 'Multiple View Geometry in Computer Vision' also, but it just refers to the ideal case, i.e., singular values are (1,1,0). I didn't find the reason of using newE.
Please can anyone explain me why people use newE?
If I understand your question correctly, then since you source data (and thus E) is usually noisy real world data, then by using diag(1,1,0) you are constraining the matrix to be of the correct scale and rank and algebraically enforcing the geometric constraints.
Wikipedia also a has a nice section explaining this.

Set figure object to bounding box of fig.get_tightbbox()

I'm wanting to mimic the figure extents observed in an output figure and apply them to the figure object itself. The output figure command I want to copy is:
plt.savefig(flname, bbox_inches='tight', pad_inches=0.03)
I've been able to grab the bounding box which generates the observed bbox in the figure using:
bbox = fig.get_tightbbox(fig.canvas.get_renderer())
but am lost as to how to apply that to the fig object!
If you go here:
http://matplotlib.org/api/figure_api.html
And look under the Figure class constructor you will find that in add_axes() and gca() there is a way to set the bbox using one of the kwargs, clip_box.
Additionally here is more information about the bbox.
http://stackoverflow.com/questions/29809238/definition-of-matplotlib-pyplot-axes-bbox
I hope this helps you like it did for me. In short, you cannot apply it to a figure, but you can seem to apply it to all axes.
If I read this question correctly, it hasn't quite been answered by dozens of answers on this general topic elsewhere on stack overflow. The overwhelming focus there actually is on savefig output, rather than on the figure handle in memory. My application was also on the figure handle, and it worked easily enough like this:
# make figure. w,h and dpi optional but allow for exact figure sizing
hf = plt.plot(x,y,figsize=(w,h),dpi=myscreendpi)
# adjust padding as required
hf.set_tight_layout({'pad':0.5})
tightbbox = hf.get_tightbbox(hf.canvas.get_renderer())
# just set it directly to figure size
hf.set(figheight=tightbbox.height,figwidth=tightbbox.width)

Contour diagram for Pandas and/or Seaborn for a 3-column matrix

I have like 400 data points which are in forms of a 3-tuple. Something like this:
[[1.2, 3.4, 7.8],
[3.1, 2.6, 3.4],
...
]
Each row is a 3-tuple point, (x, y, z) which shows a point in 3D space.
What I want to do is drawing a contour diagram using these values in the form shown in https://en.wikipedia.org/wiki/Contour_line.
I want this:https://en.wikipedia.org/wiki/Contour_line#/media/File:Contour2D.svg.
I want the third dimension (z) to be the source for contours.
I have seen some other examples on the net, but they are so confusing. They are relying on a function to draw the diagram which is not in my case. I am representing the function as a matrix.
I hope I give enough information to let you know what I am looking for.
Thanks guys.
You can try conrec algorithm from Paul Bourke. It's implemented in many languages and also good explained. It uses the marching cube algorithm.

Octave colorbar and units

In GNU Octave you can make a picture where different colors represent different values in a matrix. You can also add a colorbar, which shows what color corresponds to what value.
Is it possible to somehow add units to the values shown in the colorbar? Instead of saying “0.36” it would say “0.36 V/nm”? I know this is possible in Matlab, but I can’t figure out how to do it in Octave. Any good workarounds?
I assume someone here will mention that I should use matplotlib instead (that usually happens). How would you accomplish the same thing with that?
The matplotlib answer (using pylab) is
imshow(random((20,20)))
colorbar(format='%.2f V/nm')
In Octave it seems that the following works (but I'm no Octave expert so maybe there's a better way):
c=colorbar();
labels = {};
for v=get(c,'ytick'), labels{end+1} = sprintf('%.2f V/nm',v); end
set(c,'yticklabel',labels);