vtkDataSetTriangleFilter doesn't create empty point/cell data arrays for empty vtkUnstructuredGrid input
vtkDataSetTriangleFilter::UnstructuredExecute does nothing at all if the input contains no cells. It should at least create point and cell data arrays according to the input. For structured data sets, it properly does that.
Is that expected or unintended behavior? If unintended, I can supply a fix.
Example code
#include <vtkDataSetTriangleFilter.h>
#include <vtkTableBasedClipDataSet.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
int main()
{
// Create unstructured grid with a single triangle,
// one point data array and one cell data array
vtkNew<vtkPoints> points;
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(1, 1, 0);
vtkIdType ids[]{ 0, 1, 2 };
vtkNew<vtkCellArray> cells;
cells->InsertNextCell(3, ids);
vtkNew<vtkUnstructuredGrid> grid;
grid->SetPoints(points);
grid->SetCells(VTK_TRIANGLE, cells);
vtkNew<vtkDoubleArray> pointData;
pointData->SetName("PointData");
pointData->InsertNextValue(0.0);
pointData->InsertNextValue(1.0);
pointData->InsertNextValue(2.0);
grid->GetPointData()->AddArray(pointData);
vtkNew<vtkDoubleArray> cellData;
cellData->SetName("CellData");
cellData->InsertNextValue(10.0);
grid->GetCellData()->AddArray(cellData);
// Clip at a high value so output is empty
vtkNew<vtkTableBasedClipDataSet> clip;
clip->SetInputData(grid);
clip->SetValue(5.0);
clip->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "PointData");
clip->Update();
// Make sure data arrays still exist, albeit empty
vtkUnstructuredGrid* output = clip->GetOutput();
assert(output->GetPointData()->GetNumberOfArrays() == grid->GetPointData()->GetNumberOfArrays());
assert(output->GetPointData()->GetArray(0)->GetNumberOfTuples() == 0);
assert(output->GetCellData()->GetNumberOfArrays() == grid->GetCellData()->GetNumberOfArrays());
assert(output->GetCellData()->GetArray(0)->GetNumberOfTuples() == 0);
// Run through triangle filter
vtkNew<vtkDataSetTriangleFilter> triangleFilter;
triangleFilter->SetInputConnection(clip->GetOutputPort());
triangleFilter->Update();
// Make sure data arrays still exist, albeit empty
output = triangleFilter->GetOutput();
assert(output->GetPointData()->GetNumberOfArrays() == grid->GetPointData()->GetNumberOfArrays()); // FAILS: No point data arrays in output
assert(output->GetCellData()->GetNumberOfArrays() == grid->GetCellData()->GetNumberOfArrays()); // FAILS: No cell data arrays in output
assert(output->GetCellData()->GetNumberOfArrays() == grid->GetCellData()->GetNumberOfArrays());
assert(output->GetCellData()->GetArray(0)->GetNumberOfTuples() == 0);
}