[vtk-developers] Casting vtkIntArray vs vtkIdTypeArray
David Doria
daviddoria at gmail.com
Fri Sep 17 15:47:26 EDT 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtk-developers/attachments/20100917/2e6a2444/attachment.htm>
More information about the vtk-developers
mailing list