Re: [matplotlib-devel] Interpolation in a triangular mesh (tri.Triangulation)

2012-11-15 Thread geoffroy billotey
Hello Ian,

Thank you for your second proposition ; I find it very interesting in fact.

(But beware that, as I do not feel able to do this on my own, your code
exemple / guidance would be needed for sure... )
I will have a look at http://matplotlib.org/devel/index.html

I think your idea of having a separate TriFinder class is quite good. My
search algo. is not optimised, only avoiding a O(N) for interpolations
along a path or line.
Some other parts of the code (especially the loop over the (x,y) points in
__call__() ) may also be performance-critical, at least for the 'cubic'
interpolator. But I dont have a clear picture on how to embed C++ code in
python so I would need your example to figure out what is possible.

Regards
Geoffroy.


2012/11/14 Ian Thomas 

> Hi Geoffroy,
>
> I have had some time to look at your TriLinearInterpolator in some detail
> (the other two files only briefly).  I would indeed like to add something
> like this to matplotlib - the mesh refinement looks very nice and the
> interpolators would be useful to many people.
>
> As you suspected, the code does need significant changes before we can
> include it.  Some are merely cosmetic, as all code must adhere to PEP8 and
> the matplotlib coding guidelines, but there are also some functional and
> performance improvements.  For example, your wavefront method for finding
> the triangle containing a certain point must be able to deal with masked
> triangulations and indeed triangulations that are discontinuous, for
> example two islands in a masked-out ocean, which is unusual but must be
> supported.  In terms of performance, there is much explicit looping within
> numpy arrays that could be improved using other numpy array commands, and
> would also reduce the length of the source code.  There is an argument for
> some of the performance-critical code to be in C/C++.
>
> I think the code used to determine which triangle contains a certain point
> should be factored out into its own TriFinder class, so that (1) it does
> not need to be replicated in the two interpolator classes, and (2)
> different algorithms can be easily swapped if necessary.  I have a C++
> TriFinder class that I could modify to work within matplotlib, and it is
> O(log N) so should be faster than your version for typical use cases.
>
> I expect that this is probably more work than you anticipated when you
> asked if the code needed any improvement!  I propose the following: if you
> are happy to give matplotlib your source code as it stands and for us to
> include it under our BSD-style license, then I will take on the
> responsibility of getting it into a form that will be accepted by the other
> developers.  I will acknowledge your contribution in both the source code
> and on the web site, something like "based on code contributed by Geoffroy
> Billotey".
>
> Alternatively, if you would like to use this as an excuse to learn how to
> contribute to matplotlib more actively but don't want to take on
> everything, then we could divide up the work so that first I write my C++
> log(N) TriFinder class and the linear interpolator that uses it, and then
> you could modify the cubic interpolator following the format of the linear
> interpolator and using my guidance as and when you need it.
>
> Let me know your preference,
> Ian
>
> P.S.  Never apologise for not being a computer scientist!  Many of our
> developers, myself included, are proper scientists or engineers!!!
>
>
>
> On 29 October 2012 09:37, Ian Thomas  wrote:
>
>> Hi Geoffroy
>>
>> This will certainly be very useful.  I need to spend some time looking at
>> it and seeing how it would best fit within the matplotlib framework,
>> particularly as only a few days ago I committed to writing a triangular
>> grid interpolator for quad grids and it would be sensible to group these
>> interpolators together in some way.
>>
>> I'll get back to you when I've had time to look at it.
>>
>> Thanks for your efforts!
>> Ian
>>
>>
>>
>> On 28 October 2012 20:17, GBillotey  wrote:
>>
>>>Hi!
>>>
>>>
>>> I had recently to develop interpolators for a function defined at the
>>> nodes
>>> of a user-specified triangular mesh.
>>> (Beside interpolation, it can help producing higher-quality tricontour
>>> plots, using interpolation on a refined mesh and matplotlib tricontour
>>> function.)
>>>
>>> Being a regular user of matplotlib, I would be happy if it can be useful
>>> to
>>> others...
>>> The code is hosted here:
>>> https://github.com/GBillotey/trimesh-interpolator.git
>>>
>>>
>&g

Re: [matplotlib-devel] trisurf plots with independent color data

2015-01-21 Thread Geoffroy Billotey
Hi,

You can also try to pass a *color* array of size ntri (number of triangles)
to the *set_array* method of the collection returned by *plot_trisurf*.

See for instance:
http://stackoverflow.com/questions/24218543/colouring-the-surface-of-a-sphere-with-a-set-of-scalar-values-in-matplotlib/24229480#24229480



2015-01-21 17:02 GMT+01:00 Maximilian Albert :

> Hi Byron,
>
> This is a bit of a workaround, but you can specify facecolors explicitly
> by creating a triangulation of your surface explicitly and creating a
> Poly3DCollection with these facecolors. I'm attaching an example below
> which is a modified version of the plot_trisurf demo [1] in the matplotlib
> documentation. It showcases both random colors and a smooth gradient (the
> latter in the line that's commented out).
>
> I would have thought that it should be possible to pass an argument like
> "facecolors" to plot_trisurf directly, since the documentation [2] states
> that "other arguments are passed on to Poly3DCollection". However, I
> couldn't get this to work quickly. Maybe someone else knows how?
>
> Best regards,
> Max
>
> [1] http://matplotlib.org/examples/mplot3d/trisurf3d_demo.html
> [2] http://matplotlib.org/mpl_toolkits/mplot3d/api.html
>
>
>
> from mpl_toolkits.mplot3d import Axes3D
> from matplotlib import cm
> import matplotlib.pyplot as plt
> import numpy as np
>
> from matplotlib.tri import Triangulation
> from mpl_toolkits.mplot3d.art3d import Poly3DCollection
>
> n_angles = 36
> n_radii = 8
>
> # An array of radii
> # Does not include radius r=0, this is to eliminate duplicate points
> radii = np.linspace(0.125, 1.0, n_radii)
>
> # An array of angles
> angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
>
> # Repeat all angles for each radius
> angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
>
> # Convert polar (radii, angles) coords to cartesian (x, y) coords
> # (0, 0) is added here. There are no duplicate points in the (x, y) plane
> x = np.append(0, (radii*np.cos(angles)).flatten())
> y = np.append(0, (radii*np.sin(angles)).flatten())
>
> # Pringle surface
> z = np.sin(-x*y)
>
> tri = Triangulation(x, y)  # NOTE: This assumes that there is a nice
> projection of the surface into the x/y-plane!
> triangle_vertices = np.array([np.array([[x[T[0]], y[T[0]], z[T[0]]],
> [x[T[1]], y[T[1]], z[T[1]]],
> [x[T[2]], y[T[2]], z[T[2) for
> T in tri.triangles])
> midpoints = np.average(triangle_vertices, axis=1)
>
> def find_color_for_point(pt):
> x, y, z = pt
> col = [(y+1)/2, (1-y)/2, 0]
> return col
>
> #facecolors = [find_color_for_point(pt) for pt in midpoints]  # smooth
> gradient
> facecolors = [np.random.random(3) for pt in midpoints]  # random colors
>
> coll = Poly3DCollection(triangle_vertices, facecolors=facecolors,
> edgecolors='black')
>
> fig = plt.figure()
> ax = fig.gca(projection='3d')
> ax.add_collection(coll)
> ax.set_xlim(-1, 1)
> ax.set_ylim(-1, 1)
> ax.set_zlim(-1, 1)
> ax.elev = 50
>
> plt.show()
>
>
>
> --
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> ___
> Matplotlib-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>
--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet___
Matplotlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel