[vtk-developers] Casting vtkIntArray vs vtkIdTypeArray

David Cole david.cole at kitware.com
Fri Sep 17 15:50:23 EDT 2010


That's not a C++ cast, that's a transformation operation....

All the array classes are siblings of each other, aren't they?


On Fri, Sep 17, 2010 at 3:47 PM, David Doria <daviddoria at gmail.com> wrote:

> I've found it very troublesome not to be able to cast similar typed arrays
> back and forth.
>
> For example, vtkIdTypeArray as vtkIntArray, or vtkFloatArray as
> vtkDoubleArray.
>
> Here is my usual process:
>
> 1) Use a filter that produces an array on the output
>
> 2) Write a file of the filter output
>
> 3) Open Paraview and open the file to figure out what the array name that
> was created is and what type it is
>
> 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...)
>
> 5) Go back to my VTK code and do this:
>
>
> vtkIntArray::SafeDownCast(filter->GetOutput()->GetArray("RegionId"))->DoSomething();
>
> 6) My program starts crashing unexpectedly.
>
> 7) I go back to this line and do
> vtkIntArray* array =
> vtkIntArray::SafeDownCast(filter->GetOutput()->GetArray("RegionId"));
> std::cout << array << std::endl;
>
> and notice that it is NULL.
>
> 8) Look through vtkPolyDataConnectivity.cxx and realize that this array is
> a vtkIdTypeArray
>
> 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."
>
> Thoughts?
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100917/369d2bb2/attachment.html>


More information about the vtk-developers mailing list