VTK9 create different stencil than vtk8

Hello,
I am having some weird results while trying to update my VTK.

I am converting a VTK polydata to Image data with the following code:
vtkSmartPointer VtkPolyDataToImage(vtkPolyData* poly, vtkImageData* templateImage)
{
vtkSmartPointer image = vtkSmartPointer::New();
image->DeepCopy(templateImage);

// fill the image with foreground voxels:
short inval = 1;
short outval = 0;
vtkIdType count = templateImage->GetNumberOfPoints();
for (vtkIdType i = 0; i < count; ++i)
{
image->GetPointData()->GetScalars()->SetTuple1(i, inval);
}

// polygonal data → image stencil:
vtkSmartPointer pol2stenc =
vtkSmartPointer::New();
pol2stenc->SetInputData(poly);
pol2stenc->SetOutputOrigin(image->GetOrigin());
pol2stenc->SetOutputSpacing(image->GetSpacing());
pol2stenc->SetOutputWholeExtent(image->GetExtent());
pol2stenc->Update();

// cut the corresponding white image and set the background:
vtkSmartPointer imgstenc = vtkSmartPointer::New();
imgstenc->SetInputData(image);
imgstenc->SetStencilConnection(pol2stenc->GetOutputPort());
imgstenc->ReverseStencilOff();
imgstenc->SetBackgroundValue(outval);
imgstenc->Update();

vtkSmartPointer outputImage = imgstenc->GetOutput();
return outputImage;
}

However, After upgrading the created image is different (like 0.2 max difference).

Do you have any idea about what could the issue here ? Is it a known issue ?

Thanks in advance

Can you explain what you mean by “0.2 max difference”? I don’t understad what the “0.2” refers to.

The vtkPolyDataToImageStencil class has only been stylistically modified between VTK 8.2.0 and VTK 9.2.5. The algorithm hasn’t changed.

Sure ! I remeshed the image back to an STL and computed the difference between the 2 meshes (vtk 8 one and vtk9 one) (point by point euclidean distance). That is what gave me the 0.2 difference.

You weren’t directly comparing the images to each other? What did you use to do the remeshing? And what was the voxel spacing?

No I did not because I first saw the error on remeshed STL’s and I did not think about the meshing part… Which will also be impacted by that vtk9 → vtk9 upgrade

here is the code used to remesh the image : Meshing code text code | WTOOLS (using marching cube)

Voxel spacing is 0.15

The vtkQuadricDecimation filter has definitely been changed since VTK 8.2.

To check vtkPolyDataToImageStencil, please do a voxel-by-voxel comparison of the image outputs. Or if that isn’t possible, then compare the vtkMarchingCubes meshes without decimating them first.

Perfect thanks a lot for your help ! Hopefully that will provide some new information and perhaps a solution.