vtkRedistributeDataSetFilter dequeues out of bounds (precision error?)
The error:
terminate called after throwing an instance of 'std::runtime_error'
what(): Dequeued 32.0001 outside [0.25,32.0] (0)
terminate called after throwing an instance of 'std::runtime_error'
what(): Dequeued 32.0001 outside [-1.0,32.0] (1)
Looks like a precision issue. This appears to originate in https://gitlab.kitware.com/third-party/diy2/-/blob/master/include/diy/detail/algorithms/kdtree-sampling.hpp#L384
The code leading to the error (input_filepath is a path to a valid dataset exported from ParaView):
inline void vtp_to_pvtp(const std::string& input_filepath, const std::string& output_filepath, const std::int32_t partitions, const bool compress)
{
auto* controller = dynamic_cast<vtkMPIController*>(vtkMultiProcessController::GetGlobalController());
auto data = vtkSmartPointer<vtkPolyData>::New();
if (controller->GetLocalProcessId() == 0)
{
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(input_filepath.c_str());
reader->Update ();
data->ShallowCopy(reader->GetOutput());
}
auto partitioner = vtkSmartPointer<vtkRedistributeDataSetFilter>::New();
partitioner->SetBoundaryMode (vtkRedistributeDataSetFilter::SPLIT_BOUNDARY_CELLS);
partitioner->SetController (controller);
partitioner->SetGenerateGlobalCellIds (false);
partitioner->SetInputData (data);
partitioner->SetNumberOfPartitions (partitions);
partitioner->SetPreservePartitionsInOutput(true);
partitioner->Update ();
auto writer = vtkSmartPointer<vtkXMLPPolyDataWriter>::New();
writer->SetDataModeToBinary ();
writer->SetFileName (output_filepath.c_str());
writer->SetHeaderTypeToUInt64();
writer->SetNumberOfPieces (partitions);
writer->SetWriteSummaryFile (1);
compress ? writer->SetCompressorTypeToZLib() : writer->SetCompressorTypeToNone();
const auto partitioned_data = dynamic_cast<vtkPartitionedDataSet*>(partitioner->GetOutput());
const auto offset = partitions / controller->GetNumberOfProcesses() * controller->GetLocalProcessId();
for (auto i = 0; i < partitioned_data->GetNumberOfPartitions(); ++i)
{
const auto unstructured_grid = dynamic_cast<vtkUnstructuredGrid*>(partitioned_data->GetPartition(i));
auto unstructured_grid_to_poly_data = vtkSmartPointer<vtkGeometryFilter>::New();
unstructured_grid_to_poly_data->SetInputData(unstructured_grid);
unstructured_grid_to_poly_data->Update ();
const auto poly_data = dynamic_cast<vtkPolyData*>(unstructured_grid_to_poly_data->GetOutput());
poly_data->GetCellData()->RemoveArray("vtkOriginalCellIds");
writer->SetInputData (poly_data);
writer->SetStartPiece(offset + i);
writer->SetEndPiece (offset + i);
writer->Write ();
}
}
Is there any quick workaround? Please let me know if I can provide more information.