Esempio n. 1
0
	def __init__(self, parent = None):
	
		QtGui.QMainWindow.__init__(self, parent)
		self.ui = Ui_MainWindow()
		self.ui.setupUi(self)
		
		self.WordleView = vtkvtg.vtkQtWordleDebugView()
		
		# Set widget for the wordle view
		self.ui.centralWidget.layout().addWidget(self.WordleView.GetWidget())
		
		data_dir = '/Users/emonson/Data/Fodava/EMoGWDataSets/'
		data_file = data_dir + 'sciNews_20110216.mat'
			
		print 'Trying to load data set from .mat file...'

		try:
			MatInput = scipy.io.loadmat(data_file, struct_as_record=True, chars_as_strings=True)
		except:
			raise IOError, "Can't load supplied matlab file"
		
		self.mat_terms = MatInput['terms'].T[0]
		
		self.WavBases = []	# Wavelet bases
		self.Centers = [] # Center of each node
		# NodeWavCoeffs = []
		# NodeScalCoeffs = []
		for ii in range(MatInput['PointsInNet'].shape[1]):
			self.WavBases.append(N.mat(MatInput['WavBases'][0,ii]))			# matrix
			self.Centers.append(N.mat(MatInput['Centers'][0,ii][0]))		# matrix

		terms = vtk.vtkStringArray()
		terms.SetName('dictionary')
		terms.SetNumberOfComponents(1)
		for term in self.mat_terms:
			terms.InsertNextValue(term[0])
		
		self.basis_idx = 0
		
		coeffs = VN.numpy_to_vtk(self.WavBases[self.basis_idx][::-1,0]*100, deep=True)
		coeffs.SetName('coefficient')
		c_sign = VN.numpy_to_vtk(N.sign(self.WavBases[self.basis_idx][::-1,0]), deep=True)
		c_sign.SetName('sign')
		
		# Create a table with some points in it...
		self.table = vtk.vtkTable()
		self.table.AddColumn(terms)
		self.table.AddColumn(coeffs)
		self.table.AddColumn(c_sign)
		
		vt = vtk.vtkViewTheme()
		lut = vtk.vtkLookupTable()
		lut.SetHueRange(0, 0.66)
		lut.SetValueRange(0.7, 0.7)
		lut.SetSaturationRange(1, 1)
		lut.Build()
		# Set value for no color by array
		vt.SetPointColor(0,0,0)
		# Set LUT for color by array
		vt.SetPointLookupTable(lut)
		# ViewTheme Background color is black by default
		vt.SetBackgroundColor(1,1,1)

		self.WordleView.AddRepresentationFromInput(self.table)
		self.WordleView.SetFieldType(vtkvtg.vtkQtWordleView.ROW_DATA)
		self.WordleView.SetColorByArray(True)
		self.WordleView.SetColorArrayName('sign')
		self.WordleView.SetTermsArrayName('dictionary')
		self.WordleView.SetSizeArrayName('coefficient')
		self.WordleView.ApplyViewTheme(vt)
		self.WordleView.SetMaxNumberOfWords(150);
		self.WordleView.SetFontFamily("Rockwell")
		self.WordleView.SetFontStyle(vtkvtg.vtkQtWordleView.StyleNormal)
		self.WordleView.SetFontWeight(99)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.HORIZONTAL)
		self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.MOSTLY_HORIZONTAL)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.HALF_AND_HALF)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.MOSTLY_VERTICAL)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.VERTICAL)

		self.WordleView.SetLayoutPathShape(vtkvtg.vtkQtWordleView.CIRCULAR_PATH)
		# self.WordleView.SetLayoutPathShape(vtkvtg.vtkQtWordleView.SQUARE_PATH)

		QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.fileExit)

		# Do first update before changing to debug mode...
		self.WordleView.Update()
		self.WordleView.ZoomToBounds()
		
# 		while(True):
# 			self.table.Modified()
# 			self.WordleView.Update()
				
		# DEBUG
		self.WordleView.SetWatchLayout(True)
		self.WordleView.SetWatchCollision(True)
		self.WordleView.SetWatchQuadTree(True)
		self.WordleView.SetWatchDelay(50000)
Esempio n. 2
0
	def __init__(self, parent = None):
	
		QtGui.QMainWindow.__init__(self, parent)
		self.ui = Ui_MainWindow()
		self.ui.setupUi(self)
		
		self.WordleView = vtkvtg.vtkQtWordleDebugView()
		
		# Set widget for the wordle view
		self.ui.centralWidget.layout().addWidget(self.WordleView.GetWidget(),0,1)
		
		term_list = [
			"straw",
			"gold",
			"name",
			"miller",
			"manikin",
			"daughter",
			"little",
			"queen",
			"man",
			"came",
			"girl",
			"give",
			"spin",
			"full",
			"whirr",
			"spun",
			"night",
			"one",
			"child",
			"king",
			"room",
			"answered",
			"morning",
			"names",
			"took",
			"began",
			"thought",
			"time",
			"find",
			"world",
			"day",
			"leg",
			"whole",
			"another",
			"three",
			"rumpelstiltskin",
			"knew",
			"left",
			"help",
			"still",
			"crying",
			"gave",
			"good",
			"round",
			"wheel",
			"second",
			"opened",
			"messenger",
			"ever",
			"told",
			"quite",
			"alone",
			"mistress",
			"larger",
			"became",
			"first",
			"brought",
			"put",
			"ring",
			"devil",
			"next",
			"house",
			"taken",
			"life",
			"door",
			"fire",
			"reel",
			"glad",
			"must",
			"beautiful",
			"heard",
			"promised",
			"saw",
			"perhaps",
			"also",
			"poor",
			"shall",
			"third",
			"wife",
			"necklace",
			"bring",
			"daybreak",
			"earth",
			"hopped",
			"inquiries",
			"cried",
			"dearer",
			"front",
			"far",
			"bid",
			"early",
			"every",
			"hands",
			"foot",
			"course",
			"always",
			"cry",
			"become",
			"conrad",
			"art",
			"hare",
			"hard",
			"back",
			"alive",
			"die",
			"curious",
			"bake",
			"even",
			"appear",
			"fox",
			"enough",
			"finger",
			"harry",
			"caspar",
			"greedy",
			"found",
			"country",
			"days",
			"asked",
			"already",
			"afterwards",
			"burning",
			"imagine",
			"delighted",
			"frightened",
			"appeared",
			"idea",
			"clever",
			"else",
			"alas",
			"astonished",
			"grew",
			"happened",
			"heart",
			"deep",
			"high",
			"evening",
			"anger",
			"commanded",
			"happen",
			"beyond",
			"end",
			"able",
			"forest",
			"jumping",
			"brew",
			"important",
			"balthazar",
			"inquire",
			"glittering"
			]

		size_list = [
			12.0,
			10.0,
			10.0,
			9.0,
			9.0,
			9.0,
			9.0,
			8.0,
			8.0,
			8.0,
			7.0,
			7.0,
			6.0,
			6.0,
			6.0,
			5.0,
			5.0,
			5.0,
			5.0,
			5.0,
			5.0,
			4.0,
			4.0,
			4.0,
			4.0,
			4.0,
			4.0,
			4.0,
			3.0,
			3.0,
			3.0,
			3.0,
			3.0,
			3.0,
			3.0,
			3.0,
			3.0,
			3.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			2.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			1.0,
			]

		terms = vtk.vtkStringArray()
		terms.SetName('dictionary')
		terms.SetNumberOfComponents(1)
		for term in term_list:
			terms.InsertNextValue(term)
		
		coeffs = vtk.vtkDoubleArray()
		coeffs.SetName('coefficient')
		coeffs.SetNumberOfComponents(1)
		for size in size_list:
			coeffs.InsertNextValue(size)
		
		coeffs2 = vtk.vtkDoubleArray()
		coeffs2.SetName('neg_coeff')
		coeffs2.SetNumberOfComponents(1)
		for size in size_list:
			coeffs2.InsertNextValue(N.sqrt(size))
		
		# Create a table with some points in it...
		self.table = vtk.vtkTable()
		self.table.AddColumn(terms)
		self.table.AddColumn(coeffs)
		self.table.AddColumn(coeffs2)
		
		self.vt = vtk.vtkViewTheme()
		lut = vtk.vtkLookupTable()
		lut.SetHueRange(0,0)
		lut.SetValueRange(0,1)
		lut.SetSaturationRange(1,1)
		lut.Build()
		# Set value for no color by array
		self.vt.SetPointColor(0,0,0)
		# Set LUT for color by array
		self.vt.SetPointLookupTable(lut)
		# ViewTheme Background color is black by default
		self.vt.SetBackgroundColor(1,1,1)

		self.vt2 = vtk.vtkViewTheme()
		lut2 = vtk.vtkLookupTable()
		lut2.SetHueRange(0, 0.66)
		lut2.SetValueRange(0.7, 0.7)
		lut2.SetSaturationRange(1, 1)
		lut2.Build()
		# Set value for no color by array
		self.vt2.SetPointColor(0,0,0)
		# Set LUT for color by array
		self.vt2.SetPointLookupTable(lut2)
		# ViewTheme Background color is black by default
		self.vt2.SetBackgroundColor(1,1,1)

		self.ui.doubleSpinBox_xbuffer.setValue(self.WordleView.Getxbuffer())
		self.ui.doubleSpinBox_ybuffer.setValue(self.WordleView.Getybuffer())
		self.ui.doubleSpinBox_randSpread.setValue(self.WordleView.GetrandSpread())
		self.ui.doubleSpinBox_thetaMult.setValue(self.WordleView.GetthetaMult())
		self.ui.doubleSpinBox_thetaPow.setValue(self.WordleView.GetthetaPow())
		self.ui.doubleSpinBox_rMult.setValue(self.WordleView.GetrMult())
		self.ui.doubleSpinBox_rPow.setValue(self.WordleView.GetrPow())
		self.ui.doubleSpinBox_dMult.setValue(self.WordleView.GetdMult())
		self.ui.doubleSpinBox_dPow.setValue(self.WordleView.GetdPow())
		self.ui.doubleSpinBox_wordSizePower.setValue(self.WordleView.GetWordSizePower())
		self.ui.comboBox_pathShape.setCurrentIndex(self.WordleView.GetLayoutPathShape())
		self.ui.comboBox_orientation.setCurrentIndex(self.WordleView.GetOrientation())

		self.WordleView.AddRepresentationFromInput(self.table)
		self.WordleView.SetFieldType(vtkvtg.vtkQtWordleView.ROW_DATA)
		self.WordleView.SetColorByArray(True)
		self.WordleView.SetColorArrayName('coefficient')
		self.WordleView.SetTermsArrayName('dictionary')
		self.WordleView.SetSizeArrayName('coefficient')
		self.WordleView.SetOutputImageDataDimensions(200, 200)
		self.WordleView.ApplyViewTheme(self.vt)
		self.WordleView.SetMaxNumberOfWords(150);
		self.WordleView.SetFontFamily("Rockwell")
		self.WordleView.SetFontStyle(vtkvtg.vtkQtWordleView.StyleNormal)
		self.WordleView.SetFontWeight(99)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.HORIZONTAL)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.MOSTLY_HORIZONTAL)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.HALF_AND_HALF)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.MOSTLY_VERTICAL)
		# self.WordleView.SetOrientation(vtkvtg.vtkQtWordleView.VERTICAL)

		QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL("triggered()"), self.fileExit)

		self.WordleView.Update()
		self.WordleView.ZoomToBounds()
		
# 		fams = vtk.vtkStringArray()
# 		self.WordleView.GetAllFontFamilies(fams)
# 		for ii in range(fams.GetNumberOfValues()):
# 			print fams.GetValue(ii)
				
		# DEBUG
# 		self.WordleView.SetWatchLayout(True)
# 		self.WordleView.SetWatchCollision(True)
# 		self.WordleView.SetWatchQuadTree(True)
# 		self.WordleView.SetWatchDelay(50000)
		self.color_by_array = True
		self.font_flag = True