[vtkusers] Low level access to Array data (OK, here's a patch suggestion)

Lisa Avila lisa.avila at kitware.com
Sun Jun 15 22:31:11 EDT 2003


Hello,

You cannot patch any *Tcl.cxx code - this is automatically generated code. 
The change must be made down in the wrapping code.

Lisa



At 09:05 PM 6/13/2003, H.Vidal, Jr. wrote:
>So it would be nice to have pointer level access to things
>like the vtkIntArray from tcl. This is handy for a situation where
>array data will be loaded from acquisition device for analysis under vtk.
>Anyway, this works in tcl for vtkCharArray like this:
>
>vtkCharArray c
>c SetNumberOfValues 100
>set p [ c GetPointer 0]
>
>Now $p will eval to the raw contents of c because a pointer to a char
>array in tcl is how tcl thinks. So I guess this is why vtk developers
>left GetPointer in methods supported for vtkCharArray under tcl.
>However, as mentioned in other posts, this was not case for vtkIntArray.
>I still have not figured out how a tcl implementation of a C++ object is
>created, but I do know that, once created, you can patch and rebuild vtk
>sources as in:
>
>So vtkIntArrayTcl.cxx is the implementation of vtkIntArray under tcl.
>
>if you patch it thusly (skip the copious comments, if you like...):
>
>0a1,4
> > // 12-Jun-03 HCV/TT
> > //  1. add GetPointer Method functionality cribbed from existing
> > //     vtkCharArrayTcl.cxx infrastructure
> > //
>327a332,359
> >
> > // HCV/TT: add GetPointer handler
> > //
> >   if((!strcmp("GetPointer",argv[1])) && (argc==3))
> >    {
> >     char tempResult[100];
> >     long temp0;
> >     int *temp20;
> >     error = 0;
> >
> >     if(Tcl_GetInt(interp,argv[2],&tempi) != TCL_OK) error = 1;
> >     temp0 = tempi;
> >     if(!error)
> >      {
> >       temp20 = op->GetPointer(temp0);
> >       if(temp20)
> >        {
> >         sprintf(tempResult,"%p",(void *)temp20);
> >         Tcl_SetResult(interp, tempResult, TCL_VOLATILE);
> >        }
> >       else
> >        {
> >         Tcl_ResetResult(interp);
> >        }
> >       return TCL_OK;
> >      }
> >    }
> >
>429a462
> >     Tcl_AppendResult(interp,"  GetPointer\t with 1 args\n",NULL);
>
>You can then do things like:
>
>vtkIntArray i
>i SetNumberOfValues 100
>set p [ i GetPointer 0]
>RxIntPointer $p
>
>If RxIntPointer looks (in C) kind of like this:
>
>void RxIntPointer(char *pcIn)
>{
>   int *pI;
>
>   if(!sscan(pcIn,"%p",&pI))
>    return;
>
>   (now access raw data via *pI indirection)
>
>
>presumably, if this kind of voodoo is applied to all vtk<thingy>Array
>code, everywhere high speed I/O to raw data is possible. Woo hoo!!
>
>have fun.
>
>hv
>
>
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: 
><http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers






More information about the vtkusers mailing list