[vtkusers] Trying to use vtkChartXY with Tcl

Mario Rodriguez biomates at telefonica.net
Wed Dec 16 14:10:21 EST 2015



El 16/12/15 a las 00:52, David Gobbi escribió:
> Hi Mario,
>
> The fact that you are using Tcl actually validates our continuing
> support for Tcl, so in a way it is a good thing.
>
> The best way to get a fully-functional VTK window with Tcl is to
> use Tk.  Take a look at these two examples:
>
>   Examples/GUI/Tcl/vtkTkRenderWidgetDemo.tcl
>   Examples/GUI/Tcl/MaceTk.tcl
>
> The MaceTk example provides a window close operation, using
> this call to the window manager:
>
>   wm protocol . WM_DELETE_WINDOW <callback function>
>
> For more information, see the tk documentation, e.g.:
> https://www.tcl.tk/man/tcl8.4/TkCmd/wm.htm
>
>  - David
>


Dear David,

I am very grateful for your help.

This is the translation of TestLinePlot.py into tcl. I hope others will 
find this example useful:




#############  START TCL  (v. 6.3) #################

package require vtk
package require vtkinteraction

vtkChartXY chart

vtkFloatArray arrX
   arrX SetName "X Axis"

vtkFloatArray arrC
   arrC SetName "Cosine"

vtkFloatArray arrS
   arrS SetName "Sine"

vtkFloatArray arrS2
   arrS2 SetName "Sine2"

set numPoints 69
set inc [expr 7.5 / ($numPoints - 1)]

for {set i 0} {$i<$numPoints} {incr i 1} {
   arrX InsertNextValue [expr $i * $inc]
   arrC InsertNextValue  [expr cos($i * $inc) + 0.0]
   arrS InsertNextValue  [expr sin($i * $inc) + 0.0]
   arrS2 InsertNextValue [expr sin($i * $inc) + 0.5]
   }

vtkTable table
   table AddColumn arrX
   table AddColumn arrC
   table AddColumn arrS
   table AddColumn arrS2

set line [chart AddPlot 0]
   $line SetInputData table 0 1
   $line SetColor 0 255 0 255
   $line SetWidth 1.0

set line [chart AddPlot 0]
   $line SetInputData table 0 2
   $line SetColor 255 0 0 255
   $line SetWidth 5.0

set line [chart AddPlot 0]
   $line SetInputData table 0 3
   $line SetColor 0 0 255 255
   $line SetWidth 4.0

vtkContextView view
   [view GetRenderer] SetBackground 1.0 1.0 1.0
   [view GetRenderWindow] SetSize 400 300
   [view GetScene] AddItem chart
   [view GetRenderWindow] SetMultiSamples 0

vtkRenderWindowInteractor iren
    iren SetRenderWindow [view GetRenderWindow]
    iren Initialize
    iren AddObserver UserEvent {wm deiconify .vtkInteract}
wm withdraw .
iren Start

#############  END TCL #################


This is a starting point for further work.

Let the force be with you!

--
Mario



More information about the vtkusers mailing list