Michael Feldman mfeldman at
Mon Aug 2 17:51:38 EDT 1999

I have modified an application that was sent to me by drew at
It creates a cube and allows me to divide each surface into small squares
and give them a color.  I need some advice on how to expand upon this and
make it do what i really want.  I need to be able to divide the cube into
smaller cubes and then color these cubes (including interior cubes). 
Here is my tcl script.  The data file refered to is a file of random 0's 
and 1's (of size numCells).  (I know that many of these lines are not
used, but that is because it was from a randomcolor generated image of a
cube). If you have time please send me any help you can. -- Thank you -


catch {load vtktcl}
# user interface command widget
source ../examplesTcl/vtkInt.tcl

# create a rendering window and renderer
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin
set n0 10
set n0m1 [expr $n0 - 1]

# Create point dataset. This basicly will create a cube with
# dimensions 0 to (n0 - 1)

vtkFloatPoints points
for {set x 0} {$x < $n0} {incr x} {
    for {set y 0} {$y < $n0} {incr y} {
        for {set z 0} {$z < $n0} {incr z} {
            points InsertNextPoint $x $y $z

# create cube to color
vtkStructuredGrid cube
    cube SetDimensions $n0 $n0 $n0
    cube SetPoints points

vtkGeometryFilter filter
    filter SetInput cube

# Compute random scalars (colors) for each cell
vtkProgrammableAttributeDataFilter randomColors
    randomColors SetInput [filter GetOutput]
    randomColors SetExecuteMethod colorCells

proc colorCells {} {
    vtkMath randomColorGenerator
    set input [randomColors GetInput]
    set output [randomColors GetOutput]
    set numCells [$input GetNumberOfCells]
    vtkScalars colors
        colors SetNumberOfScalars $numCells
    set f [open "../graphics/myprog/data" "r"]
    for {set i 0} {$i < $numCells} {incr i} {
        gets $f col
#       colors SetScalar $i [randomColorGenerator Random 0 1]
#	if { $i < [expr $numCells/2] } {   
#	set j 1 
#	} else {
#	set j 0}

        colors SetScalar $i $col
    puts "$numCells"
    [$output GetCellData] CopyScalarsOff
    [$output GetCellData] PassData [$input GetCellData]
    [$output GetCellData] SetScalars colors
    colors Delete; # reference counting - it's ok
    randomColorGenerator Delete
    close $f
# mapper and actor
vtkPolyDataMapper mapper
    mapper SetInput [randomColors GetPolyDataOutput]
    eval mapper SetScalarRange [[randomColors GetPolyDataOutput]

vtkActor cubeActor
    cubeActor SetMapper mapper
ren1 AddActor cubeActor

wm withdraw .
iren SetUserMethod {wm deiconify .vtkInteract}
iren Initialize
iren Start


Michael Feldman

mfeldman at
SRC '01

This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.

More information about the vtkusers mailing list