How to get a name of the previous filter in the pipeline?

Hello!

I have the file that is being read and then is processed by several filters. However, I want to use the original file name in one of the consequent filters to dump some data to relevant file for debug purposes.

However, I am not able to do that.

Logically seems like information should be in vtkInformation

  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
  std::ostringstream stream;
  inInfo->PrintSelf(stream, vtkIndent());
  std::string str = stream.str();

But I have not found nothing like the name of the original file.

Thanks

The file name of a reader is not passed as vtkInformation. You might be able to traverse your pipeline back to the source from the current filter with something like

vtkAlgorithm* input = this;
vtkAlgorithmOutput* conn = nullptr;
do
{
  conn = input->GetInputConnection(0,0);
  if (conn)
  {
    input = conn->GetProducer();
  }
} while (conn);

the cast the final vtkAlgorthm to the reader type and access the FileName member from it.

Thank you a lot, dear Cory

So the final solution is

  std::string initial_file_name;

  vtkAlgorithm* initial_algorithm = this;
  vtkAlgorithmOutput* connection = nullptr;
  do
  {
    connection = initial_algorithm->GetInputConnection(0, 0);
    if (connection)
    {
      initial_algorithm = connection->GetProducer();
    }
  } while (connection);

  vtkPVDReader* pvd_reader = vtkPVDReader::SafeDownCast(initial_algorithm);

  if (pvd_reader != nullptr)
  {
    initial_file_name = pvd_reader->GetFileName();
  }

  std::regex regexp("[A-Za-z0-9_.]+$");
  std::smatch match;
  std::regex_search(initial_file_name, match, regexp);

  std::string matched_file_name = match.str(0);