/*============================================================================= NOTE: THIS FILE WAS AUTOMATICALLY GENERATED BY THE ManagedITK PROJECT. Project: ManagedITK Program: Insight Segmentation & Registration Toolkit Module: itkManaged@MANAGED_BASE_NAME@.cxx Language: C++/CLI Author: Dan Mueller Date: $Date$ Revision: $Revision$ 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 Dan Mueller 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 __itkManaged@MANAGED_BASE_NAME@_cxx #define __itkManaged@MANAGED_BASE_NAME@_cxx // Use some managed namespaces #using #using #using using namespace System; using namespace System::IO; using namespace System::Reflection; using namespace System::Diagnostics; using namespace System::Collections::Generic; namespace itk { /// ///This class is a managed interface for itk::@MANAGED_BASE_NAME@. /// /// ///Both the wrapper and type classes derive from this interface. /// public interface class I@MANAGED_BASE_NAME@ { @MANAGED_PROPERTIES_INTERFACE@ @MANAGED_METHODS_INTERFACE@ }; /// ///This class is a managed wrapper around itk::@MANAGED_BASE_NAME@. /// public ref class itk@MANAGED_BASE_NAME@ : itkMeshBase, I@MANAGED_BASE_NAME@ { protected: itkMeshBase^ m_Instance; ///Protected constructor. itk@MANAGED_BASE_NAME@ ( ) : itkMeshBase( ) { } public: ///Dispose of the managed object. ~itk@MANAGED_BASE_NAME@ ( ) { if (!this->IsDisposed) { this->m_IsDisposed = true; delete m_Instance; } } ///Finalize the managed object. !itk@MANAGED_BASE_NAME@ ( ) { if (!this->IsDisposed && this->DisposeNativeObjectOnFinalize) delete this; } /// ///Gets/sets if the underlying native object should be disposed when the managed object is finalized. ///The default is true. /// property bool DisposeNativeObjectOnFinalize { virtual bool get() override { if ( this->m_Instance == nullptr ) return true; else return this->m_Instance->DisposeNativeObjectOnFinalize; } virtual void set( bool value ) override { if ( this->m_Instance != nullptr ) this->m_Instance->DisposeNativeObjectOnFinalize = value; } } ///Get a string representing the type instance of this INativePointer. ///"2", "3". property String^ MangledTypeString { virtual String^ get() override { INativePointer^ instanceSmartPtr = safe_cast(m_Instance); return instanceSmartPtr->MangledTypeString; } } /// ///Get/set the pointer to the native ITK object associated with this wrapper instance. /// ///The pointer to the native ITK object. property IntPtr NativePointer { virtual IntPtr get() override { return IntPtr(this->m_Instance->NativePointer); } virtual void set ( IntPtr value ) override { this->m_Instance->NativePointer = value; } } ///Get the last modified time. property unsigned long MTime { virtual unsigned long get() override { return this->m_Instance->MTime; } } ///Create a specific type instance using the given types. ///An array of types specifying which instance to create. static @NAMESPACE@@MANAGED_BASE_NAME@^ New ( ... array^ types ) { // Check that types is valid if ( types == nullptr || types->Length == 0 ) throw gcnew itk::itkInvalidWrappedTypeException("The given types array is invalid. A non-empty, valid types array must be specified to create an instance of a wrapped itk::@MANAGED_BASE_NAME@."); // Create the MangledTypeString for the specified explicit instance String^ mangledType = String::Empty; for each ( itk::INativePointer^ type in types ) mangledType += type->MangledTypeString; return @NAMESPACE@@MANAGED_BASE_NAME@::New( mangledType ); } ///Create a specific type instance using the given types. ///A string specifying which instance type to create. Eg. "UC2", "F3", etc. static @NAMESPACE@@MANAGED_BASE_NAME@^ New ( String^ mangledType ) { // Create a new managed object @NAMESPACE@@MANAGED_BASE_NAME@^ newManagedObject = gcnew @NAMESPACE@@MANAGED_BASE_NAME@(); newManagedObject->m_MangledTypeString = mangledType; // Get the name of the instance type to create String^ nameInstanceType = "@NAMESPACE@.@NAMESPACE@@MANAGED_BASE_NAME@_" + mangledType; try { // Create the correct instance class Type^ typeInstance = Assembly::GetExecutingAssembly()->GetType(nameInstanceType); if (typeInstance == nullptr) throw gcnew NullReferenceException("The type '" + nameInstanceType + "' could not be found in " + Assembly::GetExecutingAssembly()->GetName() ); Object^ objInstance = typeInstance->InvokeMember("New", BindingFlags::InvokeMethod, Type::DefaultBinder, nullptr, nullptr); if (objInstance == nullptr) throw gcnew NullReferenceException("Could not invoke the New() method for '" + nameInstanceType + "'."); newManagedObject->m_Instance = safe_cast(objInstance); // Pass events from type to wrapper newManagedObject->PassEventsFromTypeToWrapper( ); // Return return newManagedObject; } catch (Exception^ ex) { throw gcnew itk::itkInvalidWrappedTypeException("Could not create an instance of '" + nameInstanceType + "'. The given type may not be supported or may be invalid.", ex); } } ///Return itk::LightObject::Print( ostream ) as a string. virtual String^ ToString ( ) override { return m_Instance->ToString( ); } /// ///Remove all observers watching this object. /// /// ///By default, observers are created for all events. Calling this ///method removes all native observers, and therefore prevents ///the firing of managed events. Call AddAnyEventObserver() to ///reset the default observers which enable the managed events. /// virtual void RemoveAllObservers ( ) override { this->m_Instance->RemoveAllObservers(); } /// ///Adds a native observer watching for any event. /// /// ///By default, observers are created for all events. Calling this ///method adds a single native observer for any event. This ///observer invokes the managed events. Therefore, calling this ///method more than once, or calling it without first calling ///RemoveAllObservers(), may cause the managed events to be ///invoked more than once. /// virtual void AddAnyEventObserver ( ) override { this->m_Instance->AddAnyEventObserver( ); this->PassEventsFromTypeToWrapper( ); } ///Separate this path from the pipeline. /// ///This method disconnects the path from the upstream pipeline. ///Hence an Update() from downstream will not propagate back past this path. ///To completely isolate this path from the pipeline, the application must ///remove this path from any filters which it is connected as the input. /// virtual void DisconnectPipeline ( ) override { this->m_Instance->DisconnectPipeline(); } ///Get the number of points comprising this set. property unsigned long NumberOfPoints { virtual unsigned long get( ) override { return this->m_Instance->NumberOfPoints; } } ///Get the number of cells comprising this mesh. property unsigned long NumberOfCells { virtual unsigned long get( ) override { return this->m_Instance->NumberOfCells; } } ///Return the pointer to the native PointsContainer. virtual IntPtr GetPoints( ) override { return this->m_Instance->GetPoints(); } ///Return a managed array of points. ///This method steps through the points array and duplicates each point in to managed memory. It operates irrespective of the mesh traits. virtual array^ GetPointsAsArray( ) override { return this->m_Instance->GetPointsAsArray(); } ///Copy the array of points to the given memory location. ///The memory location to write the points. It is the caller's responsiblity to ensure enough memory has been allocated. virtual void GetPointsAsArray( IntPtr arrayptr ) override { this->m_Instance->GetPointsAsArray( arrayptr ); } ///Return the pointer to the native CellsContainerPointer. virtual IntPtr GetCells( ) override { return this->m_Instance->GetCells( ); } ///Return a managed array of cells. ///This method steps through the cell array and duplicates each index in to managed memory. It operates irrespective of the mesh traits. virtual array^ GetCellsAsArray( ) override { return this->m_Instance->GetCellsAsArray( ); } ///Copy the array of cell indicies to the given memory location. For this method to be useful, all cells must have the same number of points (ie. all LINE_CELL, all TRIANGLE_CELL, etc). ///The memory location to write the cell indices. It is the caller's responsiblity to ensure enough memory has been allocated. virtual void GetCellIndicesAsArray( IntPtr arrayptr ) override { this->m_Instance->GetCellIndicesAsArray( arrayptr ); } @MANAGED_PROPERTIES_WRAPPER@ @MANAGED_METHODS_WRAPPER@ private: ///Pass managed events from the type instance to this wrapper instance. void PassEventsFromTypeToWrapper() { this->m_Instance->Started += gcnew itkEventHandler(this, &itk@MANAGED_BASE_NAME@::Instance_StartedHandler); this->m_Instance->Ended += gcnew itkEventHandler(this, &itk@MANAGED_BASE_NAME@::Instance_EndedHandler); this->m_Instance->Aborted += gcnew itkEventHandler(this, &itk@MANAGED_BASE_NAME@::Instance_AbortedHandler); this->m_Instance->Iteration += gcnew itkEventHandler(this, &itk@MANAGED_BASE_NAME@::Instance_IterationHandler); this->m_Instance->Modified += gcnew itkEventHandler(this, &itk@MANAGED_BASE_NAME@::Instance_ModifiedHandler); } ///Handle the Started event. void Instance_StartedHandler(itkObject^ sender, itkEventArgs^ e) { this->InvokeStartedEvent(e); } ///Handle the Ended event. void Instance_EndedHandler(itkObject^ sender, itkEventArgs^ e) { this->InvokeEndedEvent(e); } ///Handle the Aborted event. void Instance_AbortedHandler(itkObject^ sender, itkEventArgs^ e) { this->InvokeAbortedEvent(e); } ///Handle the Iteration event. void Instance_IterationHandler(itkObject^ sender, itkEventArgs^ e) { this->InvokeIterationEvent(e); } ///Handle the Modified event. void Instance_ModifiedHandler(itkObject^ sender, itkEventArgs^ e) { this->InvokeModifiedEvent(e); } }; // end ref class } // end namespace itk #endif