[vtkusers] How can I insert a Tcl binary string into a vtkDataArray?

Erin McKay e.mckay at unsw.edu.au
Mon Feb 7 16:06:43 EST 2005

Actually its not that hard (ahem). SetArray works just fine...

I have attached a brief code example for future reference:

> I have a big chunk of data (from a database) in a Tcl binary string.
> I'd really like to stuff it into a vtkDataArray for analysis. Is there
> any fast way to do this? I've tried vtkCharArray::SetArray but it
> doesn't like string arguments. SetValue is too slow. I've seen similar
> questions asked in the mailing list archives but no definitive answers
> as yet. Surely it can't be that hard??

package require my_stuff
package require vtk
package require vtkinteraction
	set wd [$dbImage GetWidth]
	set ht [$dbImage GetHeight]
	set buffer [$dbImage CopyData]
	# buffer is a binary string produced, in this instance, using a SWIG 

	vtkCharArray imageData
	imageData SetArray $buffer [string bytelength $buffer] 1

	vtkImageData myImage
	myImage SetDimensions $wd $ht 1
	myImage SetScalarTypeToFloat
	[myImage GetPointData] SetScalars imageData

	vtkImageViewer viewer
	viewer SetInput myImage
	viewer SetColorWindow [expr $wd + $ht]
	viewer SetColorLevel [expr ($wd + $ht / 2)]

	viewer Render
	wm withdraw .

More information about the vtkusers mailing list