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
##############################
# 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)
connect1_ = tvtk.PolyDataConnectivityFilter(extraction_mode=6,
closest_point=[0, 0, 30])
connect1 = mlab.pipeline.user_defined(contour, filter=connect1_)
surf1 = mlab.pipeline.surface(connect1,color=(0.9, 0.72, 0.62))
connect2_ = tvtk.PolyDataConnectivityFilter(extraction_mode=6,
closest_point=[0, 0, 10])
connect2 = mlab.pipeline.user_defined(contour, filter=connect2_)
surf2 = mlab.pipeline.surface(connect2,color=(0.62, 0.72, 0.9))
###########################################################
# Using of the "on_mouse_pick" method of the scene
# to change the color
##########################################################
def picker_callback(picker_obj):
print picker_obj.mapper_position
print 'try to change the color'
picker_obj.actor.property.color = (1,0,0)
fig.on_mouse_pick(picker_callback,type='cell')
fig.scene.disable_render = False
------------------------------------------------------------------------------
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