[vtkusers] [Newbie] TCL problem: vtk objects persisting in second function call
Jonathan Bailleul
bailleul at greyc.ismra.fr
Thu Jan 30 10:07:26 EST 2003
Dear all,
I retrieved a tcl script (cf sample at the end of message) that I
decided to put inside a procedure to enable iterated calling.
Unfortunately, the second call of the procedure raises the error:
"vtkImageReader reader: this objects already exists" (or so, tcl is not
installed in my office)
It seems strange regarding the basic idea that an object instanciated
inside a function should disappear at function's end! So vtk objects are
persistent and global, or did I really miss something with TCL (I've
just started learning).
What should I do so? Test for existence of object, and if yes, only
modify its properties? Seems weird!
In advance, thank you for your patience and your comments.
Source code sample:
proc segmented16 {NAME STUDY TISSUE} {
source importGlobals.tcl
set OK 1
# Set defaults for any parameters not defined
if {[info exists NAME] == 0} {
puts "segmented16.tcl: NAME is not defined"
set OK 0
}
if {[info exists STUDY] == 0} {
puts "segmented16.tcl: STUDY is not defined"
set OK 0
}
...
}
if {[info exists TISSUE] == 0} {
puts "segmented16.tcl: TISSUE is not defined"
set OK 0
}
if { $OK == 0 } {
puts "segmented16.tcl: One or more required parameters are missing!"
#exit
}
if {[info exists SLICE_ORDER] == 0} {set SLICE_ORDER si}
if {[info exists HEADER_SIZE] == 0} {set HEADER_SIZE 0}
if {[info exists FILE_PATTERN] == 0} {set FILE_PATTERN %s.%d}
...
if {[info exists SMOOTH_SHRINK] == 0} {set SMOOTH_SHRINK .10}
if {[info exists VOI] == 0} {
set VOI "0 [expr $COLUMNS - 1] 0 [expr $ROWS - 1] 0 $ZMAX"
}
if {[info exists SAMPLE_RATE] == 0} {set SAMPLE_RATE "1 1 1"}
set originx [expr ( $COLUMNS / 2.0 ) * $PIXEL_SIZE * -1.0]
set originy [expr ( $ROWS / 2.0 ) * $PIXEL_SIZE * -1.0]
vtkImageReader reader;
eval reader SetFilePrefix $STUDY
eval reader SetDataExtent 0 [expr $COLUMNS - 1] 0 [expr $ROWS - 1]
$START_SLICE $END_SLICE
eval reader SetDataVOI $VOI
eval reader SetDataSpacing $PIXEL_SIZE $PIXEL_SIZE $SPACING
eval reader SetDataOrigin $originx $originy [expr ( $START_SLICE -
1) * $SPACING]
reader SetFilePattern $FILE_PATTERN
reader SetTransform $SLICE_ORDER
reader SetHeaderSize $HEADER_SIZE
reader SetDataMask 0x7fff;
reader SetDataByteOrderTo$BYTE_ORDER
reader SetDataScalarTypeToUnsignedShort
[reader GetOutput] ReleaseDataFlagOn
--
--------------------------
Jonathan BAILLEUL
Doctorant au GREYC Image
ISMRA, Université de Caen
More information about the vtkusers
mailing list