There are often cases when I am not sure if an array is going to be a vtkDoubleArray or a vtkFloatArray.<div><br></div><div>Take this code for example:<div><br></div><div><div>#include <vtkSmartPointer.h></div><div>#include <vtkPointData.h></div>
<div>#include <vtkSphereSource.h></div><div>#include <vtkPolyDataNormals.h></div><div>#include <vtkDataArray.h></div><div>#include <vtkDoubleArray.h></div><div>#include <vtkFloatArray.h></div>
<div><br></div><div>int main(int, char *[])</div><div>{</div><div> vtkSmartPointer<vtkSphereSource> sphereSource =</div><div> vtkSmartPointer<vtkSphereSource>::New();</div><div> sphereSource->Update();</div>
<div><br></div><div> vtkSmartPointer<vtkPolyDataNormals> polyDataNormals =</div><div> vtkSmartPointer<vtkPolyDataNormals>::New();</div><div> polyDataNormals->SetInputConnection(sphereSource->GetOutputPort());</div>
<div> polyDataNormals->Update();</div><div><br></div><div> vtkDoubleArray* doubleNormals =</div><div> vtkDoubleArray::SafeDownCast(polyDataNormals->GetOutput()->GetPointData()->GetNormals());</div><div><br>
</div><div> if(doubleNormals)</div><div> {</div><div> std::cout << "Has double normals" << std::endl;</div><div> }</div><div> </div><div> vtkFloatArray* floatNormals =</div><div> vtkFloatArray::SafeDownCast(polyDataNormals->GetOutput()->GetPointData()->GetNormals());</div>
<div> if(floatNormals)</div><div> {</div><div> std::cout << "Has float normals" << std::endl;</div><div> }</div><div><br></div><div> vtkDataArray* dataNormals =</div><div> vtkDataArray::SafeDownCast(polyDataNormals->GetOutput()->GetPointData()->GetNormals());</div>
<div> if(dataNormals)</div><div> {</div><div> std::cout << "Has data normals" << std::endl;</div><div> double n[3];</div><div> //dataNormals->GetTupleValue(0,n); //this does not work</div>
<div> }</div><div> </div><div>// the following code will work whether the array was doubles or floats, I just need to be able to call GetTupleValue (and get a float or a double, I don't care which)</div><div><br>
</div><div>// ....</div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div></div><div><br></div><div>The normals are a vtkFloatArray, so the vtkDoubleArray cast fails. Since both vtkDoubleArray and vtkFloatArray derive from vtkDataArray, I thought I could get the array as a vtkDataArray, but then GetTupleValue function is not defined because it doesn't know what type the array is!</div>
<div><br></div><div>Can anyone share how you handle situations like this?</div><div><br></div><div>Thanks,<br><br>David<br>
</div></div>