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

frank frank1985876 at gmail.com
Tue Nov 7 02:50:21 EST 2017


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!



More information about the vtkusers mailing list