Hello,
I am working in a vtkUnstructuredGrid containing Wedges and Hexaedrons and want to interpolate a field to a point inside this region.
To do this I use the vtkCellLocator::GetCell funciton and calculate my interpolation using the returned cellId and weights.
In most cases this works great, in some rare cases, the weights I get back are negative, the smallest ones being -5e-04.
Here is a short code to see what I do exactly.
// Create the grid
vtkSmartPointer<vtkUnstructuredGridReader> reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
reader->SetFileName(grid_filename);
reader->Update();
vtkSmartPointer<vtkUnstructuredGrid> grid = reader->GetOutput();
// Create the locator
vtkSmartPointer<vtkCellLocator> locator = vtkSmartPointer<vtkCellLocator>::New();
locator->SetDataSet(grid);
locator->BuildLocator();
// Example point that leads to negative interpolationweights
double point[3] = {3.0554227618270680e-01,1.4144742433817215e-01,1.2424490971455174e-01};
// Get cell and Interpolationweights
double tol2 = 1e-6;
vtkSmartPointer<vtkGenericCell> cell = vtkSmartPointer<vtkGenericCell>::New();
double pcoords[3];
double weights[8] = {0, 0, 0, 0, 0, 0, 0, 0};
vtkIdType cellId = locator->FindCell(point, tol2, cell, pcoords, weights);
The sum of the weights is always 1, so the weights are normalized.
For one cell I could also visually confirm that the correct cellId was returned.
An example for the weights I receive (in this case the cell is a wedge) is:
-4.6036431438310814e-04, 9.0408118410633680e-05, -2.8471462140115263e-04, 5.5147346747578618e-01, 1.0830048505102596e-01, 3.4106153452738280e-01, 0.0000000000000000e+00, 0.0000000000000000e+00
To test edge cases in my grid, I tried the interpolation on the points in the grid.
vtkSmartPointer<vtkPointData> points = grid->GetPointData();
In this case I got some negative weights as well, but none smaller than -1e-10.
What could cause this issue?