[vtkusers] What's wrong with this TCL script?

Michnay Balázs michnay at freemail.hu
Thu Dec 2 10:40:59 EST 2004

Hi all,
The following tcl script should extract regions from a BMP file, but it 
doesn't act as I expected.
It uses vtkConnectivityFilter to extract regions from the BMP file having 
the ScalarConnectivity set to true.
It extracts the largest region, but GetNumberOfExtrqctedRegions 
returns a huge number. (it seems like to be the number of pixels falling 
into the extracted region and the image contains 8 connected 
What should I do to this code to fix this?
This code was generated by VTKGUI 1.0 and runs without problems...
Thanks again,

PS: If my problem (extracting connected components from a 
vtkImageData without using ContourFilter) cannot be solved with VTK 
and I need to write my own routines, please let me know...


# ------------------------------------------------------------
# Call the VTK Tcl packages to make available all VTK commands
# ------------------------------------------------------------

package require vtk
package require vtkinteraction
package require vtktesting

# --------------------------------------------------------------
# Create a Renderer, a RenderWindow and a RenderWindowInteractor
# --------------------------------------------------------------

vtkRenderer R
   R SetBackground 0.5 0.5 0.5 
   R SetLightFollowCamera 1

vtkRenderWindow RW
   RW AddRenderer R
   RW AddRenderer R
   RW SetSize 853 580 

vtkRenderWindowInteractor RWI
   RWI SetRenderWindow RW
   RWI SetLightFollowCamera 1

# -----------------------
# Create the VTK pipeline
# -----------------------

vtkBMPReader BMPR
#   BMPR SetInput [...bmp file...]

vtkConnectivityFilter CF
   CF SetInput [BMPR GetOutput]
   CF SetOutput [CF GetOutput]
   CF SetClosestPoint 0 0 0 
   CF SetProgress 1
   CF SetScalarRange 0 0 
   CF SetExtractionMode 4
   CF SetAbortExecute 0
   CF SetColorRegions 1
   CF SetDebug 0
   CF SetGlobalWarningDisplay 1
   CF SetReleaseDataFlag 0
   CF SetScalarConnectivity 1

vtkDataSetMapper DSM
   DSM SetInput [CF GetOutput]
   DSM SetScalarRange 0 1 
   DSM SetColorMode 0
   DSM SetResolveCoincidentTopology 0
   DSM SetScalarMode 0
   DSM SetImmediateModeRendering 0
   DSM SetScalarVisibility 1

vtkActor A
   A SetMapper DSM

# -----------------------------------
# Insert all actors into the renderer
# -----------------------------------

   R AddActor A

# -------------------------------------
# Reset the camera and show the console 
# -------------------------------------

R ResetCamera
R ResetCameraClippingRange
RW Render
#RWI Start

;# To enable a console, uncomment next line
#console show
wm withdraw .


More information about the vtkusers mailing list