[vtkusers] Non-virtual version of vtkDataArrayTemplate

Cory Quammen cory.quammen at kitware.com
Thu Apr 7 09:35:44 EDT 2016


Hi Matthieu,

I'm not sure if there is a templated array factory in VTK to do this.

You could make specialized templated utility functions specialized for each
of your types, e.g. (not tested):

template <typename T>
int GetVTKType(T *)
{
  return 0;
}

template <>
int GetVTKType(int *)
{
  return VTK_INT;
}

template <>
int GetVTKType(float* )
{
  return VTK_FLOAT;
}

and so on, then use this to create the right type of array in a switch
statement:

int arrayType = GetVTKType();
switch (arrayType)
{
  case VTK_INT:
    return vtkIntArray::New();
    break;

  case VTK_FLOAT:
    return vtkFloatArray::New();
    break;

  default:
    //...
}

HTH,
Cory

On Thu, Apr 7, 2016 at 7:08 AM, Matthieu Heitz <heitz.matthieu at gmail.com>
wrote:

> Hi all !
>
> I have a template class myClass<T>, where T can be a scalar (float, int,
> double, etc.)
> I would like to create a vtkFloatArray, vtkIntArray, or vtkDoubleArray,
> depending on the type T.
> I thought that vtkDataArrayTemplate<T> would be a good solution.
> Unfortunately, it is a virtual class, so I can't write this :
>
> vtkSmartPointer< vtkDataArrayTemplate<T> > array =
> vtkSmartPointer<vtkDataArrayTemplate<T> >::New();
>
> because when I try to instantiate a myClass<float>, I get the error :
>
> error: invalid conversion from ‘vtkObject*’ to
> ‘vtkDataArrayTemplate<float>*’ [-fpermissive]
>
> 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.
>
> P.S: I use VTK 6.0.0
>
> Thank you !
> Matthieu Heitz
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160407/774b728d/attachment.html>


More information about the vtkusers mailing list