Hi Gael,

Thank for your response. It is working correctly.
Now I would like to do the same thing but with N regions and each region of 
different label.

How can I do that ? Do I need to create a loop to extract every region ?

Example : 

for i in xrange(im.max()+1):
    connect_ = tvtk.PolyDataConnectivityFilter(extraction_mode=6, 
                                        closest_point=ndimage.center_of_mass(im 
== i))
    connect = mlab.pipeline.user_defined(contour, filter=connect_)
    surf = mlab.pipeline.surface(connect,color=(0.9, 0.72, 0.62))

It is quite slow to compute this code.
Any ideas ?

Thanks,
Eric

On Nov 16, 2010, at 7:46 AM, Gael Varoquaux wrote:

> Hey,
> 
> Sorry for the slow reply,
> 
> On Mon, Nov 15, 2010 at 11:52:41AM +0100, moscardi wrote:
>>   # Code
> 
>>   import numpy as np
> 
>>   # Define the sphere cut in two
> 
>>   xdim, ydim, zdim = 50, 50, 50
>>   vx, vy, vz = 1., 1., 1.
>>   R = 25
>>   cx = 25
>>   cy = 25
>>   cz = 25
>>   data = np.zeros([xdim, ydim, zdim],np.uint8)
>>   for i in xrange(xdim):
>>       for j in xrange(ydim):
>>           for k in xrange(zdim):
>>               if (i * vx - cx)**2 + (j * vy - cy)**2 + (k * vz - cz)**2 < (R
>>   * R) :
>>                   data[i,j,k] = 1
>>   data[:,:,24:26] = 0
> 
>>   # Using of "Tvtk segmentation example" from mayavi
>>   # to display the sphere
> 
>>   from enthought.mayavi import mlab
>>   from enthought.tvtk.api import tvtk
>>   fig = mlab.figure(bgcolor=(0, 0, 0), size=(400, 500))
>>   fig.scene.disable_render = True
>>   src = mlab.pipeline.scalar_field(data)
>>   src.update_image_data = True
>>   contour = mlab.pipeline.contour(src, )
>>   #contour.filter.contours = [1,]
>>   contour.filter.number_of_contours = 2
>>   #connect_ = tvtk.PolyDataConnectivityFilter(extraction_mode=4)
>>   connect_ = tvtk.PolyDataConnectivityFilter(extraction_mode=5)
> 
> Here is your problem: you are using the 'all_regions' extraction mode
> of the connectivity filter (check in the pipeline GUI), so you are indeed
> getting all regions not differentiated.
> 
> What you should do is select one regions, for instance using a
> 'closest_point', and create one actor for each region. I am attaching a
> modification of your script that does that.
> 
> By the way: you have forgetten to set the disable_render flag back to
> False, so the updating was a bit awkward.
> 
> HTH,
> 
> Gael
> <tmp.py>

Eric MOSCARDI
INRIA - Virtual Plants
CIRAD, Avenue Agropolis
34398 Montpellier Cedex 5, France
04 67 61 58 00 (ask number 60 09)
email : [email protected]


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
MayaVi-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mayavi-users

Reply via email to