[vtkusers] points problem for newbie

Spencer Ross Austin sr.austin at btinternet.com
Thu Jun 21 15:43:53 EDT 2007


Dear VTK Users

 

I am new to the VTK/TK world and am having a few teething problems, the
small program I have written below won't work because it seems I can't pass
a vtkPoints request into the scale option, which I hope will allow me to
affect the point of insertion for my glyphs, making the points move up and
down or left and right depending on the scale bars.

 

I would appreciate if anyone could shed some light on the situation, or if
you could correct the problem so I might hack around it and understand my
error.

 

Yours gratefully 

 

BunHead

 

 

 

 

# Load required packages for VTK interaction

package require vtk

package require vtkinteraction

package require vtktesting

 

set AlphaX 0

set AlphaY 0

set AlphaZ 0

 

# create point for glyphs and lines, within 3D space x,y,z

vtkPoints inputPoints

            inputPoints SetNumberOfPoints 3

            inputPoints InsertPoint 0 1 0 0

            inputPoints InsertPoint 1 0 1 0

            inputPoints InsertPoint 2 -1 0 0

 

# Convert 'inputPoints' to PolyData for other VTK function to understand

vtkPolyData inputData

            inputData SetPoints inputPoints  

            

# create a sphere called 'balls'

vtkSphereSource balls

            balls SetRadius .05

            balls SetPhiResolution 10

            balls SetThetaResolution 10

 

#create a glyph using 'balls' as the object and 'inputData' for location
with 3D space

vtkGlyph3D glyphPoints

            glyphPoints SetInput inputData

            glyphPoints SetSource [balls GetOutput]

 

#Assign simple mapper to glyph

vtkPolyDataMapper glyphMapper

            glyphMapper SetInput [glyphPoints GetOutput]

 

#create actor of gylph to enable rendering 

vtkActor glyph

            glyph SetMapper glyphMapper

            eval   [glyph GetProperty] SetDiffuseColor $tomato

            [glyph GetProperty] SetSpecular .3

            [glyph GetProperty] SetSpecularPower 30

 

# Create the polyline.

vtkCellArray lines

            lines InsertNextCell 4

            lines InsertCellPoint 0 

            lines InsertCellPoint 1 

            lines InsertCellPoint 2 

            lines InsertCellPoint 0 

 

# will have to contain a command that work out weather it is the last [NODE]
in the current network

#thus determining weather it requires connecting to the first [NODE] to
complete the circuit

            

# Generate the polyline for the spline using the 'inputPoints' as the start
and end possitions.

vtkPolyData profileData

            profileData SetPoints inputPoints

            profileData SetLines lines

 

# Add thickness to the resulting line.

vtkTubeFilter profileTubes

            profileTubes SetNumberOfSides 8

            profileTubes SetInput profileData

            profileTubes SetRadius .0075

 

vtkPolyDataMapper profileMapper

            profileMapper SetInput [profileTubes GetOutput]

 

vtkActor profile

            profile SetMapper profileMapper

            eval  [profile GetProperty] SetDiffuseColor $banana

            [profile GetProperty] SetSpecular .3

            [profile GetProperty] SetSpecularPower 30

 

# Now create the RenderWindow, Renderer and Interactor

#

 

vtkRenderer ren1

            ren1 AddActor glyph

            ren1 AddActor profile

 

vtkRenderWindow renWin

            renWin AddRenderer ren1

            renWin SetSize 500 500

            

vtkRenderWindowInteractor iren

            iren SetRenderWindow renWin

 

set vtkw [vtkTkRenderWidget .ren \

            -width 300 \

            -height 300 \

            -rw renWin]

# render the image

 

iren Initialize

iren AddObserver UserEvent {wm deiconify .vtkInteract}

 

# prevent the tk window from showing up

#wm withdraw .

 

 

# Create scroller bars for the user to adjust the position of the
'inputPoints'

 

frame .pos

 

set xaxis [scale .pos.xaxis \

                                    -from 0 -to 3 -res 0.5 \

                                    -orient horizontal \

                                    -label "Adjust 'X' axis:" \

                                    -command changeX]

                                    

$xaxis set [inputPoints GetPoint 0]

 

proc changeX {xres} {

            inputPoints InsertPoint 0 $xres 0 0

            renWin Render

}

 

set yaxis [scale .pos.yaxis \

                                    -from 0 -to 3 -res 0.5 \

                                    -orient horizontal \

                                    -label "Adjust 'Y' axis:" \

                                    -command changeY]

                                    

$yaxis set [inputPoints GetPoint 0]

 

proc changeY {yres} {

            inputPoints InsertPoint 0 0 $yres 0

            renWin Render

}

 

button .pos.quit -text "Quit" -command ::vtk::cb_exit

button .pos.reset -text "Reset Camera" -command resetCamera

 

vtkCamera cam1

 

proc resetCamera {} {

                        cam1 SetClippingRange 0.0 0.0

                        cam1 SetFocalPoint 0.0 0.5 0.0

                        cam1 SetPosition 0.0 0.0 5.0

                        cam1 SetViewUp 0.0 0.0 0.0

            ren1 SetActiveCamera cam1

            renWin Render

}

 

 

pack $xaxis $yaxis .pos.reset .pos.quit -side top -anchor nw -fill both

pack $vtkw .pos -side top -fill both -expand yes

 

wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit

 

tkwait window .

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070621/ddab1b60/attachment.htm>


More information about the vtkusers mailing list