| 415 | |
| 416 | |
| 417 | void |
| 418 | ProcessObject::SetOutput(const DataObjectIdentifierType & name, DataObject * output) |
| 419 | { |
| 420 | /* |
| 421 | Set an Output of this filter. This method |
| 422 | * does Register()/UnRegister() manually to |
| 423 | * deal with the fact that smart pointers aren't |
| 424 | * around to do the reference counting. |
| 425 | */ |
| 426 | |
| 427 | // copy the key, because it might be destroyed in that method, so a reference |
| 428 | // is not enough. |
| 429 | const DataObjectIdentifierType key = name; |
| 430 | |
| 431 | if (key.empty()) |
| 432 | { |
| 433 | itkExceptionMacro("An empty string can't be used as an output identifier"); |
| 434 | } |
| 435 | |
| 436 | // does this change anything? |
| 437 | const auto it = m_Outputs.find(key); |
| 438 | if (it != m_Outputs.end() && it->second.GetPointer() == output) |
| 439 | { |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | // Keep a handle to the original output and disconnect the old output from |
| 444 | // the pipeline |
| 445 | DataObjectPointer oldOutput; |
| 446 | if (m_Outputs[key]) |
| 447 | { |
| 448 | oldOutput = m_Outputs[key]; |
| 449 | m_Outputs[key]->DisconnectSource(this, key); |
| 450 | } |
| 451 | |
| 452 | if (output) |
| 453 | { |
| 454 | output->ConnectSource(this, key); |
| 455 | } |
| 456 | // save the current reference (which releases the previous reference) |
| 457 | m_Outputs[key] = output; |
| 458 | |
| 459 | // if we are clearing an output, we need to create a new blank output |
| 460 | // so we are prepared for the next Update(). this copies the requested |
| 461 | // region ivar |
| 462 | if (!m_Outputs[key]) |
| 463 | { |
| 464 | itkDebugMacro(" creating new output object."); |
| 465 | const DataObjectPointer newOutput = this->MakeOutput(key); |
| 466 | this->SetOutput(key, newOutput); |
| 467 | |
| 468 | // If we had an output object before, copy the requested region |
| 469 | // ivars and release data flag to the new output |
| 470 | if (oldOutput) |
| 471 | { |
| 472 | newOutput->SetRequestedRegion(oldOutput); |
| 473 | newOutput->SetReleaseDataFlag(oldOutput->GetReleaseDataFlag()); |
| 474 | } |