------------------------------------------------------------------------------
| 1992 | |
| 1993 | //------------------------------------------------------------------------------ |
| 1994 | void vtkAlgorithm::SetInputDataObject(int port, vtkDataObject* input) |
| 1995 | { |
| 1996 | if (input == nullptr) |
| 1997 | { |
| 1998 | // Setting a nullptr input removes the connection. |
| 1999 | this->SetInputConnection(port, nullptr); |
| 2000 | return; |
| 2001 | } |
| 2002 | |
| 2003 | // We need to setup a trivial producer connection. However, we need to ensure |
| 2004 | // that the input is indeed different from what's currently setup otherwise |
| 2005 | // the algorithm will be modified unnecessarily. This will make it possible |
| 2006 | // for users to call SetInputData(..) with the same data-output and not have |
| 2007 | // the filter re-execute unless the data really changed. |
| 2008 | |
| 2009 | if (!this->InputPortIndexInRange(port, "connect")) |
| 2010 | { |
| 2011 | return; |
| 2012 | } |
| 2013 | |
| 2014 | if (this->GetNumberOfInputConnections(port) == 1) |
| 2015 | { |
| 2016 | vtkAlgorithmOutput* current = this->GetInputConnection(port, 0); |
| 2017 | vtkAlgorithm* producer = current ? current->GetProducer() : nullptr; |
| 2018 | if (vtkTrivialProducer::SafeDownCast(producer) && producer->GetOutputDataObject(0) == input) |
| 2019 | { |
| 2020 | // the data object is unchanged. Nothing to do here. |
| 2021 | return; |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | vtkTrivialProducer* tp = vtkTrivialProducer::New(); |
| 2026 | tp->SetOutput(input); |
| 2027 | this->SetInputConnection(port, tp->GetOutputPort()); |
| 2028 | tp->Delete(); |
| 2029 | } |
| 2030 | |
| 2031 | //------------------------------------------------------------------------------ |
| 2032 | void vtkAlgorithm::AddInputDataObject(int port, vtkDataObject* input) |