Exemplo n.º 1
0
	def PedIdToIndexSelection(self):

		# Get pedigree ids from current output_link selection
		pedIdSel = self.output_link.GetCurrentSelection()
		cs = vtk.vtkConvertSelection()
		idxSel = cs.ToIndexSelection(pedIdSel, self.table)

		# Trying to disable event invocation while chaging this selection
		self.link.RemoveObservers("AnnotationChangedEvent")
		self.link.SetCurrentSelection(idxSel)
		self.link.AddObserver("AnnotationChangedEvent", self.PCoordsSelectionCallback)

		# Now do the same for the highlight_link_idxs selection
		pedIdSel = self.highlight_link.GetCurrentSelection()
		cs = vtk.vtkConvertSelection()
		idxSel = cs.ToIndexSelection(pedIdSel, self.table)
		if idxSel.GetNumberOfNodes() > 0:
			idxVtk = idxSel.GetNode(0).GetSelectionList()
			if idxVtk.GetNumberOfTuples() > 0:
				print "PC highlight_link_idxs indices: ", VN.vtk_to_numpy(idxVtk)
			else:
				print "PC highlight_link_idxs NO TUPLES"
		else:
			print "PC highlight_link_idxs NO NODES"
		self.highlight_link_idxs.SetCurrentSelection(idxSel)
Exemplo n.º 2
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkConvertSelection(), 'Processing.',
         ('vtkSelection', 'vtkDataObject'), ('vtkSelection',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Exemplo n.º 3
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkConvertSelection(),
                                       'Processing.',
                                       ('vtkSelection', 'vtkDataObject'),
                                       ('vtkSelection', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
	def ScaleSelectionCallback(self, caller, event):
		# This will contain a scale value from detail_image_flow, which should
		# only exist if there is also a highlight_selection from image_flow.
		# Here combine those two pieces of information to select the correct tree
		# node corresponding to that pedigree_id highlight and scale value
		
		# This call doesn't make sense if there isn't a highlight link
		# since it follows that highlighted individual to the selected scale
		if self.highlight_link is None:
			return
		
		# Don't want to update if this is an internal call
		if self.scale_internal_call:
			self.scale_internal_call = False
			return
		
		# The content type is Index for now...
		scaleSel = caller.GetCurrentSelection()
		
		# Note: Empty selection should still contain a node, but no tuples
		if (scaleSel.GetNumberOfNodes() > 0) and (scaleSel.GetNode(0).GetSelectionList().GetNumberOfTuples() > 0):
			# This should only contain a single value or none
			scaleVal = scaleSel.GetNode(0).GetSelectionList().GetValue(0)
			print "Scale value from detail to icicle: ", scaleVal
			
			# Highlight should also contain a single pedigree id...
			pedSel = self.highlight_link.GetCurrentSelection()
			pedIdVal = pedSel.GetNode(0).GetSelectionList().GetValue(0)
			print "Pedigree ID value right now in icicle highlight", pedIdVal
			
			# NOTE: Accessing member variable
			nodes_at_scale = N.nonzero(self.ds.Scales==scaleVal)[0].tolist()
			
			for node_id in nodes_at_scale:
				if (self.ds.PointsInNet[node_id]==pedIdVal).any():
					
					# Assuming for now that this is a cell "Index", so getting pedigree ID
					sel = vtk.vtkSelection()
					node = vtk.vtkSelectionNode()
					node.SetFieldType(0)		# Cell
					node.SetContentType(4)		# Indices
					id_array = N.array([node_id], dtype='int64')
					id_vtk = VN.numpy_to_vtkIdTypeArray(id_array, deep=True)
					node.SetSelectionList(id_vtk)
					sel.AddNode(node)
					# Note: When selection is cleared, the current selection does NOT contain any nodes
					self.areapoly1.Update()
					cs = vtk.vtkConvertSelection()
					pedIdSelection = cs.ToPedigreeIdSelection(sel, self.areapoly1.GetOutput())
					pedIdSelection.GetNode(0).SetFieldType(3)	# convert to vertext selection
					
					# Copy converted selection to output annotation link (fires AnnotationChangedEvent)
					self.output_link.SetCurrentSelection(pedIdSelection)
					self.applycolors1.Update()
					self.renWin.Render()
Exemplo n.º 5
0
	def HighlightSelectionCallback(self, caller, event):
		# Need to convert pedigree IDs that we get back from image_flow into indices
		annSel = caller.GetCurrentSelection()
		# Note: When selection is cleared, the current selection does NOT contain any nodes
		if annSel.GetNumberOfNodes() > 0:
			idxVtk = annSel.GetNode(0).GetSelectionList()
			if idxVtk.GetNumberOfTuples() > 0:
				cs = vtk.vtkConvertSelection()
				idxSelection = cs.ToIndexSelection(annSel, self.table)
				# Copy converted selection to output annotation link (fires AnnotationChangedEvent)
				self.highlight_link_idxs.SetCurrentSelection(idxSelection)
			else:
				empty_arr = N.array([],dtype='int64')
				empty_vtk = VN.numpy_to_vtkIdTypeArray(empty_arr, deep=True)
				self.highlight_link_idxs.GetCurrentSelection().GetNode(0).SetSelectionList(empty_vtk)

		self.chartView.Render()
Exemplo n.º 6
0
	def PedIdToIndexSelection(self):

		# Convert pedigree id highlight_link to highlight_link_idxs selection
		# (Don't have to do this with output_link & link right now because this chart
		#  is sharing the internal index link with the pcoords_chart which is doing the calc.
		#  In principle could just share the same highlight_link_idxs, too and not have to do
		#  this...)
		pedIdSel = self.highlight_link.GetCurrentSelection()
		cs = vtk.vtkConvertSelection()
		idxSel = cs.ToIndexSelection(pedIdSel, self.table)
		if idxSel.GetNumberOfNodes() > 0:
			idxVtk = idxSel.GetNode(0).GetSelectionList()
			if idxVtk.GetNumberOfTuples() > 0:
				print "XY highlight_link_idxs indices: ", VN.vtk_to_numpy(idxVtk)
			else:
				print "XY highlight_link_idxs NO TUPLES"
		else:
			print "XY highlight_link_idxs NO NODES"
		self.highlight_link_idxs.SetCurrentSelection(idxSel)
Exemplo n.º 7
0
	def PCoordsSelectionCallback(self, caller, event):
		# Defined for testing ID picking
		annSel = caller.GetCurrentSelection()
		# Note: When selection is cleared, the current selection does NOT contain any nodes
		cs = vtk.vtkConvertSelection()
		pedIdSelection = cs.ToPedigreeIdSelection(annSel, self.table)

		# Copy converted selection to output annotation link (fires AnnotationChangedEvent)
		self.output_link.SetCurrentSelection(pedIdSelection)

		# Test conversion by printing
		if pedIdSelection.GetNumberOfNodes() > 0:
			idxVtk = pedIdSelection.GetNode(0).GetSelectionList()
			if idxVtk.GetNumberOfTuples() > 0:
				print "PC ped ids: ", VN.vtk_to_numpy(idxVtk)
		else:
			print "PC empty selection"

		self.view.Render()
	def selectNode(self):
		# (x0,y0) = self.interactor.GetLastEventPosition()
		(x,y) = self.interactor.GetEventPosition()
		cellPicker = vtk.vtkCellPicker()
		someCellPicked = cellPicker.Pick(x,y,0,self.renderer)
		pickedCellId = cellPicker.GetCellId()
		propPicker = vtk.vtkPropPicker()
		somePropPicked = propPicker.PickProp(x,y,self.renderer)
		pickedProp = propPicker.GetViewProp()
		navigated = False
		# NOTE: For some reason, sometimes on switching data sets
		#   we're getting to the print statement with scale_list undefined
		#   so I added this initialization...
		scale_list = []
		
		# Navigate with buttons
		if somePropPicked and (pickedProp != self.icicle_actor):
			# First, test whether there is a current selection because we can only move if
			# there was a selection to move in the first place
			if self.output_link.GetCurrentSelection().GetNumberOfNodes() > 0:
				# If so, get the current pedigree_id
				prev_ped_vtk = self.output_link.GetCurrentSelection().GetNode(0).GetSelectionList()
				# NOTE: Counting on a single ID
				prev_ped_id = prev_ped_vtk.GetValue(0)
				# Now figure out which menu item was picked
				for ii, m_actor in enumerate(self.menu.GetActorList()):
					if pickedProp == m_actor:
						# print "Menu Actor picked, index = ", ii
						# Call the proper nav routine and get back the new ped_id
						new_ped_id = self.menu_functions[ii](prev_ped_id)
						new_ped_n = N.array([new_ped_id], dtype='int64')
						new_ped_vtk = VN.numpy_to_vtkIdTypeArray(new_ped_n, deep=True)
						self.output_link.GetCurrentSelection().GetNode(0).SetSelectionList(new_ped_vtk)
						self.output_link.InvokeEvent("AnnotationChangedEvent")
						self.applycolors1.Update()
						self.renWin.Render()			
						# Set list for scale_link
						scale_list = [self.ds.Scales[new_ped_id]]
						navigated = True
					
		# Pick a cell of the icicle view
		# Cell picker doesn't work with Actor2D, so nav menu won't report any cells
		if someCellPicked and not navigated:
			print "Icicle picked cell index: ", pickedCellId
			# Assuming for now that this is a cell "Index", so getting pedigree ID
			sel = vtk.vtkSelection()
			node = vtk.vtkSelectionNode()
			node.SetFieldType(0)		# Cell
			node.SetContentType(4)		# Indices
			id_array = N.array([pickedCellId], dtype='int64')
			id_vtk = VN.numpy_to_vtkIdTypeArray(id_array, deep=True)
			node.SetSelectionList(id_vtk)
			sel.AddNode(node)
			# Note: When selection is cleared, the current selection does NOT contain any nodes
			self.areapoly1.Update()
			cs = vtk.vtkConvertSelection()
			pedIdSelection = cs.ToPedigreeIdSelection(sel, self.areapoly1.GetOutput())
			pedIdSelection.GetNode(0).SetFieldType(3)	# convert to vertext selection
			
			# Copy converted selection to output annotation link (fires AnnotationChangedEvent)
			self.output_link.SetCurrentSelection(pedIdSelection)
			self.applycolors1.Update()
			self.renWin.Render()
			# Set list for scale_link
			scale_list = [self.ds.Scales[pickedCellId]]
			
		if not someCellPicked and not somePropPicked:
			# reset selection to blank
			print "Blank selection"
			return
			self.output_link.GetCurrentSelection().RemoveAllNodes()
			self.output_link.InvokeEvent("AnnotationChangedEvent")
			self.applycolors1.Update()
			self.renWin.Render()
			# Set list for scale_link
			scale_list = []

		print "scale picked in icicle view: ", scale_list
		
		id_array = N.array(scale_list, dtype='int64')
		id_vtk = VN.numpy_to_vtkIdTypeArray(id_array, deep=True)
		self.scale_link.GetCurrentSelection().GetNode(0).SetSelectionList(id_vtk)
		# For now want this event to trigger detail view, but not internal scale selection callback
		self.scale_internal_call = True
		self.scale_link.InvokeEvent("AnnotationChangedEvent")
Exemplo n.º 9
0
def selectionChangedCallback(caller,eventId):
	x,y = istyle.GetInteractor().GetEventPosition()
	z = 0
	ren1.SetDisplayPoint(x,y,0)
	ren1.DisplayToWorld()
	# print (x,y)
	# print ren1.GetWorldPoint()
	
	picker.Pick(x,y,0,ren1)
	print picker.GetCellId()
	
	# List of offsets for creating frustrum corners from point
	o = []			# offsets
	t = 1.0			# amount
	o.append((-1*t,-1*t,-1.0))
	o.append([-1*t,-1*t,+1.0])
	o.append([-1*t,+1*t,-1.0])
	o.append([-1*t,+1*t,+1.0])
	o.append((+1*t,-1*t,-1.0))
	o.append([+1*t,-1*t,+1.0])
	o.append([+1*t,+1*t,-1.0])
	o.append([+1*t,+1*t,+1.0])
	
	frustcorners = vtk.vtkDoubleArray()
	frustcorners.SetNumberOfComponents(4)
	frustcorners.SetNumberOfTuples(8)
	
	for ii in range(8):
		ren1.SetDisplayPoint(x+o[ii][0],y+o[ii][1],z+o[ii][2])
		ren1.DisplayToWorld()
		(m,n,l,w) = ren1.GetWorldPoint()
		frustcorners.SetTuple4(ii,m,n,l,w)
	
	# Enumerator:	(content type)
		# SELECTIONS	
		# GLOBALIDS		
		# PEDIGREEIDS	
		# VALUES	
		# INDICES	
		# FRUSTUM	
		# LOCATIONS		
		# THRESHOLDS	
		# BLOCKS 
	# Enumerator: (field type)
		# CELL	
		# POINT		
		# FIELD		
		# VERTEX	
		# EDGE	
		# ROW	
		
	sel = vtk.vtkSelection()
	node = vtk.vtkSelectionNode()
	node.SetContentType(5)		# FRUSTRUM
	node.SetFieldType(0)		# CELL
	node.SetSelectionList(frustcorners)
	sel.AddNode(node);
	sel.Update()
	print 'Node prop:', node.GetSelectedProp()
	
	cs = vtk.vtkConvertSelection()
	outSel = cs.ToIndexSelection(sel, texPlane.GetOutput())	# INDICES
	outNode = outSel.GetNode(0)
	print 'Number of Tuples in outSelNode0: ', outNode.GetSelectionList().GetNumberOfTuples()
	print 'Tuple0: ', outNode.GetSelectionList().GetValue(0)
	
	cs2 = vtk.vtkConvertSelection()
	outSel2 = cs.ToPedigreeIdSelection(sel, texPlane.GetOutput())	# INDICES
	outNode2 = outSel.GetNode(0)
	print 'Number of Tuples in outSelNode0: ', outNode2.GetSelectionList().GetNumberOfTuples()
	print 'Tuple0: ', outNode2.GetSelectionList().GetValue(0)
	print 'Prop: ', outNode2.GetProperties().Get(outNode2.PROP())
	print 'Prop: ', outNode2.GetSelectedProp(), '\n'