ttk icon indicating copy to clipboard operation
ttk copied to clipboard

Only accept ttk-triangulable input data objects

Open JonasLukasczyk opened this issue 3 years ago • 0 comments

Currently most ttk filters have a FillInputPortInformation method that looks like this:

int ttkHelloWorld::FillInputPortInformation(int port, vtkInformation *info) {
  if(port == 0) {
    info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
    return 1;
  }
  return 0;
}

However, if the filter needs to derive a ttkTriangulation for the input data object then this might not be possible since vtkDataSet also includes data types that are not supported by ttkTriangulation. So if a filter will derive a ttkTriangulation one actually has to list all data types that are supported by ttkTriangulation:

int ttkHelloWorld::FillInputPortInformation(int port, vtkInformation *info) {
  if(port == 0) {
    info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid");
    return 1;
  }
  return 0;
}

Since this is a very common use case we should add a new static method to ttkAlgorithm that handles this:

int ttkHelloWorld::FillInputPortInformation(int port, vtkInformation *info) {
  if(port == 0) {
    ttkAlgorithm::RequireTriangulableInputDataObject(info);    
    return 1;
  }
  return 0;
}

static void ttkAlgorithm::RequireTriangulableInputDataObject(vtkInformation *info){
    info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
    info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid");
}

JonasLukasczyk avatar Feb 25 '22 09:02 JonasLukasczyk