On Mon, Aug 03, 2009 at 05:57:29PM -0400, Tom Foutz wrote:
> I saw that there is delaunay tessalation as well in mayavi, which
> sparked my question.

> I am using NEURON, a software package which now uses python.  I have a
> number of neuron cells which I need to populate inside a volume.  I
> have written a script which will randomly populate points within a
> cube which is larger than the volume of interest.  All I need to know
> now is whether or not that point is within the volume described by
> triangular meshes.

OK, but the interior part of the delaunay tessalation of a cloud of
points is, AFAIK, not garantied to be the convex hull. It does contain
it, I believe.

Here is some code using the vtk ProbeFilter to evaluate the data in a
delaunay interpolation. If you put ones on your mesh, what evaluates to
one is inside the Delaunay interpolation range, and what evaluates to 0
is outside.

HTH,

Gaƫl
from enthought.mayavi import mlab

from enthought.tvtk.api import tvtk



import numpy as np

from scipy import vectorize



n = 8

t = np.linspace(-np.pi, np.pi, n)

z = np.exp(1j*t)

x = z.real.copy()

y = z.imag.copy()

z = np.zeros_like(x)



triangles = [(0, i, i+1) for i in range(n)]

x = np.r_[0, x]

y = np.r_[0, y]

z = np.r_[1, z]



mlab.clf()

mesh = mlab.triangular_mesh(x, y, z, triangles, 

                            scalars=np.ones_like(x), 

                            opacity=0.5)



delaunay = mlab.pipeline.delaunay3d(mesh)

unstructured_grid = delaunay.outputs[0]



def probe_data(dataset, x, y, z):

    """ Probe a vtk dataset at given points x, y, z.



        Parameters

        ----------

        dataset: vtk dataset

            The dataset giving the data you are interested in

        x: float or ndarray

            The x position where you want to query the data

        y: float or ndarray

            The y position where you want to query the data

        z: float or ndarray

            The z position where you want to query the data

    

        Returns

        --------

        The values of the scalar data at the given point. 

    """

    # XXX: Should be implemented for more than just the scalars

    shape = x.shape

    x = np.atleast_1d(x)

    y = np.atleast_1d(y)

    z = np.atleast_1d(z)

    probe_data = mesh = tvtk.PolyData(points=np.c_[x.ravel(),

                                                   y.ravel(),

                                                   z.ravel()])

    probe = tvtk.ProbeFilter()

    probe.input = probe_data

    probe.source = dataset

    probe.update()

    

    values = probe.output.point_data.scalars.to_array()

    values = np.reshape(values, shape)

    return values







x_, y_, z_ = np.mgrid[-1:1:30j, -1:1:30j, -1:1:30j]

labels = probe_data(unstructured_grid, x_, y_, z_)



src = mlab.pipeline.scalar_field(x_, y_, z_, labels, transparent=True)



#scp = mlab.pipeline.scalar_cut_plane(src)

scp = mlab.pipeline.scalar_cut_plane(src)



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
MayaVi-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Reply via email to