Skip to content
berkgeveciPublic

About

VTK Tcl compatibility layer using tclpy

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

vtk_tcl

A Tcl compatibility layer that emulates the classic VTK Tcl bindings (removed in VTK 8.2) by bridging VTK's Python API back into Tcl via tclpy.

Overview

The original VTK Tcl bindings allowed direct object creation and method calls using a natural Tcl syntax:

vtkCylinderSource cylinder
cylinder SetResolution 50
mapper SetInputConnection [cylinder GetOutputPort]

This project restores that workflow by intercepting Tcl commands and dispatching them to VTK through Python. It also provides a vtkTkRenderWidget command for embedding VTK render windows inside Tk GUIs with interactive camera controls.

Requirements

  • Tcl 8.6+ (with Tk for GUI examples)
  • Python 3 with VTK installed (pip install vtk)
  • tclpy Tcl extension

Usage

Source the compatibility layer and use VTK as you would with the classic Tcl bindings:

source vtktcl.tcl

vtkCylinderSource cylinder
cylinder SetResolution 50

vtkPolyDataMapper mapper
mapper SetInputConnection [cylinder GetOutputPort]

vtkActor actor
actor SetMapper mapper

vtkRenderer ren
vtkRenderWindow renWin
renWin AddRenderer ren

vtkRenderWindowInteractor iren
iren SetRenderWindow renWin

ren AddActor actor
iren Initialize
renWin Render
iren Start

Tk Integration

Embed a VTK render window in a Tk application:

source vtktcl.tcl
package require Tk

vtkRenderer ren
vtkRenderWindow renWin
renWin AddRenderer ren

vtkTkRenderWidget .vtk -width 600 -height 600 -rw renWin
pack .vtk

The widget supports mouse interaction (rotate, pan, zoom) out of the box.

Observers

VTK observers work with Tcl callbacks:

proc onKeyPress {} {
    puts "Key pressed!"
}
iren AddObserver KeyPressEvent onKeyPress

Files

  • vtktcl.tcl - The compatibility layer (source this to use VTK from Tcl)
  • test_vtk.tcl - Basic rendering example with a cylinder
  • test_vtk_observer.tcl - Observer/callback example
  • test_vtk_tk.tcl - Full Tk GUI with sliders, color controls, and embedded VTK rendering

License

This project is licensed under the BSD 3-Clause License. See LICENSE for details.

About

VTK Tcl compatibility layer using tclpy

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages