diff --git a/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.cpp b/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.cpp index bb3b59670a..1281510b8d 100644 --- a/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.cpp +++ b/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.cpp @@ -1,90 +1,108 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkSurfaceToSurfaceFilter.h" #include "mitkSurface.h" mitk::SurfaceToSurfaceFilter::SurfaceToSurfaceFilter() : SurfaceSource() { } mitk::SurfaceToSurfaceFilter::~SurfaceToSurfaceFilter() { } void mitk::SurfaceToSurfaceFilter::SetInput( const mitk::Surface* surface ) { this->SetInput( 0, const_cast( surface ) ); } void mitk::SurfaceToSurfaceFilter::SetInput( unsigned int idx, const mitk::Surface* surface ) { if ( this->GetInput(idx) != surface ) { this->SetNthInput( idx, const_cast( surface ) ); - this->CreateOutputsForAllInputs(idx); + this->CreateOutputForInput(idx); this->Modified(); } } const mitk::Surface* mitk::SurfaceToSurfaceFilter::GetInput() { if (this->GetNumberOfInputs() < 1) return NULL; return static_cast(this->ProcessObject::GetInput(0)); } const mitk::Surface* mitk::SurfaceToSurfaceFilter::GetInput( unsigned int idx) { if (this->GetNumberOfInputs() < 1) return NULL; return static_cast(this->ProcessObject::GetInput(idx)); } +void mitk::SurfaceToSurfaceFilter::CreateOutputForInput(unsigned int idx) +{ + if (this->GetNumberOfIndexedInputs() < idx || this->GetInput(idx) == NULL) + { + mitkThrow() << "Error creating output for input ["<GetNumberOfIndexedOutputs() <= idx) + this->SetNumberOfIndexedOutputs( idx+1 ); + + if (this->GetOutput(idx) == NULL) + { + DataObjectPointer newOutput = this->MakeOutput(idx); + this->SetNthOutput(idx, newOutput); + } + this->GetOutput( idx )->Graft( this->GetInput( idx) ); + this->Modified(); +} -void mitk::SurfaceToSurfaceFilter::CreateOutputsForAllInputs(unsigned int /*idx*/) +void mitk::SurfaceToSurfaceFilter::CreateOutputsForAllInputs() { this->SetNumberOfIndexedOutputs( this->GetNumberOfIndexedInputs() ); for (unsigned int idx = 0; idx < this->GetNumberOfIndexedInputs(); ++idx) { if (this->GetOutput(idx) == NULL) { DataObjectPointer newOutput = this->MakeOutput(idx); this->SetNthOutput(idx, newOutput); } this->GetOutput( idx )->Graft( this->GetInput( idx) ); } this->Modified(); } void mitk::SurfaceToSurfaceFilter::RemoveInputs( mitk::Surface* surface ) { for (unsigned int idx = 0; idx < this->GetNumberOfIndexedInputs(); ++idx) { if ( this->GetInput(idx) == surface ) { this->RemoveOutput(idx); } } } diff --git a/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.h b/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.h index 1452868b49..b6e74c5e3c 100644 --- a/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.h +++ b/Core/Code/Algorithms/mitkSurfaceToSurfaceFilter.h @@ -1,68 +1,85 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKSURFACETOSURFACEFILTER_H_HEADER_INCLUDED_C10B4740 #define MITKSURFACETOSURFACEFILTER_H_HEADER_INCLUDED_C10B4740 #include "mitkSurfaceSource.h" namespace mitk { class Surface; //##Documentation //## @brief Superclass of all classes getting surfaces (instances of class //## Surface) as input and generating surfaces as output. //## //## In itk and vtk the generated result of a ProcessObject is only guaranteed //## to be up-to-date, when Update() of the ProcessObject or the generated //## DataObject is called immediately before access of the data stored in the //## DataObject. This is also true for subclasses of mitk::BaseProcess and thus //## for mitk::mitkSurfaceToSurfaceFilter. //## @ingroup Process class MITK_CORE_EXPORT SurfaceToSurfaceFilter : public mitk::SurfaceSource { public: mitkClassMacro(SurfaceToSurfaceFilter, mitk::SurfaceSource); itkFactorylessNewMacro(Self) itkCloneMacro(Self) typedef itk::DataObject::Pointer DataObjectPointer; using itk::ProcessObject::SetInput; virtual void SetInput( const mitk::Surface* surface ); + /** + * @brief Add a new input at the given index (idx) + * Calls mitk::Surface::CreateOutputForInput(idx) + * @note The inputs must be added sequentially + * @param idx the index of the input, which must be incremental + * @param surface the input which should be added + */ virtual void SetInput( unsigned int idx, const mitk::Surface* surface ); virtual const mitk::Surface* GetInput(); virtual const mitk::Surface* GetInput( unsigned int idx ); - virtual void CreateOutputsForAllInputs(unsigned int idx); + /** + * @brief Create a new output for the input at idx + * @param idx the index of the input for which the output should be created + */ + virtual void CreateOutputForInput(unsigned int idx); + + /** + * @brief Creates outputs for all existing inputs + * @note For each existing input a new output will be allocated + */ + virtual void CreateOutputsForAllInputs(); virtual void RemoveInputs( mitk::Surface* surface ); protected: SurfaceToSurfaceFilter(); virtual ~SurfaceToSurfaceFilter(); }; } // namespace mitk #endif /* MITKSURFACETOSURFACEFILTER_H_HEADER_INCLUDED_C10B4740 */