[vtk-developers] Adding a vtkDataArray::ExportToVoidPointer

Prabhu Ramachandran prabhu_r at users.sf.net
Wed Jul 20 14:32:34 EDT 2005


Hi,

I have a simple implementation of
vtkDataArray::ExportToVoidPointer as suggested by Tuhin Sinha here:

 http://public.kitware.com/pipermail/vtkusers/2004-August/075852.html

Basically, I plan to add the following to vtkDataArrayTemplate.txx
(along with the code needed in the header and in vtkDataArray.h):

+//----------------------------------------------------------------------------
+template <class T>
+void vtkDataArrayTemplate<T>::ExportToVoidPointer(void *out_ptr)
+{
+  if(out_ptr && this->Array) 
+    {
+    memcpy(static_cast<T*>(out_ptr), this->Array, 
+           (this->MaxId + 1)*sizeof(T));
+    }
+}
+

This allows someone to do the following:

    >>> import vtk, Numeric
    >>> f = vtk.vtkFloatArray()
    >>> for i in range(10): f.InsertNextValue(i*i)
    ...
    >>> a = Numeric.zeros(10, 'f')
    >>> f.ExportToVoidPointer(a)
    >>> print a
    [  0.   1.   4.   9.  16.  25.  36.  49.  64.  81.]
    
Rather than have to go through ImageExport/ImageImport.

If no one has any objections I can check this in.

cheers,
prabhu



More information about the vtk-developers mailing list