def draw_nodes(self): nc = self.ds.scalar_display_settings.node_color ns = self.ds.scalar_display_settings.node_size lhn = self.nodes_lh lhn_ix = self.ds.lhnodes rhn = self.nodes_rh rhn_ix = self.ds.rhnodes for nodes, ixes in ((lhn, lhn_ix), (rhn, rhn_ix)): nr = len(ixes) #set node size if self.ds.display_mode == 'scalar' and ns: scalars = self.ds.node_scalars[ns] #for node size, the scalars need to be scaled to 0-1 scalars = (scalars - np.min(scalars)) / (np.max(scalars) - np.min(scalars)) #logarithmic scaling does a better job of differentiating large nodes scalars = (np.exp(scalars * np.log(2)) - 1) / (np.e - 1) #scalars=(4**(scalars*np.log(3)/np.log(4))-1)/3 #scalars=(4**scalars-1)/3 #scalars**=2 nodes.glyph.scale_mode = 'scale_by_vector' nodes.glyph.glyph.scale_factor = 12 nodes.mlab_source.dataset.point_data.vectors = (np.tile( scalars[ixes], (3, 1)).T) else: nodes.glyph.scale_mode = 'data_scaling_off' nodes.glyph.glyph.scale_factor = 3 #set node color -- we dont care about ds.node_colors for mayavi if (self.ds.display_mode == 'normal' or (self.ds.display_mode == 'scalar' and not nc) or (self.ds.display_mode in ['module_single', 'module_multi'] and self.ds.opts.modules_on_surface)): scalars = np.tile(.3, nr) set_lut(nodes, self.ds.opts.default_map) set_color_range(nodes, (0., 1.)) nodes.mlab_source.dataset.point_data.scalars = scalars elif self.ds.display_mode == 'scalar': #and nc must be true scalars = self.ds.node_scalars[nc] set_lut(nodes, self.ds.opts.scalar_map) set_color_range(nodes, scalars) nodes.mlab_source.dataset.point_data.scalars = scalars[ixes] elif self.ds.display_mode == 'module_single': scalars = np.tile(.3, self.ds.nr_labels) scalars[self.ds.get_module()] = .8 set_lut(nodes, self.ds.opts.default_map) set_color_range(nodes, (0., 1.)) nodes.mlab_source.dataset.point_data.scalars = scalars[ixes] elif self.ds.display_mode == 'module_multi': new_colors = np.array( self.ds.module_colors[:self.ds.nr_modules + 1]) manager = nodes.module_manager.scalar_lut_manager #set the mayavi object to the dummy cmap that we hide from user #so that when changed notifications will work correctly manager.lut_mode = 'black-white' #now adjust its LUT manually manager.number_of_colors = self.ds.nr_modules manager.lut.table = new_colors #set the mayavi scalars to be fractions between 0 and 1 import bct nodes.mlab_source.dataset.point_data.scalars = (bct.ls2ci( self.ds.modules, zeroindexed=True))[ixes] + 1 set_color_range(nodes, (0., self.ds.nr_modules + 1)) mlab.draw()
def draw_nodes(self): nc=self.ds.scalar_display_settings.node_color ns=self.ds.scalar_display_settings.node_size lhn=self.nodes_lh; lhn_ix=self.ds.lhnodes rhn=self.nodes_rh; rhn_ix=self.ds.rhnodes for nodes,ixes in ((lhn,lhn_ix),(rhn,rhn_ix)): nr=len(ixes) #set node size if self.ds.display_mode=='scalar' and ns: scalars = self.ds.node_scalars[ns] #for node size, the scalars need to be scaled to 0-1 scalars = (scalars-np.min(scalars)) / (np.max(scalars)-np.min(scalars)) #logarithmic scaling does a better job of differentiating large nodes scalars = (np.exp(scalars*np.log(2))-1)/(np.e-1) #scalars=(4**(scalars*np.log(3)/np.log(4))-1)/3 #scalars=(4**scalars-1)/3 #scalars**=2 nodes.glyph.scale_mode='scale_by_vector' nodes.glyph.glyph.scale_factor=12 nodes.mlab_source.dataset.point_data.vectors=( np.tile(scalars[ixes],(3,1)).T) else: nodes.glyph.scale_mode='data_scaling_off' nodes.glyph.glyph.scale_factor=3 #set node color -- we dont care about ds.node_colors for mayavi if (self.ds.display_mode=='normal' or (self.ds.display_mode=='scalar' and not nc) or (self.ds.display_mode in ['module_single', 'module_multi'] and self.ds.opts.modules_on_surface)): scalars = np.tile(.3, nr) set_lut(nodes, self.ds.opts.default_map) set_color_range(nodes, (0.,1.)) nodes.mlab_source.dataset.point_data.scalars = scalars elif self.ds.display_mode=='scalar': #and nc must be true scalars = self.ds.node_scalars[nc] set_lut(nodes, self.ds.opts.scalar_map) set_color_range(nodes, scalars) nodes.mlab_source.dataset.point_data.scalars = scalars[ixes] elif self.ds.display_mode=='module_single': scalars = np.tile(.3, self.ds.nr_labels) scalars[self.ds.get_module()]=.8 set_lut(nodes, self.ds.opts.default_map) set_color_range(nodes, (0.,1.)) nodes.mlab_source.dataset.point_data.scalars = scalars[ixes] elif self.ds.display_mode=='module_multi': new_colors=np.array(self.ds.module_colors[ :self.ds.nr_modules+1]) manager=nodes.module_manager.scalar_lut_manager #set the mayavi object to the dummy cmap that we hide from user #so that when changed notifications will work correctly manager.lut_mode='black-white' #now adjust its LUT manually manager.number_of_colors=self.ds.nr_modules manager.lut.table=new_colors #set the mayavi scalars to be fractions between 0 and 1 import bct nodes.mlab_source.dataset.point_data.scalars=(bct.ls2ci( self.ds.modules,zeroindexed=True))[ixes]+1 set_color_range(nodes, (0., self.ds.nr_modules+1)) mlab.draw()
def draw_surfs(self): from parsing_utils import demangle_hemi srf_scalar = self.ds.scalar_display_settings.surf_color nc = self.ds.scalar_display_settings.node_color if (self.ds.display_mode == 'scalar' and srf_scalar): scalars = self.ds.node_scalars[srf_scalar] colors_lh = np.zeros((len(self.ds.srf.lh_verts)), ) colors_rh = np.zeros((len(self.ds.srf.rh_verts)), ) for i, l in enumerate(self.ds.labnam): #assumes that lh labels start with L and so on vertices = self.ds.labv[demangle_hemi(l)] if l[0] == 'l': colors_lh[vertices] = scalars[i] elif l[0] == 'r': colors_rh[vertices] = scalars[i] self.syrf_lh.mlab_source.scalars = colors_lh self.syrf_rh.mlab_source.scalars = colors_rh for syrf in (self.syrf_lh, self.syrf_rh): set_lut(syrf, self.ds.opts.scalar_map) set_color_range(syrf, scalars) syrf.actor.mapper.scalar_visibility = True #we don't need to set the scalars properly, but lets set the scalar range #of the surface properly so that a colorbar will capture it elif (self.ds.display_mode == 'scalar' and nc): scalars = self.ds.node_scalars[nc] #the scalar colorbar refers to syrf_lh only min_scale, max_scale = np.min(scalars), np.max(scalars) colors = np.tile(min_scale, (len(self.ds.srf.lh_verts), )) colors[0] = max_scale self.syrf_lh.mlab_source.scalars = colors for syrf in (self.syrf_lh, self.syrf_rh): syrf.actor.mapper.scalar_visibility = False elif (self.ds.display_mode == 'module_multi' and self.ds.opts.modules_on_surface): new_colors = np.array(self.ds.module_colors[:self.ds.nr_modules + 1]) for syrf, nodes, letter, verts in ((self.syrf_lh, self.ds.lhnodes, 'l', self.ds.srf.lh_verts), (self.syrf_rh, self.ds.rhnodes, 'r', self.ds.srf.rh_verts)): colors = np.zeros((len(verts)), ) manager = syrf.module_manager.scalar_lut_manager #set the mayavi object to the dummy cmap #so that when changed notifications will work correctly manager.lut_mode = 'black-white' #now adjust its LUT manually manager.number_of_colors = self.ds.nr_modules manager.lut.table = new_colors import bct ci = bct.ls2ci(self.ds.modules, zeroindexed=True)[nodes] i = 0 for l in self.ds.labnam: #assumes that lh labels start with L and so on if not l[0] == letter: continue vertices = self.ds.labv[demangle_hemi(l)] colors[vertices] = ci[i] + 1 i += 1 syrf.mlab_source.scalars = colors set_color_range(syrf, (0., self.ds.nr_modules + 1)) syrf.actor.mapper.scalar_visibility = True else: for syrf in (self.syrf_lh, self.syrf_rh): syrf.actor.mapper.scalar_visibility = False
def draw_surfs(self): from parsing_utils import demangle_hemi srf_scalar=self.ds.scalar_display_settings.surf_color nc = self.ds.scalar_display_settings.node_color if (self.ds.display_mode=='scalar' and srf_scalar): scalars = self.ds.node_scalars[srf_scalar] colors_lh=np.zeros((len(self.ds.srf.lh_verts)),) colors_rh=np.zeros((len(self.ds.srf.rh_verts)),) for i,l in enumerate(self.ds.labnam): #assumes that lh labels start with L and so on vertices=self.ds.labv[demangle_hemi(l)] if l[0]=='l': colors_lh[vertices] = scalars[i] elif l[0]=='r': colors_rh[vertices] = scalars[i] self.syrf_lh.mlab_source.scalars=colors_lh self.syrf_rh.mlab_source.scalars=colors_rh for syrf in (self.syrf_lh,self.syrf_rh): set_lut(syrf,self.ds.opts.scalar_map) set_color_range(syrf, scalars) syrf.actor.mapper.scalar_visibility=True #we don't need to set the scalars properly, but lets set the scalar range #of the surface properly so that a colorbar will capture it elif (self.ds.display_mode=='scalar' and nc): scalars = self.ds.node_scalars[nc] #the scalar colorbar refers to syrf_lh only min_scale, max_scale = np.min(scalars), np.max(scalars) colors = np.tile(min_scale, (len(self.ds.srf.lh_verts),)) colors[0] = max_scale self.syrf_lh.mlab_source.scalars = colors for syrf in (self.syrf_lh,self.syrf_rh): syrf.actor.mapper.scalar_visibility=False elif (self.ds.display_mode=='module_multi' and self.ds.opts.modules_on_surface): new_colors=np.array(self.ds.module_colors[:self.ds.nr_modules+1]) for syrf,nodes,letter,verts in ( (self.syrf_lh,self.ds.lhnodes,'l',self.ds.srf.lh_verts), (self.syrf_rh,self.ds.rhnodes,'r',self.ds.srf.rh_verts)): colors=np.zeros((len(verts)),) manager=syrf.module_manager.scalar_lut_manager #set the mayavi object to the dummy cmap #so that when changed notifications will work correctly manager.lut_mode='black-white' #now adjust its LUT manually manager.number_of_colors=self.ds.nr_modules manager.lut.table=new_colors import bct ci = bct.ls2ci(self.ds.modules,zeroindexed=True)[nodes] i = 0 for l in self.ds.labnam: #assumes that lh labels start with L and so on if not l[0]==letter: continue vertices=self.ds.labv[demangle_hemi(l)] colors[vertices] = ci[i]+1 i+=1 syrf.mlab_source.scalars = colors set_color_range(syrf, (0., self.ds.nr_modules+1)) syrf.actor.mapper.scalar_visibility=True else: for syrf in (self.syrf_lh,self.syrf_rh): syrf.actor.mapper.scalar_visibility=False