/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedPipeline.cxx Language: C++/CLI Author: Dan Mueller $Date: 2007-04-11 16:26:16 +1000 (Wed, 11 Apr 2007) $ $Revision: 128 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. Portions of this code are covered under the ITK and VTK copyright. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ #pragma once #pragma warning( disable : 4635 ) // Disable warnings about XML doc comments #ifndef __itkManagedPipeline_cxx #define __itkManagedPipeline_cxx // Include some useful ManagedITK files #include "itkManagedDataObject.cxx" #include "itkManagedProcessObject.cxx" #include "itkManagedImageSource.cxx" #include "itkManagedImageToImageFilter.cxx" // Use some managed namespaces #using #using using namespace System; using namespace System::IO; using namespace System::Reflection; using namespace System::ComponentModel; using namespace System::Diagnostics; using namespace System::Collections::Generic; namespace itk { /// ///A class for grouping filters into a simple itkPipeline object. ///Add filters using the AddFilter() or SetFilter() methods, add inputs using ///the SetInput() method, get outputs using the GetOutput() method, ///and update the Pipeline using the Update() method. Filters must be added BEFORE ///the Input/Output/Update methods can be called. /// /// ///The pipeline can work for internal filters which expect multiple inputs by ///explicitly setting the inputs instead of or after calling ///ConnectInternalFiltersInputsAndOutputs(). /// public ref class itkPipeline { private: bool m_IsDisposed; List^ m_Filters; ///Initialise the pipeline. void Initialise ( ) { this->m_IsDisposed = false; this->m_Filters = gcnew List(); } public: ///Default constructor which creates an empty list of filters. itkPipeline ( ) { this->Initialise(); } ///Constructor taking the list of filters. ///The list of filter instance objects in this pipline. itkPipeline ( ... array^ filters ) { this->Initialise(); for each ( itkImageToImageFilter^ filter in filters) this->m_Filters->Add( filter ); } ///Dispose of the managed object. ~itkPipeline ( ) { if (!this->m_IsDisposed) { try { // Dispose of each filter for each ( itkImageToImageFilter^ filter in this->m_Filters) if (filter != nullptr && !filter->IsDisposed) delete filter; // Clean up the list of filters this->m_Filters->Clear(); this->m_Filters = nullptr; } catch ( ... ) { // Do nothing } finally { this->m_IsDisposed = true; } } } ///Get the list of filters comprising this pipeline. ///Filters can be added to this pipeline using Filters.Add() or AddFilters(). property List^ Filters { virtual List^ get() { return this->m_Filters; } } ///Add a filter to the end of the pipeline. ///The filter to add to the end of the pipeline. ///Filters can be added to this pipeline using Filters.Add() or AddFilters(). virtual void AddFilter( itkImageToImageFilter^ filter ) { this->m_Filters->Add( filter ); } /// ///Set the filter at the specified position in the pipeline. ///The index must be less than Filters.Length, otherwise an IndexOutOfRangeException ///will be thrown. /// ///The index of the filter to set. ///The filter object to set. virtual void SetFilter( unsigned int index, itkImageToImageFilter^ filter ) { this->m_Filters[index] = filter; } ///Set the first input of the pipeline object. ///The input as an itkDataObject. ///The first filter must be added to the pipeline before calling this method. virtual void SetInput( itkDataObject^ input ) { this->m_Filters[0]->SetInput( input ); } ///Set the specified input of the pipeline object. ///The input as an itkDataObject. ///The first filter must be added to the pipeline before calling this method. virtual void SetInput(unsigned int index, itkDataObject^ input) { this->m_Filters[0]->SetInput( index, input ); } /// ///Connects the output of each internal filter to the input of the next filter. /// /// ///This method has no effect if the number of internal filters is one. /// virtual void ConnectInternalFiltersInputsAndOutputs( ) { // Connect the output to the input of the next filter for (int i=1; i < this->m_Filters->Count; i++) this->m_Filters[i]->SetInput( this->m_Filters[i-1]->GetOutput() ); } /// ///Call Update() on the last filter in the pipeline. /// /// ///The user must have already connected the internal filter inputs and outputs by ///calling or ConnectInternalFiltersInputsAndOutputs or by explicitly setting them. /// virtual void Update ( ) { // Update the last filter this->m_Filters[this->m_Filters->Count - 1]->Update(); } ///Get the first output of the pipeline object. ///The itkDataObject to make as the output. ///All filters must be added to the pipeline before calling this method. virtual void GetOutput( itkDataObject^ output ) { this->m_Filters[this->m_Filters->Count - 1]->GetOutput( output ); } ///Get the specified output of the pipeline object. ///The itkDataObject to make as the output. ///All filters must be added to the pipeline before calling this method. virtual void GetOutput(unsigned int index, itkDataObject^ output) { this->m_Filters[this->m_Filters->Count - 1]->GetOutput( index, output ); } /// ///Converts the itkPipeline to a string representation. ///Eg. "itkTest1ImageFilter -> itkTest2ImageFilter". /// ///A string represetnation of the itkPipeline. virtual String^ ToString() override { String^ result = String::Empty; for each (itkProcessObject^% filter in this->m_Filters) result += filter->Name + " -> "; result->TrimEnd( ' ', '-', '>' ); return result; } }; // end ref class } // end namespace itk #endif