Using vtkArrayCalculator to get a Vector Field from three Scalars (C++)

I have a vti Data with three Scalar Arrays and I am stuck, this is what I have done so far:

xmlImageDataReader->SetFileName(sFilename.c_str());
xmlImageDataReader->Update();

imageDataGeometryFilter->SetInputConnection(xmlImageDataReader->GetOutputPort());
imageDataGeometryFilter->Update();
imageDataGeometryFilter->GetOutput()->GetPointData()->GetArray(0)->SetName(“u”);
imageDataGeometryFilter->GetOutput()->GetPointData()->GetArray(1)->SetName(“v”);
imageDataGeometryFilter->GetOutput()->GetPointData()->GetArray(2)->SetName(“w”);
imageDataGeometryFilter->Update();

arrayCalc->AddScalarArrayName(“u”);
arrayCalc->AddScalarArrayName(“v”);
arrayCalc->AddScalarArrayName(“w”);

arrayCalc->SetResultArrayName(“Vector”);
arrayCalc->SetFunction(“uiHat+vjHat+w*kHat”);

After that I wanted to add the Vector array and set it as active.

I would appreciate any help!
Thanks in advance

Check out Filters/General/vtkMergeVectorComponents.h - I think it’ll do what you want.

I get this Error Message if I try to include it:“vtkMergeVectorComponents.h”: No such file or directory.

But it seems that is excactly what i would need.

I want this as my result, so i can add Glyphfilter and Streamlinefilter in VTK.

Thank you for your fast reply

I got the vector I wanted with the following line: dataArray=arrayCalc->GetDataSetOutput()->GetPointData()->GetArray(“Vector”);

1 Like