That's not a C++ cast, that's a transformation operation....<div><br></div><div>All the array classes are siblings of each other, aren't they?<br><div><br><br><div class="gmail_quote">On Fri, Sep 17, 2010 at 3:47 PM, David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><span style="font-family:arial, sans-serif;font-size:12.5px;border-collapse:collapse">I've found it very troublesome not to be able to cast similar typed arrays back and forth.<div>

<br></div><div>For example, vtkIdTypeArray as vtkIntArray, or vtkFloatArray as vtkDoubleArray.<div><br>Here is my usual process:</div><div><br></div><div>1) Use a filter that produces an array on the output</div><div><br>


</div><div>2) Write a file of the filter output</div><div><br></div><div>3) Open Paraview and open the file to figure out what the array name that was created is and what type it is</div><div><br></div><div>4) Note that paraview shows a data array named "RegionId" (I used vtkPolyDataConnectivityFilter) and that its Data Type is "int" (very confusing, because it is actually vtkIdType...)</div>


<div><br></div><div>5) Go back to my VTK code and do this:</div><div><br></div><div>vtkIntArray::SafeDownCast(filter->GetOutput()->GetArray("RegionId"))->DoSomething();</div><div><br></div><div>6) My program starts crashing unexpectedly.</div>


<div><br></div><div>7) I go back to this line and do</div><div>vtkIntArray* array = vtkIntArray::SafeDownCast(filter->GetOutput()->GetArray("RegionId"));</div><div>std::cout << array << std::endl;</div>


<div><br></div><div>and notice that it is NULL.</div><div><br></div><div>8) Look through vtkPolyDataConnectivity.cxx and realize that this array is a vtkIdTypeArray</div><div><br></div><div>It would make a lot of sense from a usability standpoint to allow reasonable casts and if they aren't exactly right provide a warning of what happened. In this case, "Warning, you have casted a vtkIdTypeArray to a vtkIntArray", or in other cases, "Warning, you have casted a vtkFloatArray to a vtkDoubleArray". I would even advocate that it is ok even to do "Warning: You have casted a vtkDoubleArray to a vtkFloatArray, some loss of precision may occur."</div>


<div><br></div><div><div>Thoughts?<br><font color="#888888"><br>David</font></div></div></div></span>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
<br>
<br></blockquote></div><br></div></div>