/*============================================================================= NOTE: THIS FILE IS A HANDMADE WRAPPER FOR THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManagedProcessObject.cxx Language: C++/CLI Author: Dan Mueller Date: $Date: 2008-06-15 19:37:32 +0200 (Sun, 15 Jun 2008) $ Revision: $Revision: 15 $ 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 __itkManagedProcessObject_cxx #define __itkManagedProcessObject_cxx // Include some useful ManagedITK files #include "itkManagedObject.cxx" // Use some managed namespaces #using #using using namespace System; using namespace System::IO; using namespace System::Reflection; using namespace System::Diagnostics; using namespace System::Collections::Generic; namespace itk { /** Forward reference to itkProcessObject */ ref class itkProcessObject; /// ///EventArgs subclass holding the current progress of a process object. ///Provides a convient method which converts the fractional progress to an integer percentage. /// public ref class itkProgressEventArgs : itkEventArgs { private: float m_Progress; public: ///Default constructor. ///The fractional progress of the process object (ie. 0.03 = 3%) itkProgressEventArgs( float progress ) : itkEventArgs( ) { this->m_Progress = progress; } ///Get the current progress as a fraction (ie. 0.03 = 3 %). property float Progress { virtual float get() { return this->m_Progress; } } ///Get the current progress as a percentage, rounded to the nearest integer value. property int ProgressAsPercentage { virtual int get() { return static_cast( System::Math::Round(this->m_Progress*100.0) ); } } }; ///A delegate for events sent from an itkProcessObject, with a progress value between 0.0 and 1.0. public delegate void itkProgressHandler(itkProcessObject^ sender, itkProgressEventArgs^ e); /// ///This abstract class is a managed replacement for itk::ProcessObject. /// /// ///ProcessObject is an abstract object that specifies behavior and ///interface of network process objects (sources, filters, mappers). ///Source objects are creators of visualization data; filters input, ///process, and output image data; and mappers transform data into ///another form (like transforming coordinates or writing data to a file). /// ///A major role of ProcessObject is to define the inputs and outputs of ///a filter. More than one input and/or output may exist for a given filter. ///Some classes (e.g., source objects or mapper objects) will not use inputs ///(the source) or outputs (mappers). In this case, the inputs or outputs is ///just ignored. /// public ref class itkProcessObject abstract : itkObject { private: String^ m_Name; itkProgressHandler^ m_EventStorage_Progress; protected: ///Protected constructor. ///A string representing the name of the ProcessObject. itkProcessObject( String^ name ) : itkObject( ) { this->m_Name = name; } public: ///Get/set a string describing the process object. property String^ Name { virtual String^ get() { return this->m_Name; } } /// ///Get the size of the input array. This is merely the size of the input array, ///not the number of inputs that have valid DataObject's assigned. /// ///Use NumberOfValidRequiredInputs to determine how many inputs are non-null. property unsigned int NumberOfInputs { virtual unsigned int get()=0; } /// ///Get the number of valid inputs. This is the number of non-null entries in the ///input array in the first NumberOfRequiredInputs slots. This method is used ///to determine whether the necessary required inputs have been set. /// property unsigned int NumberOfValidRequiredInputs { virtual unsigned int get()=0; } ///Return the length of the output array. property unsigned int NumberOfOutputs { virtual unsigned int get()=0; } ///Get/set the number of threads to create when executing. property unsigned int NumberOfThreads { virtual unsigned int get()=0; virtual void set(unsigned int threads)=0; } ///An event which is raised when the progress of the process is updated. event itkProgressHandler^ Progress { public: void add (itkProgressHandler^ handler) { m_EventStorage_Progress += handler; } void remove (itkProgressHandler^ handler) { m_EventStorage_Progress -= handler; } internal: void raise( itkProcessObject^ obj, itkProgressEventArgs^ e ) { if (this->m_EventStorage_Progress != nullptr) this->m_EventStorage_Progress(obj, e); } } /// ///Bring this filter up-to-date. /// /// ///Update() checks modified times against last execution times, and ///re-executes objects if necessary. A side effect of this method ///ss that the whole pipeline may execute in order to bring this filter ///up-to-date. This method updates the currently prescribed requested region. ///If no requested region has been set on the output, then the requested ///region will be set to the largest possible region. Once the requested ///region is set, Update() will make sure the specified requested region ///is up-to-date. To have a filter always to produce its largest possible ///region, users should call UpdateLargestPossibleRegion() instead. /// virtual void Update ( ) = 0; /// ///Bring the largest possible region of this filter up-to-date. /// /// ///Like Update(), but sets the output requested region to the ///largest possible region for the output. This is the method users ///should call if they want the entire dataset to be processed. If ///a user wants to update the same output region as a previous call ///to Update() or a previous call to UpdateLargestPossibleRegion(), ///then they should call the method Update(). /// virtual void UpdateLargestPossibleRegion ( ) = 0; /// ///Set the AbortGenerateData flag to true, and try to prematurely terminate the process. /// /// ///Process objects may handle premature termination of execution in different ways. ///Eg. many filters totally ignore this flag. /// virtual void AbortGenerateData ( ) = 0; ///Invoke the Progress event. virtual void InvokeProgressEvent ( itkProgressEventArgs^ e ) { this->Progress(this, e); } }; // end ref class } // end namespace #endif