[vtkusers] Accessing vtkPolyData scalars with Python

David Doria daviddoria at gmail.com
Wed Feb 15 11:47:40 EST 2012


On Wed, Feb 15, 2012 at 11:38 AM, bberkowi <benjamin-berkowitz at uiowa.edu>wrote:

> OK, so if anyone can just help in general, it doesn't have to be with
> Python
> syntax (but it would be helpful).  This is what I have so far, and it's not
> working:
>
>    distanceMapper.Surface.GetPointData().SetActiveScalars('Scalars_')
>    distanceArray = distanceMapper.Surface.GetPointData().GetScalars()
>
>    #print 'DISTANCE SURFACE:',  distanceMapper.Surface
>
>    print 'DISTANCE ARRAY:',  distanceArray
>    tuple = []
>    tuple = distanceArray.GetTuple(0)
>    print tuple
>
> and GetTuple() doesn't work.  It returns an error, "Traceback (most recent
> call last):
>  File "VTK_testing.py", line 80, in <module>
>    tuple = distanceArray.GetTuple(0)
> AttributeError: GetTuple"
>

If you don't know what type to expect, then you have to assume double (that
is how VTK works):

vtkDataArray* array = polydata->GetCellData()->GetScalars();
double value[array->GetNumberOfComponents()];
array->GetTupleValue(value);

If you do know what type to expect, you can use that type:

vtkIntArray* array =
vtkIntArray::SafeDownCast(polydata->GetCellData()->GetScalars());
int value[array->GetNumberOfComponents()];
array->GetTupleValue(value);

Deleting the cells is a whole separate problem entirely - I think the
accepted practice is just to flag which ones you want to delete and
recreate the topology only using those cells (skipping adding the ones that
you wanted to delete). You can also use something like
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ExtractSelectionCells but
the syntax gets very confusing.

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120215/df9e522f/attachment.htm>


More information about the vtkusers mailing list