<div dir="ltr">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 :( ).<div><br></div><div>Use GetNumberOfTuples() + GetNumberOfComponents(), or GetNumberOfValues() for the actual number of elements in the array.</div><div><br></div><div>Cheers,</div><div>Dave</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 3, 2016 at 4:43 PM, Eszter FehĂ©r <span dir="ltr"><<a href="mailto:fehereszter@gmail.com" target="_blank">fehereszter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><span>Dear Users,</span><br><span></span><br><span>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:</span><br><span></span><br><span>vtkSmartPointer<<wbr>vtkStringArray> array = vtkStringArray::<wbr>vtkSafeDownCast(polydata-><wbr>GetFieldData()-><wbr>GetAbstractArray("strname",i))<wbr>;</span><br><span></span><br><span>The field data in the vtk file is like:</span><br><span>FIELD FieldData 1</span><br><span>strname 1 4 string</span><br><span>a</span><br><span>b</span><br><span>c</span><br><span>d</span><br><span></span><br><span>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. </span><br><span>The size of the array depends on the actual number of string values but it is really confusing:</span><br><span></span><table cellspacing="0" border="0"><colgroup width="85"></colgroup><colgroup width="114"></colgroup><tbody><tr><td height="17" align="left" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">actual size</span></td><td align="left" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">array->GetSize()</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">1</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">1</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">2</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">3</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">3</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">3</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">4</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">7</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">5</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">7</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">6</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">7</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">7</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">7</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">8</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">15</span></td></tr><tr><td height="17" align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">9</span></td><td align="right" style="border:1px solid rgb(0,0,0)"><span style="background-color:rgba(255,255,255,0)">15</span></td></tr></tbody></table>What am I doing wrong?</div><div>I use vtk7.0.0.</div><div><br></div><div>Any help would be much appreciated.</div><div><br></div><div>Regards, Eszter</div></div><br>______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>