Tom Foutz | 3 Aug 2009 23:11
Picon

Check point Inside/Outside a volume

I've made a closed volume triangular mesh using:
triangular_mesh(X,Y,Z,triangles,color=self.color,opacity=self.opacity)

And I have a point (x,y,z)

In matlab I have been able to use the delaunay tessellation method to determine whether or not the point is inside the triangle mesh.  However, I have not found any way to do it in python.

Any ideas?
-Tom

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 3 Aug 2009 23:14
Favicon
Gravatar

Re: Check point Inside/Outside a volume

On Mon, Aug 03, 2009 at 05:11:26PM -0400, Tom Foutz wrote:
>    I've made a closed volume triangular mesh using:
>    triangular_mesh(X,Y,Z,triangles,color=self.color,opacity=self.opacity)

>    And I have a point (x,y,z)

>    In matlab I have been able to use the delaunay tessellation method to
>    determine whether or not the point is inside the triangle mesh.  However,
>    I have not found any way to do it in python.

>    Any ideas?

What is your end goal? You can use Delaunay tessalation with Mayavi too,
but the question is: what do you want to do afterward?

Gaël

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Tom Foutz | 3 Aug 2009 23:57
Picon

Re: Check point Inside/Outside a volume

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.

Thanks!
-Tom

On Aug 3, 2009, at 17:14, Gael Varoquaux
<gael.varoquaux <at> normalesup.org> wrote:

> On Mon, Aug 03, 2009 at 05:11:26PM -0400, Tom Foutz wrote:
>>   I've made a closed volume triangular mesh using:
>>   triangular_mesh
>> (X,Y,Z,triangles,color=self.color,opacity=self.opacity)
>
>>   And I have a point (x,y,z)
>
>>   In matlab I have been able to use the delaunay tessellation
>> method to
>>   determine whether or not the point is inside the triangle mesh.
>> However,
>>   I have not found any way to do it in python.
>
>>   Any ideas?
>
> What is your end goal? You can use Delaunay tessalation with Mayavi
> too,
> but the question is: what do you want to do afterward?
>
> Gaël

------------------------------------------------------------------------------
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
Gael Varoquaux | 4 Aug 2009 11:59
Favicon
Gravatar

Re: Check point Inside/Outside a volume

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
Attachment (test.py): text/x-python, 2058 bytes
------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Tom Foutz | 4 Aug 2009 17:07
Picon

Re: Check point Inside/Outside a volume

Thank you so much gael!  That worked perfectly. I attached a picture of the result.  I am amazed at how fast it finds the result.
-Tom

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 4 Aug 2009 17:09
Favicon
Gravatar

Re: Check point Inside/Outside a volume

On Tue, Aug 04, 2009 at 11:07:28AM -0400, Tom Foutz wrote:
>    Thank you so much gael!  That worked perfectly. I attached a picture of
>    the result.  I am amazed at how fast it finds the result.
>    -Tom

Nothing makes me happier than a happy user! I must admit I tried other
approachs require less VTK wizardry, and they were much slower.

Gaël

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Tom Foutz | 4 Aug 2009 18:58
Picon

Re: Check point Inside/Outside a volume

Thanks again for you help.  I am looking at the code, and I see that you are creating two meshes, one for the population of points tested, and the other for the volume mesh.

Since I don't have a perfectly convex mesh for the volume, some points in concave areas are mistakenly identified as included in the mesh.  Could this be a problem with the delaunay3d conversion to an unstructered grid?

I'm including a picture to demonstrate this.

Thanks again!
-Tom

On Tue, Aug 4, 2009 at 11:09, Gael Varoquaux <gael.varoquaux <at> normalesup.org> wrote:
On Tue, Aug 04, 2009 at 11:07:28AM -0400, Tom Foutz wrote:
>    Thank you so much gael!  That worked perfectly. I attached a picture of
>    the result.  I am amazed at how fast it finds the result.
>    -Tom

Nothing makes me happier than a happy user! I must admit I tried other
approachs require less VTK wizardry, and they were much slower.

Gaël

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 4 Aug 2009 19:02
Favicon
Gravatar

Re: Check point Inside/Outside a volume

On Tue, Aug 04, 2009 at 12:58:28PM -0400, Tom Foutz wrote:
>    Since I don't have a perfectly convex mesh for the volume, some points in
>    concave areas are mistakenly identified as included in the mesh.  Could
>    this be a problem with the delaunay3d conversion to an unstructered grid?

>    I'm including a picture to demonstrate this.

The problem is that Delaunay will give you a convex hull of the points,
but not the interior of the surface. The points that you see as
mis-labels are in the convex hull of the points, but not inside your
surface.

You have a 'closure' problem, which is a different problem than a convex
hull one, and a much more difficult, I believe. I must admit that I do
not know hos to solve it.

Cheers;

Gaël

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Tom Foutz | 5 Aug 2009 05:42
Picon

Find interpolated data on triangular mesh

Hi, I am working on a triangular mesh of data, and I am trying to interpolate values that are between vertices.  I have come up with the following method:, based on Gael's previous examples.  However, I always get an array of 0.0 for output.

Thanks!
--Tom

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

from enthought.mayavi import mlab
mesh=mlab.pipeline.triangular_mesh_source(x,y,z,tri,scalars=volt)

def interpolate_voltage(x,y,z,mesh):
    delaunay = mlab.pipeline.delaunay3d(mesh)
    unstructured_grid = delaunay.outputs[0]

    from enthought.tvtk.api import tvtk
    shape=x.shape

    x = np.atleast_1d(x)
    y = np.atleast_1d(y)
    z = np.atleast_1d(z)
    probe_data=tvtk.PolyData(points=np.c_[x.ravel(),y.ravel(),z.ravel()])
    probe = tvtk.ProbeFilter()
    probe.input = probe_data
    probe.source = unstructured_grid
    probe.update()
    values = probe.output.point_data.scalars.to_array()
    values = np.reshape(values, shape)
    return values

X,Z=np.meshgrid(np.linspace(min(x),max(x),5),np.linspace(min(z),max(z),5))
X=X.flatten()
Z=Z.flatten()
Y=np.zeros(X.shape)
interpVolt=interpolate_voltage(X,Y,Z,mesh)
print interpVolt

mlab.pipeline.surface(mesh)
#mlab.points3d(X,Y,Z,interpVolt,scale_mode='scalar',scale_factor=3e-3)
mlab.points3d(X,Y,Z,scale_mode='scalar',scale_factor=3e-3)
mlab.show()

------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users
Gael Varoquaux | 5 Aug 2009 07:38
Favicon
Gravatar

Re: Find interpolated data on triangular mesh

On Tue, Aug 04, 2009 at 11:42:36PM -0400, Tom Foutz wrote:
>    Hi, I am working on a triangular mesh of data, and I am trying to
>    interpolate values that are between vertices.  I have come up with the
>    following method:, based on Gael's previous examples.  However, I always
>    get an array of 0.0 for output.

It is hard to say, as the example you give does not run, and thus does
not allow to test the problem.

I am tempted to say that this is because you have a cloud of points that
does not define a good interpolation domain.

I have modified your example so that it works, but I have not added any
fundemental differences.

Gaël
Attachment (test.py): text/x-python, 885 bytes
------------------------------------------------------------------------------
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
MayaVi-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Gmane