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">&lt;<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>&gt;</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 &lt;vtkSmartPointer.h&gt;</div><div>
#include &lt;vtkPointData.h&gt;</div>
<div>#include &lt;vtkSphereSource.h&gt;</div><div>#include &lt;vtkPolyDataNormals.h&gt;</div><div>#include &lt;vtkDataArray.h&gt;</div><div>#include &lt;vtkDoubleArray.h&gt;</div><div>#include &lt;vtkFloatArray.h&gt;</div>

<div><br></div><div>int main(int, char *[])</div><div>{</div><div>  vtkSmartPointer&lt;vtkSphereSource&gt; sphereSource =</div><div>    vtkSmartPointer&lt;vtkSphereSource&gt;::New();</div><div>  sphereSource-&gt;Update();</div>

<div><br></div><div>  vtkSmartPointer&lt;vtkPolyDataNormals&gt; polyDataNormals =</div><div>    vtkSmartPointer&lt;vtkPolyDataNormals&gt;::New();</div><div>  polyDataNormals-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());</div>

<div>  polyDataNormals-&gt;Update();</div><div><br></div><div>  vtkDoubleArray* doubleNormals =</div><div>    vtkDoubleArray::SafeDownCast(polyDataNormals-&gt;GetOutput()-&gt;GetPointData()-&gt;GetNormals());</div><div><br>

</div><div>  if(doubleNormals)</div><div>    {</div><div>    std::cout &lt;&lt; &quot;Has double normals&quot; &lt;&lt; std::endl;</div><div>    }</div><div>    </div><div>  vtkFloatArray* floatNormals =</div><div>    vtkFloatArray::SafeDownCast(polyDataNormals-&gt;GetOutput()-&gt;GetPointData()-&gt;GetNormals());</div>

<div>  if(floatNormals)</div><div>    {</div><div>    std::cout &lt;&lt; &quot;Has float normals&quot; &lt;&lt; std::endl;</div><div>    }</div><div><br></div><div>  vtkDataArray* dataNormals =</div><div>    vtkDataArray::SafeDownCast(polyDataNormals-&gt;GetOutput()-&gt;GetPointData()-&gt;GetNormals());</div>

<div>  if(dataNormals)</div><div>    {</div><div>    std::cout &lt;&lt; &quot;Has data normals&quot; &lt;&lt; std::endl;</div><div>    double n[3];</div><div>    //dataNormals-&gt;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&#39;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&#39;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>