David,<br><br>if you are using dataNormals then you can use GetComponent() function to retrieve the normals . This always returns double so you dont really need to know the type . But in case you want to make the class depending on type, I think you can switch using the GetDataTypeAsString function.<br>
<br>Darshan<br><br><div class="gmail_quote">On Sun, Aug 22, 2010 at 11:49 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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>
<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>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br>