<div dir="ltr">Hi Matthieu,<div><br></div><div>I'm not sure if there is a templated array factory in VTK to do this.<br><div><br></div><div>You could make specialized templated utility functions specialized for each of your types, e.g. (not tested):</div><div><br></div><div>template <typename T></div><div>int GetVTKType(T *)</div><div>{</div><div>  return 0;</div><div>}</div><div><br></div><div>template <></div><div>int GetVTKType(int *)</div><div>{</div><div>  return VTK_INT;</div><div>}</div><div><br></div><div>template <></div><div>int GetVTKType(float* )</div><div>{</div><div>  return VTK_FLOAT;</div><div>}</div><div><br></div><div>and so on, then use this to create the right type of array in a switch statement:</div><div><br></div><div>int arrayType = GetVTKType();</div><div>switch (arrayType)</div><div>{</div><div>  case VTK_INT:</div><div>    return vtkIntArray::New();</div><div>    break;</div><div><br></div><div>  case VTK_FLOAT:</div><div>    return vtkFloatArray::New();</div><div>    break;</div><div><br></div><div>  default:</div><div>    //...</div><div>}</div></div><div><br></div><div>HTH,</div><div>Cory</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 7, 2016 at 7:08 AM, Matthieu Heitz <span dir="ltr"><<a href="mailto:heitz.matthieu@gmail.com" target="_blank">heitz.matthieu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi all !<br><br></div>I have a template class myClass<T>, where T can be a scalar (float, int, double, etc.)<br></div>I would like to create a vtkFloatArray, vtkIntArray, or vtkDoubleArray, depending on the type T.<br></div>I thought that vtkDataArrayTemplate<T> would be a good solution.<br></div>Unfortunately, it is a virtual class, so I can't write this :<br><br>vtkSmartPointer< vtkDataArrayTemplate<T> > array =  vtkSmartPointer<vtkDataArrayTemplate<T> >::New();<br><div><br></div><div>because when I try to instantiate a myClass<float>, I get the error :<br><br>error: invalid conversion from ‘vtkObject*’ to ‘vtkDataArrayTemplate<float>*’ [-fpermissive]<br><br></div><div>So
 my question is: Is there an non-virtual version of vtkDataArrayTemplate
 that would allow me to create a vtkFloatArray when T is float, 
vtkDoubleArray when T is double, etc.<br><br></div><div>P.S: I use VTK 6.0.0<br></div><div><br></div>Thank you !<div><div><img src="https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif"></div></div><span class="HOEnZb"><font color="#888888"><div><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Matthieu Heitz<br></div></div></div></div></div></div></div>
</font></span></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</div>