catch {load vtktcl} # Setting up a color database: white, red, green, blue, yellow # cyan, magenta, sky blue, black set color(0) "1 1 1" set color(1) "1 0 0" set color(2) "0 1 0" set color(3) "0 0 1" set color(4) "1 1 0" set color(5) "0 1 1" set color(6) "1 0 1" set color(7) "0.5 0.5 1" set color(8) "0 0 0" # Create the RenderWindow, Renderer vtkRenderer ren1 vtkRenderWindow renWin renWin AddRenderer ren1 vtkRenderWindowInteractor iren iren SetRenderWindow renWin set file [open "object.dat"] # j: keeps track of how many moves # pointIndex: keeps track of how many points per move set j 0 set jtemp 0 set pointIndex 0 # creating the initial points and cell array vtkFloatPoints points_$j vtkCellArray order_$j set line [gets $file] while {! [eof $file]} { # this will allow creation of new points and arrays on the fly if {$jtemp < $j} { vtkFloatPoints points_$j vtkCellArray order_$j order_$jtemp InsertNextCell $pointIndex for {set i 0} {$i < $pointIndex} {incr i} { order_$jtemp InsertCellPoint $i } set pointIndex 0 set jtemp $j } else { # skipping the moves if {[string index $line 0] == "&"} { incr j set line [gets $file] } else { if {[llength $line] != "0"} { set x [lindex $line 0] set y [lindex $line 1] # testing if there is a 3D input, otherwise set z to 0 if {[llength $line] == "3"} { set z [lindex $line 2] } else { set z 0 } points_$j InsertPoint $pointIndex $x $y $z incr pointIndex set line [gets $file] } else { set line [gets $file] } } } } # since the while loop won't create the final points and arrays order_$jtemp InsertNextCell $pointIndex for {set i 0} {$i < $pointIndex} {incr i} { order_$jtemp InsertCellPoint $i } # simple for loop that creates setup for the j moves for {set i 0} {$i <= $j} {incr i} { vtkPolyData profile_$i profile_$i SetPoints points_$i vtkDelaunay2D del_$i del_$i SetInput profile_$i del_$i SetTolerance 0.001 del_$i SetAlpha 0.0 del_$i Update vtkPolyDataMapper map_triangle_$i map_triangle_$i SetInput [del_$i GetOutput] vtkActor triangulation_$i triangulation_$i SetMapper map_triangle_$i set temp [expr $i+1] eval [triangulation_$i GetProperty] SetColor $color($temp) [triangulation_$i GetProperty] SetOpacity .9 ren1 AddActor triangulation_$i } # Render ren1 SetBackground 1 1 1 renWin SetSize 500 500 renWin Render #-------------------------------- # # Small user interface added # #-------------------------------- proc savePPM {} { renWin SetFileName "display.ppm" renWin SaveImageAsPPM } button .ppm -text "Save as PPM" -command savePPM button .exit -text "Exit" -command exit pack .ppm .exit -side top -fill both -expand t wm geometry . +510+0 wm title . "VTK Display V1.4"