Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sige0008
    New Member
    • Sep 2006
    • 13

    #1

    Help

    Hi all

    I'm trying to colour and scale spherical glyphs using two different scalar arrays in the Polydata.Unfort unately, what I seem to be able to do is to colour *and* scale according to the one scalar array, but not be able to scale by one scalar and colour by the other. The code attached:

    Can anyone help what wrong with my code?

    This is data file:
    1,6,3
    1,6,2
    2,6,4
    2,3,5
    6,3,2
    6,3,2

    from vtk import *
    from vtk.tk.vtkTkRen derWindowIntera ctor import *
    from Tkinter import *

    def RawDataExample( ):
    """ Creates 2D data inside a vtkTkRenderWind owInteractor. """
    def SetScalar1():
    #color grid by first set of scalars
    myGrid.GetPoint Data().SetScala rs(myFirstScala r)
    win.Render()
    return
    def SetScalar2():
    ##color grid by second set of scalars
    myGrid.GetPoint Data().SetScala rs(mySecondScal ar)
    win.Render()
    return
    def SetScalar3():
    myGrid.GetPoint Data().SetScala rs(myThirdScala r)
    win.Render()
    return

    # create root window
    root = Tk()
    root.title("Raw Data 1")
    f=Frame(root)
    f.pack()
    heading=Label(f ,text="Raw Data")
    heading.pack()
    quit=Button(f,t ext="Quit",comm and=root.destro y)
    quit.pack()

    #set up a structured points and two arrays to hold sets of data
    myGrid=vtkPolyD ata()

    myPoint=vtkPoin ts()

    myFirstScalar = vtkIntArray()
    myFirstScalar.S etName("myfirst ")
    mySecondScalar = vtkIntArray()
    mySecondScalar. SetName("myseco nd")
    myThirdScalar=v tkIntArray()
    myThirdScalar.S etName("mythird ")

    myGlyph=vtk.vtk Glyph3D()

    #set up buttons to swap from 1 scalar array to the other
    Scalar1btn= Button(f,text= "scalar1", command=SetScal ar1)
    Scalar2btn= Button(f,text= "scalar2", command=SetScal ar2)
    Scalar3btn= Button(f,text= "scalar3", command=SetScal ar3)
    Scalar1btn.pack ()
    Scalar2btn.pack ()
    Scalar3btn.pack ()


    win = vtkTkRenderWind owInteractor(ro ot, width=300, height=300)
    win.Initialize( )
    win.GlobalWarni ngDisplayOff()
    def quit(obj=root):
    obj.destroy()

    ren = vtk.vtkRenderer ()
    win.GetRenderWi ndow().AddRende rer(ren)

    ## #set grid with 6 points
    ## myGrid.SetDimen sions(3,2,1)
    ## myGrid.SetSpaci ng(1,1,0)
    ## myGrid.SetOrigi n(0.,0.,0.)



    # read some data for 6 points

    f=open('textdat a.txt', 'r')
    for line in f:
    #read in a line and split up into a list delimited by ,
    linelist = line.split(',')
    print linelist
    #put two numbers into two integer arrays
    myPoint.InsertN extPoint((float )(linelist[0]),(float)(linel ist[2]),0)
    myFirstScalar.I nsertNextValue( (int)(linelist[0]))
    mySecondScalar. InsertNextValue ((int)(linelist[1]))
    myThirdScalar.I nsertNextValue( (int)(linelist[2]))

    data = vtk.vtkFloatArr ay()
    data.SetNumberO fComponents(2)
    data.SetNumberO fTuples(3)
    data.CopyCompon ent(0, myFirstScalar, 0)
    data.CopyCompon ent(1, myFouthScalar, 0)
    data.SetName("d ata")


    myGrid.SetPoint s(myPoint)
    myGrid.GetPoint Data().AddArray (data)
    myGrid.GetPoint Data().SetActiv eScalars("data" )


    cone=vtk.vtkSph ereSource()

    myGlyph.SetInpu t(myGrid)
    myGlyph.SetSour ce(cone.GetOutp ut())
    myGlyph.Clampin gOff()
    myGlyph.SetScal eModeToScaleByS calar()
    myGlyph.SetScal eFactor(.1)
    myGlyph.SetColo rModeToColorByS calar()


    myMapper = vtk.vtkPolyData Mapper()
    myMapper.SetInp ut(myGlyph.GetO utput())
    myMapper.Scalar VisibilityOn()
    myMapper.ColorB yArrayComponent ("data", 1)
    myMapper.SetSca larRange(0,6)

    myActor = vtk.vtkActor()
    myActor.SetMapp er(myMapper)

    ren.AddActor(my Actor)

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

    # start the tk mainloop
    root.mainloop()

    RawDataExample( )
  • sige0008
    New Member
    • Sep 2006
    • 13

    #2
    Thank guys, I have found solution for this :-)

    I am thinking to add another scalar array to control the shape of points

    any ideas? thanks:-)

    Comment

    Working...