[vtkusers] vtktkrenderwidget problem

Pratheek Arora pratheeka at wiproge.med.ge.com
Wed May 2 08:07:03 EDT 2001


Hello friend
  I am facing one problem. I am trying to open a file in  vtkTkRenderWidget
but I am unable to open the file. it also not showing amy error, can you
tell me why it is so happening
I am sending a program
thanks
prateek

****************************************************************************
*****************
## Create a little app for loading and viewing polygonal files
##
catch {load vtktcl}

source f:\\istart.bat

# Create gui
wm title . "Registration"
frame .mbar -relief raised -bd 2
pack .mbar -side top -fill x

menubutton .mbar.file -text File -menu .mbar.file.menu
menubutton .mbar.view -text View -menu .mbar.view.menu
menubutton .mbar.help -text Help -menu .mbar.help.menu
pack .mbar.file .mbar.view -side left
pack .mbar.help -side right

menu .mbar.file.menu
    .mbar.file.menu add command -label Open -command OpenFile
    .mbar.file.menu add command -label Exit -command exit

set view Left
menu .mbar.view.menu
    .mbar.view.menu add radiobutton -label Front -variable view -value
Front\
            -command {UpdateView 1 0 0 0 1 0}
    .mbar.view.menu add radiobutton -label Back -variable view -value Back\
            -command {UpdateView -1 0 0 0 1 0}
    .mbar.view.menu add radiobutton -label Left -variable view -value Left\
            -command {UpdateView 0 0 1 0 1 0}
    .mbar.view.menu add radiobutton -label Right -variable view -value
Right\
            -command {UpdateView 0 0 -1 0 1 0}
    .mbar.view.menu add radiobutton -label Top -variable view -value Top\
            -command {UpdateView 0 1 0 0 0 1}
    .mbar.view.menu add radiobutton -label Bottom -variable view -value
Bottom\
            -command {UpdateView 0 -1 0 0 0 1}
    .mbar.view.menu add radiobutton -label Isometric -variable view \
        -value Isometric -command {UpdateView 1 1 1 0 1 0}

menu .mbar.help.menu
    .mbar.help.menu add command -label {Buy a book!}

vtkTkRenderWidget .window -width 300 -height 300
    BindTkRenderWidget .window
pack .window -side top -anchor nw -padx 3 -pady 3 -fill both -expand 1

set ren [vtkRenderer ren]

# Procedure to set particular views
proc UpdateView {x y z vx vy vz} {
    global ren renWin

    set camera [$ren GetActiveCamera]
    $camera SetViewPlaneNormal $x $y $z
    $camera SetViewUp $vx $vy $vz
    $ren ResetCamera
    Render
}

# Procedure opens file and resets view
proc OpenFile {} {
     global renWin ren

     set types {
         {{PNMREADER}                            {.pgm}        }
         {{Cyberware (Laser Scanner)}            {.ppn}        }
         {{TIFIMAGE READER}                      {.tif}        }
         {{Visualization Toolkit (polygonal)}    {.vtk}        }
         {{All Files }                           *             }
     }
     set filename [tk_getOpenFile -filetypes $types]
     if { $filename != "" } {
	$ren RemoveActor bannerActor
        $ren RemoveActor actor
         if { [info commands reader] != "" } {reader Delete}
         if { [string match *.pgm $filename] } {
             vtkPNMReader reader
             reader SetFileName $filename
             puts $filename
             puts "prateek arora "
         } elseif { [string match *.ppn $filename] } {
             vtkPNMReader reader
             reader SetFileName $filename
             puts $filename
         } elseif { [string match *.vtk $filename] } {
             vtkPolyDataReader reader
             reader SetFileName $filename
             puts $filename
         } elseif { [string match *.tif $filename] } {
             vtkTIFFReader reader
             reader SetFileName $filename
             puts $filename
         } elseif { [string match *.tri $filename] } {
             vtkMCubesReader reader
             reader SetFileName $filename
         } else {
             puts "Can't read this file"
             return
         }


        mapper SetInput [reader GetOutput]
#        $reader Update
        if { [[reader GetOutput] GetNumberOfCells] <= 0 } {
            $ren AddActor bannerActor
        } else {
            $ren AddActor actor
        }
        $ren ResetCamera
        $renWin Render
    }
}

# Create pipeline
set reader stl
vtkSTLReader stl
vtkBYUReader byu
vtkPolyDataReader vtk
vtkImageMapper   mapper
vtkActor2D actor
    actor SetMapper mapper

vtkVectorText banner
    banner SetText "     vtk\nPolygonal Data\n    Viewer"
vtkPolyDataMapper bannerMapper
    bannerMapper SetInput [banner GetOutput]
vtkActor bannerActor
    bannerActor SetMapper bannerMapper

set renWin [.window GetRenderWindow]
# set ren   [$renWin MakeRenderer]

$ren AddActor bannerActor
[$ren GetActiveCamera] Zoom 1.25

****************************************************************************
***********





More information about the vtkusers mailing list