472,378 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

I am back for help:-)

Hi folks:

I have figured out how to sacle glyph by one scalar array, and color by another scalar array. but when I want to change color by third scalar array, I met some problems. At the beginning, I color the glyph by sex, and then I want to color by occupation. I thought I just need to the following code in order to change color. However, if I click occupation radiobutton, color can be changed according to the data given. but I can not change back by clicking sex radiobutton.(ie glyph still color by occupation once I click any radiobuttons)
def ColorGroup():
if v==1:

myMapper.ColorByArrayComponent("data", 2)
myMapper.SetScalarRange(0,maxSnum)
win.Render()

else:

myMapper.ColorByArrayComponent("data", 8)
myMapper.SetScalarRange(0,maxOccu)
win.Render()

Can anone tell me where I am wrong??Thanks:-)

The following is my whole code and data file, Can you play with this to find where I am wrong?
8 0 1 21 0 5.1 35 2 6 1 1
9 1 1 42 1 4.95 57 3 0 1 1
12 0 0 1 0 6.67 19 3 2 1 0
12 0 0 4 0 4 22 3 3 0 0
12 0 0 17 0 7.5 35 2 6 0 1
13 0 0 9 1 13.07 28 3 0 0 0
10 1 0 27 0 4.45 43 3 6 0 0
12 0 0 9 0 19.47 27 2 5 0 0
16 0 0 11 0 13.28 33 3 6 1 1
12 0 1 9 1 8.75 27 3 0 0 0

title='visualization of wage'
# -*- coding: cp1252 -*-
import tkFont
from vtk import *
from vtk.tk.vtkTkRenderWindowInteractor import *
from Tkinter import *

def RawDataExample():
""" Creates 2D data inside a vtkTkRenderWindowInteractor. """

def ColorGroup():
if v==1:

myMapper.ColorByArrayComponent("data", 2)
myMapper.SetScalarRange(0,maxSnum)
win.Render()

else:

myMapper.ColorByArrayComponent("data", 8)
myMapper.SetScalarRange(0,maxOccu)
win.Render()

# create root window
root = Tk()
root.title("Information Visualization of Wage")
f=Frame(root)
f.pack()

heading=Label(f,text="Create a Visualization Tool to analyse large datasets",font=tkFont.Font ( family="Helvetica",
size=20, weight="bold") )
heading.pack()

colorGroup=Frame(root,relief="sunken",border=1)
colorGroup.pack(side="right")

lblColor=Label(colorGroup,relief="groove", text="Group by Colour",font=tkFont.Font ( family="New",
size=12))
lblColor.pack()

v=IntVar()
radSex=Radiobutton(colorGroup,width=10,text="Sex", anchor=W,variable=v,value=1,command=ColorGroup)
radOccupation=Radiobutton(colorGroup,width=10,text ="Occupation",anchor=W,variable=v,value=6,command= ColorGroup)
v.set(1)

radSex.pack()
radOccupation.pack()

quit=Button(root,text="Exit",command=root.destroy, font=tkFont.Font ( family="Helvetica",
size=12, weight="bold"),cursor="heart")
quit.pack(side="bottom")

#set up a structured points and two arrays to hold sets of data
myGrid=vtkPolyData()
myPoint=vtkPoints()

## create 11 arrays for 11 variables
EducationArray = vtkIntArray()
EducationArray.SetName("education")
SouthArray = vtkIntArray()
SouthArray.SetName("south")
SexArray=vtkIntArray()
SexArray.SetName("sex")
ExperienceArray=vtkIntArray()
ExperienceArray.SetName("experience")
UnionArray=vtkIntArray()
UnionArray.SetName("union")
WageArray=vtkFloatArray()
WageArray.SetName("wage")
AgeArray=vtkIntArray()
AgeArray.SetName("age")
RaceArray=vtkIntArray()
RaceArray.SetName("race")
OccupationArray=vtkIntArray()
OccupationArray.SetName("occupation")
SectorArray=vtkIntArray()
SectorArray.SetName("sector")
MarriageArray=vtkIntArray()
MarriageArray.SetName("marriage")

## create window, glyph etc
win = vtkTkRenderWindowInteractor(root, width=300, height=300)
win.Initialize()
win.GlobalWarningDisplayOff()
def quit(obj=root):
obj.destroy()

ren = vtk.vtkRenderer()
win.GetRenderWindow().AddRenderer(ren)

## reading the data from the file and add data into 11 arrays
f=open('textdata.txt', 'r')
for line in f:
#read in a line and split up into a list delimited by ,
linelist = line.split("\t")
print linelist
#put two numbers into two integer arrays
myPoint.InsertNextPoint((float)(linelist[0]),(float)(linelist[3]),0)
EducationArray.InsertNextValue((int)(linelist[0]))
SouthArray.InsertNextValue((int)(linelist[1]))
SexArray.InsertNextValue((int)(linelist[2]))
ExperienceArray.InsertNextValue((int)(linelist[3]))
UnionArray.InsertNextValue((int)(linelist[4]))
WageArray.InsertNextValue((float)(linelist[5]))
AgeArray.InsertNextValue((int)(linelist[6]))
RaceArray.InsertNextValue((int)(linelist[7]))
OccupationArray.InsertNextValue((int)(linelist[8]))
SectorArray.InsertNextValue((int)(linelist[9]))
MarriageArray.InsertNextValue((int)(linelist[10]))


## add 11 arrays into one array in order to retrive the data.
data = vtk.vtkFloatArray()
data.SetNumberOfComponents(11)
data.SetNumberOfTuples(10)
data.CopyComponent(0, WageArray, 0)
data.CopyComponent(1, SouthArray, 0)
data.CopyComponent(2, SexArray,0)
data.CopyComponent(3, ExperienceArray,0)
data.CopyComponent(4, UnionArray,0)
data.CopyComponent(5, EducationArray,0)
data.CopyComponent(6, AgeArray,0)
data.CopyComponent(7, RaceArray,0)
data.CopyComponent(8, OccupationArray,0)
data.CopyComponent(9, SectorArray,0)
data.CopyComponent(10, MarriageArray,0)
data.SetName("data")

## find the max, and min number for the education and experience which
## are going to use in X,Y Axes.
listEdu=[]
listExp=[]
listSex=[]
listOcc=[]
for i in range(10): ######## this may be 9 !!!!!!!!!
listEdu[:0]=[data.GetComponent(i,5)]
listExp[:0]=[data.GetComponent(i,3)]
listSex[:0]=[data.GetComponent(i,2)]
listOcc[:0]=[data.GetComponent(i,8)]
maxXnum=max(listEdu)
minXnum=min(listEdu)
maxYnum=max(listExp)
minYnum=min(listExp)
maxSnum=max(listSex)
minSnum=min(listSex)
maxOccu=max(listOcc)
print maxXnum,minXnum,maxYnum,minYnum,maxSnum,minSnum

## set the points positions and add array into dataset
myGrid.SetPoints(myPoint)
myGrid.GetPointData().AddArray(data)
myGrid.GetPointData().SetActiveScalars("data")


# create x, y axes and scalar bar
MyXAxis=vtk.vtkAxisActor2D()
MyXAxis.SetFontFactor(0.5)
MyXAxis.SetLabelFactor(1.0)
MyXAxis.SetLabelFormat("%6.4g")
MyXAxis.GetProperty().SetColor(0,2,0)
MyXAxis.SetNumberOfLabels(10)
MyXAxis.SetRange(minXnum,maxXnum)
MyXAxis.SetPoint1(minXnum,minYnum)
MyXAxis.SetPoint2(maxXnum,minYnum)
MyXAxis.SetTitle("Education")


MyYAxis=vtk.vtkAxisActor2D()
MyYAxis.SetFontFactor(0.5)
MyYAxis.SetLabelFactor(1.0)
MyYAxis.SetLabelFormat("%6g")
MyYAxis.GetProperty().SetColor(0,2,0)
MyYAxis.SetNumberOfLabels(10)
MyYAxis.SetRange(maxYnum,minYnum)
MyYAxis.SetPoint1(minXnum,maxYnum)
MyYAxis.SetPoint2(minXnum,minYnum)
MyYAxis.SetTitle("Experience")


myTrans=vtk.vtkTransform()
myTransFilter=vtk.vtkTransformFilter()

Xrange=maxXnum-minXnum
Yrange=maxYnum-minYnum


if Xrange>Yrange:
myTrans.Scale(1,Xrange/Yrange,1)
MyYAxis.SetPoint1(minXnum,maxYnum*Xrange/Yrange)
else:
myTrans.Scale(Yrange/Xrange,1,1)
MyXAxis.SetPoint2(maxXnum*Yrange/Xrange,minYnum)

MyXAxis.GetPositionCoordinate().SetCoordinateSyste mToWorld()
MyXAxis.GetPoint1Coordinate().SetCoordinateSystemT oWorld()
MyXAxis.GetPoint2Coordinate().SetCoordinateSystemT oWorld()

MyYAxis.GetPositionCoordinate().SetCoordinateSyste mToWorld()
MyYAxis.GetPoint1Coordinate().SetCoordinateSystemT oWorld()
MyYAxis.GetPoint2Coordinate().SetCoordinateSystemT oWorld()

myTransFilter.SetInput(myGrid)
myTransFilter.SetTransform(myTrans)


## set source as sphere
sphere=vtk.vtkSphereSource()
sphere.SetRadius(.9)
sphere.SetPhiResolution(30)
sphere.SetThetaResolution(30)

# display points as glyphs
myGlyph=vtk.vtkGlyph3D()
myGlyph.SetInput(myTransFilter.GetOutput())
myGlyph.SetSource(sphere.GetOutput())
myGlyph.ClampingOff()
myGlyph.SetScaleModeToScaleByScalar()
myGlyph.SetScaleFactor(0.1)
myGlyph.SetColorModeToColorByScalar()

myMapper = vtk.vtkPolyDataMapper()
myMapper.SetInput(myGlyph.GetOutput())
myMapper.ScalarVisibilityOn()
myMapper.ColorByArrayComponent("data", 1)
myMapper.SetScalarRange(0,maxSnum)

myActor = vtk.vtkActor()
myActor.SetMapper(myMapper)

print myMapper.GetLookupTable

MyLegend=vtk.vtkScalarBarActor()
MyLegend.SetLookupTable(myMapper.GetLookupTable())
MyLegend.SetTitle('Scalar Bar')
MyLegend.SetOrientationToVertical()
MyLegend.SetLabelFormat("%6.4g")
MyLegend.SetNumberOfLabels(6)
MyLegend.SetHeight(1)

ren.AddActor(myActor)
ren.AddActor(MyLegend)
ren.AddActor(MyXAxis)
ren.AddActor(MyYAxis)

# pack the win into the tk root
win.pack(side="left",fill='both', expand=1)
win.Start()

# start the tk mainloop
root.mainloop()

RawDataExample()
Sep 30 '06 #1
1 2778
hi folks:

I fixed my problem now, I made a silly mistake. I should use v.get()==1, not v==1. :-)

have a nice day, everybody!!!!!
Sep 30 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
1
by: Jenny | last post by:
Need urgent help for an unsolved problem. In our ASP web application, we creat a Back button and if user click on this button, it execute history.go(-1) to go back to the previous page. All our...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
2
by: Keshav Gadia | last post by:
Hi, I am an ASP.net newbie. I am writing a user control that is made up of datagrid with one of the columns opening a new window to display some details on click of the set image. I have...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
4
by: Tami | last post by:
Hello, I could use some advice on the best way to connect to some php in my source code using ajax. So that the php will re-execute after so much time with a script elsewhere on the server. Please...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
10
by: =?Utf-8?B?am9uaWdy?= | last post by:
New to VB.NET, designing my first form with an MS manual at my side, placing objects and writing code. For good reason I just: SAVED All (!!) deleted all objects leaving only a grey form,...
13
by: HardHackz | last post by:
Hey, I'm having a little problem editing a file. Whenever I put something into it, it erases the old thing, is there a way to fix this so it doesn't erase the last thing?
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.