vtkDistancePolyDataFilter (dynamic)

Would it make sense to add to transforms to the filter to allow dynamic updates?

I did it this way

vtkMTimeType spsDistancePolyDataFilter::GetMTime()
{
  vtkMTimeType mTime = this->Superclass::GetMTime();
  vtkMTimeType time;

  // Would only make sense if it had inputs
  vtkLinearTransform* transform = this->Transform0;
  if (transform)
  {
    time = transform->GetMTime();
    mTime = (time > mTime) ? time : mTime;
  }
  transform = this->Transform1;
  if (transform)
  {
    time = transform->GetMTime();
    mTime = (time > mTime) ? time : mTime;
  }

  // If any of the input transforms are updated, we update the internal transform
  if (mTime > this->Superclass::GetMTime())
  {
    this->Transform->Update();
  }
  return mTime;
}

//------------------------------------------------------------------------------
spsDistancePolyDataFilter::spsDistancePolyDataFilter()
{
  this->SignedDistance = 1;
  this->NegateDistance = 0;
  this->ComputeSecondDistance = 1;
  this->ComputeCellCenterDistance = 1;
  this->ComputeDirection = 0;

  this->SetNumberOfInputPorts(2);
  this->SetNumberOfOutputPorts(2);
  this->Transform = vtkSmartPointer<vtkTransform>::New();
  this->Transform0 = vtkSmartPointer<vtkTransform>::New();
  this->Transform1 = vtkSmartPointer<vtkTransform>::New();

  vtkSmartPointer<vtkTransform> temp = vtkTransform::SafeDownCast(this->Transform0->GetInverse());
  this->Transform1->SetInput(temp);
  this->Transform->SetInput(this->Transform1);
}

It works nicely. Working on some nasty template specialization of the `vtkImplicitPolyDataDistance` to speed things up in case we have normals and specialize on float or double precision. I'm not so found of how I got things to update correctly when either of the transforms were updated.

What are your thoughts?

I would say, yes and no. It makes sense if you need the extra efficiency of doing the transformation in-place, or if the design is a nice fit for you application.

However, this can already be achieved by adding vtkTransformPolyDataFilter to the pipeline, and the pipeline will handle the MTime correctly for updates. So contributing it to VTK, for example, wouldn’t add new functionality to VTK. Within VTK itself, it’s best if each filter is kept as simple as possible, for the sake of maintainability. (I’ve contributed some overly complicated filters to VTK myself, of course, and I’ve paid the price by maintaining them for years and years after creating them… so I speak from experience).

I hear you and I agree this addition is not super simple. I have used it in a complicated setup, where distance map is computed dynamically on decimated meshes to locate a subset of the meshes, which then is used for computing distances on a subset of the meshes in high-resolution in real-time.

Thanks for quick response and thank you for your PR fixing the transform bug (I have seen the effect of this before).