[Insight-users] how to load package in tcl for itk

Henkjan Huisman h.huisman at rad.umcn.nl
Fri, 26 Mar 2004 11:09:08 +0100


--=-9ysmorSR0tFyF6RSSlWS
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: quoted-printable

Attached tcl script will be in InsightToolkit/Examples/Visualization
someday. It demonstrates how to use both itk and vtk in a tcl-scripting
environment. You need the latest ConnectVTKITK from InsightApplications.
The pkgIndex.tcl files of vtk, itk and ConnectVTKITK should be in your
TCLLIB_PATH. See attached example.

Happy tcl-ing

Henkjan

On Fri, 2004-03-26 at 04:38, wavelethe at pku.org.cn wrote:
> that means, if i have NOT use tcl wrapers in vtk compiling, it would not =
work.
> could you tell me the steps using tcl in itk/vtk?
> (1) compile itk with tcl wrapers
> (2) compile vtk with tcl wrapers
> ...
>=20
>=20
> > -----Original Message-----
> > =B7=A2=BC=FE=C8=CB: Brad King <brad.king at kitware.com>
> > =C8=D5=C6=DA: Thu, 25 Mar 2004 09:03:45 -0500
> > =CA=D5=BC=FE=C8=CB: wavelethe at pku.org.cn
> > =B3=AD=CB=CD: "insight-users at itk.org" <insight-users at itk.org>
> > =D6=F7=CC=E2: Re: [Insight-users] how to load package in tcl for itk
> > wavelethe at pku.org.cn wrote:
> >=20
> > > after compiling SimpleLevelSetsExample seccessfully,
> > > I was told that "Result:can't find package vtkinteraction" when i run=
 View2DOutputInVTK.tcl in ASED=20
> > > Errorinfo: can't find package vtkinteraction while execting
> > > "package require vtkinteraction" invoked from within "interp eval $in=
terp $command"
> > >=20
> > > I am newbie and learning them, and i need some direction
> > > I have searched the file named "vtkinteraction", but only found one i=
n vtkwrap directory
> >=20
> > This example depends on VTK for visualization.  In order to run it=20
> > correctly, you need to have the VTK tcl wrappers in your TCLLIBPATH.=20
> > You should set the TCLLIBPATH variable to point at the Wrapping/Tcl=20
> > directory in the VTK build tree.
> >=20
> > -Brad
> >=20
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> ---------------------------------------------------------------
> =BB=B6=D3=AD=CA=B9=D3=C3=B1=B1=BE=A9=B4=F3=D1=A7=D0=A3=D3=D1=CD=F8(PKUAA)=
=B5=E7=D7=D3=D3=CA=BC=FE=CF=B5=CD=B3 http://www.pku.org.cn
>=20
>=20
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users

--=-9ysmorSR0tFyF6RSSlWS
Content-Disposition: attachment; filename=CannyEdgeDetectionImageFilterConnectVTKITK.tcl
Content-Type: text/x-tcl; name=CannyEdgeDetectionImageFilterConnectVTKITK.tcl; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

# This file demonstrates how to connect VTK and ITK pipelines together
# in scripted languages with the new ConnectVTKITK wrapping functionality.
# Data is loaded in with VTK, processed with ITK and written back to disc
# with VTK.=20
#
# For this to work, you have to build InsightApplications/ConnectVTKITK
# as well.
#
# -- Charl P. Botha <cpbotha AT ieee.org>
# -- Modified to Tcl version by H.J.Huisman (25 March 2004)
# Execute this script by:
#      tclsh CannyEdgeDetectionImageFilterConnectVTKITK.tcl
# You must set the environment variable TCLLIB_DIR to where the tcl
# libraries are on your system. For example:
#      export  TCLLIB_DIR=3D"/data/usr/itk16/lib/InsightToolkit /data/usr/v=
tk422/lib/vtk /data/prog/InsightApplications-1.6.0/ConnectVTKITK/"
#
puts "Loading VTK package [package require vtk]"
puts "Loading InsightToolkit [package require InsightToolkit]"
puts "Loading ConnectVTKITK [package require ConnectVTKITK]"
wm withdraw .

# VTK will read the PNG image for us
vtkPNGReader reader
reader SetFileName "../../Testing/Data/Input/cthead1.png"

# it has to be a single component, itk::VTKImageImport doesn't support more
vtkImageLuminance lum
lum SetInput [reader GetOutput]

# let's cast the output to float
vtkImageCast imageCast
imageCast SetOutputScalarTypeToFloat
imageCast SetInput [lum GetOutput]

# the end-point of this VTK pipeline segment is a vtkImageExport
vtkImageExport vtkExporter
vtkExporter SetInput [imageCast GetOutput]

# it connects to the itk::VTKImageImport at the beginning of
# the subsequent ITK pipeline; two-dimensional float type
set itkImporter [itkVTKImageImportF2_New]

# Call the magic function that connects the two.  This will only be=20
# available if you built ITK with ITK_CSWIG_CONNECTVTKITK set to ON.
ConnectVTKToITKF2 vtkExporter [$itkImporter GetPointer]

# perform a canny edge detection and rescale the output
set canny [itkCannyEdgeDetectionImageFilterF2F2_New]
set rescaler [itkRescaleIntensityImageFilterF2US2_New]
$canny SetInput [$itkImporter GetOutput]
$rescaler SetInput [$canny GetOutput]
$rescaler SetOutputMinimum 0
$rescaler SetOutputMaximum 65535

# this will form the end-point of the ITK pipeline segment
set itkExporter [itkVTKImageExportUS2_New]
$itkExporter SetInput [$rescaler GetOutput]

# the vtkImageImport will bring our data back into VTK-land
vtkImageImport vtkImporter
# do the magic connection call (once again: only available if you built
# ITK with ITK_CSWIG_CONNECTVTKITK set to ON)
ConnectITKUS2ToVTK [$itkExporter GetPointer] vtkImporter

# finally write the image to disk using VTK
vtkPNGWriter writer
writer SetFileName "testout.png"
writer SetInput [vtkImporter GetOutput]

# before we call Write() on the writer, it is prudent to give
# our ITK pipeline an Update() call... this is not necessary
# for normal error-less operation, but ensures that exceptions
# thrown by ITK get through to us in the case of an error;
# This is because the VTK wrapping system does not support
# C++ exceptions.
$rescaler Update

# write the file to disk...
writer Write

puts "\n\nWrote testout.png to current directory."
exit

--=-9ysmorSR0tFyF6RSSlWS--