[vtkusers] loading string field data

David Lonie david.lonie at kitware.com
Tue Oct 4 13:01:24 EDT 2016


For VTK arrays, GetSize() is analogous to std::vector::capacity() -- ie. it
returns the size of the allocated memory buffer, not the number of elements
in the array (confusing, I know :( ).

Use GetNumberOfTuples() + GetNumberOfComponents(), or GetNumberOfValues()
for the actual number of elements in the array.

Cheers,
Dave

On Mon, Oct 3, 2016 at 4:43 PM, Eszter Fehér <fehereszter at gmail.com> wrote:

> Dear Users,
>
> I have a problem with string field data loading from ascii vtk files in
> c++. The file content is loaded to a vtkPolyData object from which I try to
> get the array of the string field data using the following:
>
> vtkSmartPointer<vtkStringArray> array = vtkStringArray::
> vtkSafeDownCast(polydata->GetFieldData()->GetAbstractArray("strname",i));
>
> The field data in the vtk file is like:
> FIELD FieldData 1
> strname 1 4 string
> a
> b
> c
> d
>
> The problem is that the size of "array" (array->GetSize()) in the case
> above is 7 and all the elements 4..7 are empty and cause segfault if I try
> to read them.
> The size of the array depends on the actual number of string values but it
> is really confusing:
> actual size array->GetSize()
> 1 1
> 2 3
> 3 3
> 4 7
> 5 7
> 6 7
> 7 7
> 8 15
> 9 15What am I doing wrong?
> I use vtk7.0.0.
>
> Any help would be much appreciated.
>
> Regards, Eszter
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161004/26957fc8/attachment.html>


More information about the vtkusers mailing list