Skip to content

Fix EvaluatePosition logic in vtkCell to handle boundary conditions

Florian Maurin requested to merge florian360/vtk:EvaluatePosition into master

In the EvaluatePosition function for nonlinear vtkCell classes, the function divides a nonlinear cell into several linear subcells. It then checks each subcell to determine if a point is inside. If not, the function also calculates the distance between the point and the boundary of the subcell. It can sometimes happen that a point is slightly outside of a subcell, but the computed distance from the boundary is zero due to numerical inaccuracies.

Within EvaluatePosition, the process iterates over all subcells, recording the subcell if the distance between the point and the subcell boundary is strictly smaller than any previously recorded distance.

Consider a scenario where a nonlinear cell is divided into two subcells, with a point positioned on the second subcell, but almost at the boundary with the first subcell (let say at a distance of 1e-16) :

  • The point is outside the first subcell, but due to numerical precision, the distance computed is zero.
  • The point is inside the second subcell ( distance of zero ).

Since the second sub cell has not a distance strictly smaller that the first one, only the first subcell is recorded. Consequently, EvaluatePosition incorrectly returns that the point is outside the nonlinear cell, potentially leading to erroneous outputs, such as NaN values from a vtkProbeFilter.

To address this issue, the solution involves adding a check to prioritize a subcell where the point is marked inside if the distances are equal.

fix: #19341 (closed)

Edited by Florian Maurin

Merge request reports