/*============================================================================= 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: $Date: 2008-03-09 19:29:02 +0100 (Sun, 09 Mar 2008) $ Revision: $Revision: 8 $ Portions of this code are covered under the ITK and VTK copyright. See http://www.itk.org/HTML/Copyright.htm for details. See http://www.kitware.com/VTKCopyright.htm for details. Copyright (c) 2008 Queensland University of Technology (QUT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================*/ #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) { // Mark as disposed this->m_IsDisposed = true; // 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; } } ///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