def add_cortical_surf(self): # lifted from Gael Varoquax # this is fairly brittle-- don't know what will result if # the brain is not skull-stripped # brain_image is (currently) a copy of the integer indices # (not the "real valued" scalars) brain_image = self.master_src.blender.main.image_arr.copy() np.putmask(brain_image, brain_image>255, 0) # since this is skull stripped from BET, the boundary will be # wherever the image drops off to 0 arr = ndimage.gaussian_filter( (brain_image > 0).astype('d'), 6 ) mask = ndimage.binary_fill_holes(arr > .5) # iterations x voxel size ~= erosion depth?? mask = ndimage.binary_erosion(mask, iterations=5) arr_blurred = ndimage.gaussian_filter( mask.astype('d'), 2 ) # This AA filter will rather dangle off the pipeline.. # it will be the "source" of the ProbeFilter, but we want # to keep it pipeline-enabled so that we can dynamically # change colors point_scalars = surf_to_component[self.surface_component] surf_colors = mlab.pipeline.set_active_attribute( self.master_src, point_scalars=point_scalars ) # Now, make a new ArraySource with the attributes copied # from master_src anat_blurred = ArraySource(transpose_input_array=False) anat_blurred.scalar_data = arr_blurred anat_blurred.scalar_name = 'blurred' anat_blurred.origin = self.master_src.data.origin anat_blurred.spacing = self.master_src.data.spacing anat_blurred = mlab.pipeline.add_dataset(anat_blurred) ## anat_blurred.update_pipeline() contour = mlab.pipeline.contour(anat_blurred) decimated = mlab.pipeline.decimate_pro(contour) extracted = mlab.pipeline.user_defined( decimated, filter=self.poly_extractor ) sampler = tvtk.ProbeFilter() sampler.source = surf_colors.outputs[0] surf_points = mlab.pipeline.user_defined(extracted, filter=sampler) self.cortical_surf = mlab.pipeline.surface( surf_points, opacity=.95 ) self.cortical_surf.actor.property.backface_culling = True self.bcontour = contour self.surf_colors = surf_colors