[vtkusers] how to create a vtkDataSet according to the type of the input

David E DeMarle dave.demarle at kitware.com
Tue Nov 7 06:05:36 EST 2017


Try data->NewInstance()

On Nov 7, 2017 3:03 AM, "frank" <frank1985876 at gmail.com> wrote:

> Hi, all
>
> If I want to create a vtkDataSet according to type of the input
> (vtkDataSet*), I can do that with the code below.
> Is there any way to get rid of those if-else? Any way like vtkDataArray
> do? vtkDataArray* a = vtkDataArray::CreateDataArray(array->GetDataType());
>
> //----------------
> vtkDataSet *data;
> if (input->IsA("vtkImageData"))
>     data = vtkImageData::New();
> else if (input->IsA("vtkStructuredGrid"))
>     data = vtkStructuredGrid::New();
>> //----------------
>
> Thank you!
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171107/af93a57c/attachment.html>


More information about the vtkusers mailing list