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

Erin McKay e.mckay at unsw.edu.au
Fri Feb 11 23:32:22 EST 2005


As noted previously, the vtkCharArray can be used with Tcl binary 
strings. But that's not the whole story. Thanks to HV for pointing me 
in the right direction...

There is a SetArray interface in the vtkCharArrayTcl.cxx wrapping code. 
This interface works with the other array types as well but isn't 
included by default. To fix, just cut and paste a (slightly) modified 
version of this interface into each of the vtk*ArrayTcl.cxx files prior 
to making VTK.

Here is the interface modified to suit the vtkFloatArray class. Note 
the reinterpret_cast - this is the only mod required.

   if ((!strcmp("SetArray",argv[1]))&&(argc == 5))
     {
     char    *temp0;
     long     temp1;
     int      temp2;
     error = 0;

     temp0 = argv[2];
     if (Tcl_GetInt(interp,argv[3],&tempi) != TCL_OK) error = 1;
     temp1 = tempi;
     if (Tcl_GetInt(interp,argv[4],&tempi) != TCL_OK) error = 1;
     temp2 = tempi;
     if (!error)
       {
       op->SetArray(reinterpret_cast<float*>(temp0),temp1,temp2);
       Tcl_ResetResult(interp);
       return TCL_OK;
       }
     }

Now, wouldn't it be nice if the wrapper generator did this for us?

Erin McKay
Senior Physicist
Dept. Nuclear Medicine, St. George Hospital
Sydney, Australia




More information about the vtkusers mailing list