Hi Gael, Thanks for your response. That was very useful for me. Nevertheless, I had to change some part of my script. For begin, I created a sphere with 5 labels : 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) : if k < 10 : data[i,j,k] = 1 if 10 < k < 20 : data[i,j,k] = 2 if 20 < k < 30 : data[i,j,k] = 3 if 30 < k < 40 : data[i,j,k] = 4 if 40 < k < 50 : data[i,j,k] = 5 For the contour, I used : contour.filter.minimum_contour = 1 contour.filter.maximum_contour = 5 instead of contour.filter.number_of_contours = int(im.max()) And I noticed that : tvtk.PolyDataConnectivityFilter with extraction_mode = 5, it extracts all regions ( and not = 6 as in the VTK documentation). Then I followed your advices for the colormap, it works very well. lut = np.random.randint(256,size=(int(data.max()),4)) lut[:,3] = 255 surf.module_manager.scalar_lut_manager.lut.table = lut Now, I try to pick a region and mark it. For that, I use : picker = fig.on_mouse_pick(picker_callback,type="cell") with the callback function : def picker_callback(picker_obj): # Marking of the region, I just change the transparency for the moment (I look for a other way) cellid = data[picker_obj.mapper_position] if cellid != 0 : lut[cellid-1,3] = 50 surf.module_manager.scalar_lut_manager.lut.table =lut mlab.draw() This is okay but the precision for performing pick operation is not terrific even if I try to change the tolerance of the picker, to use the on_mouse_pick with type = "point" and "cell" But I don't see how I can do for improve that. I am attaching a the script if you have the time to run it. |
############################## # 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) : if k < 10 : data[i,j,k] = 1 if 10 < k < 20 : data[i,j,k] = 2 if 20 < k < 30 : data[i,j,k] = 3 if 30 < k < 40 : data[i,j,k] = 4 if 40 < k < 50 : data[i,j,k] = 5 ########################################################## # 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 = mlab.figure(bgcolor=(1, 1, 1), size=(400, 500)) fig = mlab.figure(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.auto_contours = True contour.filter.minimum_contour = 1 contour.filter.maximum_contour = 5 connect_ = tvtk.PolyDataConnectivityFilter(extraction_mode=5,color_regions=True) connect = mlab.pipeline.user_defined(contour, filter=connect_) surf = mlab.pipeline.surface(connect) #col = np.array([[0,0,255,255],[255,255,255,255],[255,0,0,255],[255,255,255,255],[0,0,255,255]]) col = np.random.randint(256,size=(int(data.max()),4)) col[:,3] = 255 surf.module_manager.scalar_lut_manager.lut.table = col ########################################################### # Using of the "on_mouse_pick" method of the scene # to change the color ########################################################## def picker_callback(picker_obj): print picker_obj.mapper_position cellid = data[picker_obj.mapper_position] print cellid if cellid != 0 : col[cellid-1,3] = 50 surf.module_manager.scalar_lut_manager.lut.table = col mlab.draw() def picker_return(picker_obj): print picker_obj.mapper_position cellid = data[picker_obj.mapper_position] print cellid if cellid != 0 : col[cellid-1,3] = 255 surf.module_manager.scalar_lut_manager.lut.table = col mlab.draw() picker =fig.on_mouse_pick(picker_callback,type="cell") picker =fig.on_mouse_pick(picker_return,type="cell",button="Right") fig.scene.disable_render = False
Thanks a lot. Eric On Nov 16, 2010, at 3:27 PM, Gael Varoquaux wrote:
Eric MOSCARDI
INRIA - Virtual Plants CIRAD, Avenue Agropolis 34398 Montpellier Cedex 5, France 04 67 61 58 00 (ask number 60 09) email : eric.mosca...@sophia.inria.fr |
------------------------------------------------------------------------------ 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 MayaVi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mayavi-users