API Reference for Enthought Tool Suite 3.2.0
This module contains all the array handling code for TVTK.
The most important functions provided by this module involve the conversion of numpy arrays/Python lists to different VTK data arrays and vice-versa.
Warning: Numpy Character arrays will not work properly since there seems no unique one-to-one VTK data array type to map it to.
BASE_REFERENCE_COUNT = vtk.vtkObject().GetReferenceCount()
Useful constants for VTK arrays.
VTK_ID_TYPE_SIZE = vtk.vtkIdTypeArray().GetDataTypeSize()
VTK_LONG_TYPE_SIZE = vtk.vtkLongArray().GetDataTypeSize()
Converts a real numpy Array (or a Python list) to a VTK array object.
This function only works for real arrays. Complex arrays are NOT handled. It also works for multi-component arrays. However, only 1, and 2 dimensional arrays are supported. This function is very efficient, so large arrays should not be a problem.
Even in cases when no copy of the numpy array data is performed, a reference to the array is cached. The passed array can therefore be deleted safely in all circumstances.
num_array : numpy array or Python list/tuple
The input array must be 1 or 2D. A copy of the numeric array data passed is made in the following circumstances:
- A Python list/tuple was passed.
- A non-contiguous numpy array was passed.
- A vtkBitArray instance was passed as the second argument.
- The types of the vtk_array and the num_array are not equivalent to each other. For example if one is an integer array and the other a float.
vtk_array : vtkDataArray (default: None)
If an optional vtkDataArray instance, is passed as an argument then a new array is not created and returned. The passed array is itself returned.
Given a nested Python list or a numpy array, this method creates a vtkCellArray instance and returns it.
A variety of input arguments are supported as described in the Parameter documentation. If numpy arrays are given, this method is highly efficient. This function is most efficient if the passed numpy arrays have a typecode ID_TYPE_CODE. Otherwise a typecast is necessary and this involves an extra copy. This method always copies the input data.
An alternative and more efficient way to build the connectivity list is to create a vtkIdTypeArray having data of the form (npts,p0,p1,...p(npts-1), repeated for each cell) and then call <vtkCellArray_instance>.SetCells(n_cell, id_list).
num_array : numpy array or Python list/tuple
Valid values are:
- A Python list of 1D lists. Each 1D list can contain one cell connectivity list. This is very slow and is to be used only when efficiency is of no consequence.
- A 2D numpy array with the cell connectivity list.
- A Python list of 2D numpy arrays. Each numeric array can have a different shape. This makes it easy to generate a cell array having cells of different kinds.
vtk_array : vtkCellArray (default: None)
If an optional vtkCellArray instance, is passed as an argument then a new array is not created and returned. The passed array is itself modified and returned.
>>> a = [[0], [1, 2], [3, 4, 5], [6, 7, 8, 9]] >>> cells = array_handler.array2vtkCellArray(a) >>> a = numpy.array([[0,1,2], [3,4,5], [6,7,8]], 'l') >>> cells = array_handler.array2vtkCellArray(a) >>> l_a = [a[:,:1], a[:2,:2], a] >>> cells = array_handler.array2vtkCellArray(l_a)
Converts a numpy array/Python list to a vtkIdList object.
num_array : numpy array or Python list/tuple
The input array must be 2D with shape[1] == 3.
vtk_idlist : vtkIdList (default: None)
If an optional vtkIdList instance, is passed as an argument then a new array is not created and returned. The passed array is itself modified and returned.
Converts a numpy array/Python list to a vtkPoints object.
Unless a Python list/tuple or a non-contiguous array is given, no copy of the data is made. Thus the function is very efficient.
num_array : numpy array or Python list/tuple
The input array must be 2D with shape[1] == 3.
vtk_points : vtkPoints (default: None)
If an optional vtkPoints instance, is passed as an argument then a new array is not created and returned. The passed array is itself modified and returned.
Convert the given array to the optional type specified by vtk_typ.
Internal function used to create a VTK data array from another VTK array given the VTK array type.
Given a bunch of arguments and optional signature information, this converts the arguments suitably. If the argument is either a Python list or a numpy array it is converted to a suitable type based on the signature information. If it is not an array, but a TVTK object the VTK object is dereferenced. Otherwise nothing is done. If no signature information is provided the arrays are automatically converted (this can sometimes go wrong). The signature information is provided in the form of a list of lists.
Dereferences the VTK object from the object if possible. This is duplicated from tvtk_base.py because I'd like to keep this module independent of tvtk_base.py.
Given a list of args and a collection of possible signatures, this function returns the most appropriate signature. This function is only called by deref_array. This implies that one of the signatures has an array type.
Returns a numpy array typecode given a VTK array type.
Returns the size of a VTK array type.
Returns a VTK typecode given a numpy array.
Returns the VTK array type to numpy array type mapping.
Returns True if the passed arr is a numpy array or a List.
Returns True if the argument is an array/Python list or if it is a vtk array.
Given a signature, return if the signature has an array.
Converts a VTK data array to a numpy array.
Given a subclass of vtkDataArray, this function returns an appropriate numpy array containing the same data. The function is very efficient since it uses the VTK imaging pipeline to convert the data. If a sufficiently new version of VTK (5.2) is installed then it actually uses the buffer interface to return a view of the VTK array in the returned numpy array.
vtk_array : vtkDataArray
The VTK data array to be converted.
| Local name | Refers to |
|---|---|
| numpy | numpy |
| set_id_type_array | enthought.tvtk.array_ext.set_id_type_array |
| sys | sys |
| types | types |
| vtk | vtk |
| vtkConstants | vtk.util.vtkConstants |
© Copyright 2002-2009 Enthought, Inc.