ActiViz/C# can't create a new vtkDataArray

Hi,

I’m trying to visualize a scalar field on an unstructured grid. I already managed to build and visualize an vtkUnstructuredGrid where Points and Cells where defined. Now I want to “plot” a scalar field on that grid…
For this, I think the easiest way is to do the following:

myVtkUnstructuredGrid.GetPointData().SetScalars(myScalarData);

The problem is ‘myScalarData’ needs to be an vtkDataArray. However I cannot create a new instance of this object. I tried the following, and they all give errors:

vtkDataArray myScalarData = new vtkDataArray();
vtkDataArray myScalarData = vtkDataArray.New();
vtkDataArray myScalarData = (vtkDataArray)vtkObject.New();

What am I doing wrong?

vtkDataArray is a pure abstract superclass of the type-specific data arrays such as vtkFloatArray, vtkDoubleArray, etc., hence you cannot instantiate it. Create one of these array type subclasses instead, and you should have better luck.

Thank you so much, that worked.

You are welcome :slight_smile: