[vtkusers] How to extract all pixel values from a vtkImageData into a Tcl binary string?
Erin McKay
intrigue at ozemail.com.au
Mon Jun 4 08:12:36 EDT 2007
Answering my own question, for future reference...
One way is to add code like the following to the Tcl wrapper code
generated during the build process. Each of the concrete vtkDataArray
subclasses may be extended in this way. The SetValuesBinary command
takes a Tcl binary string and inserts it into an existing, allocated
array at a nominated offset. Parameters are offset and count (in the
array's native units) and the string. The GetValuesBinary command
returns a binary string containing a nominated number of values, from a
nominated offset in the array. Parameters are offset and count.
if ((!strcmp("SetValuesBinary",argv[1]))&&(argc == 5))
{
char *temp0;
long temp1;
long temp2;
error = 0;
if (Tcl_GetInt(interp,argv[2],&tempi) != TCL_OK) error = 1;
temp1 = tempi;
if (Tcl_GetInt(interp,argv[3],&tempi) != TCL_OK) error = 1;
temp2 = tempi;
temp0 = argv[4];
if (!error)
{
double *pix = op->WritePointer(temp1,temp2);
long len = sizeof(double) * temp2;
memcpy((char*)pix,temp0,len);
Tcl_ResetResult(interp);
}
return TCL_OK;
}
if ((!strcmp("GetValuesBinary",argv[1]))&&(argc == 4))
{
error = 0;
long temp1;
long temp2;
error = 0;
if (Tcl_GetInt(interp,argv[2],&tempi) != TCL_OK) error = 1;
temp1 = tempi;
if (Tcl_GetInt(interp,argv[3],&tempi) != TCL_OK) error = 1;
temp2 = tempi;
if (!error)
{
double *pix = op->WritePointer(temp1,temp2);
long len = sizeof(double) * temp2;
Tcl_Obj *obj = Tcl_NewStringObj((char*)pix,len);
Tcl_SetObjResult(interp, obj);
}
else
{
Tcl_ResetResult(interp);
}
return TCL_OK;
}
Erin McKay
Lead Programmer & Tea Boy
Computerhead
More information about the vtkusers
mailing list