Hello,
I am using to calculate the gradient of each vertex in an unstructured grid. I followed this example and made some changes: https://gitlab.kitware.com/vtk/vtk/-/blob/v9.2.0/Accelerators/Vtkm/Filters/Testing/Cxx/TestVTKMGradient.cxx
But my codes always gives me segmentation fault when i want to access the gradient data(with the type of vtkDoubleArray*)
int main()
{
vtkNew<vtkXMLUnstructuredGridReader> reader;
reader->SetFileName("testInput.vtu");
reader->Update();
vtkNew<vtkGradientFilter> gradientFilter;
gradientFilter->SetInputConnection(reader->GetOutputPort());
gradientFilter->SetInputScalars(vtkDataObject::FIELD_ASSOCIATION_POINTS, "scalars");
gradientFilter->SetResultArrayName("gradient");
gradientFilter->Update();
vtkDoubleArray* gradientArray =
vtkArrayDownCast<vtkDoubleArray>(vtkDataSet::SafeDownCast(gradientFilter->GetOutput())
->GetPointData()
->GetArray("gradient"));
// seg fault here!
gradientArray->GetNumberOfComponents();
}
testInput.vtu (1.0 KB)
Thank you in advance!